TXSDateTime 类型数据赋值出现异常
导入wsdl文件后生成如下文件
h文件
// ************************************************************************ //
#ifndef __wds9002ext_h__
#define __wds9002ext_h__
#include <System.hpp>
#include <InvokeRegistry.hpp>
#include <XSBuiltIns.hpp>
#include <SoapHTTPClient.hpp>
namespace NS_wds9002ext {
class RealDataItem;
class HisDataItem;
// ************************************************************************ //
// Namespace : urn:wds9002ext
// ************************************************************************ //
class RealDataItem : public TRemotable {
private:
int Fsend_id;
float Fv;
TXSDateTime* Ft;
public:
__fastcall ~RealDataItem();
__published:
__property int send_id = { read=Fsend_id, write=Fsend_id };
__property float v = { read=Fv, write=Fv };
__property TXSDateTime* t = { read=Ft, write=Ft };
};
// ************************************************************************ //
// Namespace : urn:wds9002ext
// ************************************************************************ //
class HisDataItem : public TRemotable {
private:
int Fsend_id;
float Fv;
TXSDateTime* Ft;
float Favg_v;
public:
__fastcall ~HisDataItem();
__published:
__property int send_id = { read=Fsend_id, write=Fsend_id };
__property float v = { read=Fv, write=Fv };
__property TXSDateTime* t = { read=Ft, write=Ft };
__property float avg_v = { read=Favg_v, write=Favg_v };
};
typedef DynamicArray<HisDataItem*> HisDataItems;
typedef DynamicArray<float> ArrayOf96Float;
// ************************************************************************ //
// Namespace : urn:wds9002ext
// ************************************************************************ //
typedef DynamicArray<BXFDataItem*> BXFDataItems;
// ************************************************************************ //
// Namespace : urn:wds9002ext
// transport : http://schemas.xmlsoap.org/soap/http
// style : document
// binding : wds9002ext
// service : wds9002ext
// port : wds9002ext
// URL : http://192.168.90.16:2556
// ************************************************************************ //
__interface INTERFACE_UUID("{648268D5-B889-F707-452C-B3A9A6A0EC22}") wds9002extPortType : public IInvokable
{
public:
virtual RealDataItem* getRealData(const int senid) = 0;
virtual HisDataItems getHisData(const int senid, const int type, const TXSDateTime* start_time, const TXSDateTime* end_time) = 0;
};
typedef DelphiInterface<wds9002extPortType> _di_wds9002extPortType;
_di_wds9002extPortType Getwds9002extPortType(bool useWSDL=false, AnsiString addr="");
#endif // __wds9002ext_h__
}; // wds9002ext
#if !defined(NO_IMPLICIT_NAMESPACE_USE)
using namespace NS_wds9002ext;
#endif
//-
///------CPP文件
#include <vcl.h>
#pragma hdrstop
#if !defined(__wds9002ext_h__)
#include "wds9002ext.h"
#endif
namespace NS_wds9002ext {
_di_wds9002extPortType Getwds9002extPortType(bool useWSDL, AnsiString addr)
{
static const char* defWSDL= "wds9002ext.wsdl";
static const char* defURL = "http://127.0.0.1:8991";
static const char* defSvc = "wds9002ext";
static const char* defPrt = "wds9002ext";
if (addr=="")
addr = useWSDL ? defWSDL : defURL;
THTTPRIO* rio = new THTTPRIO(0);
if (useWSDL) {
rio->WSDLLocation = addr;
rio->Service = defSvc;
rio->Port = defPrt;
} else {
rio->URL = addr;
}
_di_wds9002extPortType service;
rio->QueryInterface(service);
if (!service)
delete rio;
return service;
}
__fastcall RealDataItem::~RealDataItem()
{
delete Ft;
}
__fastcall HisDataItem::~HisDataItem()
{
delete Ft;
delete Fmin_t;
delete Fmax_t;
}
// ************************************************************************ //
// This routine registers the interfaces and types used by invoke the SOAP
// Service.
// ************************************************************************ //
static void RegTypes()
{
/* wds9002extPortType */
InvRegistry()->RegisterInterface(__interfaceTypeinfo(wds9002extPortType), L"urn:wds9002ext", L"UTF-8");
InvRegistry()->RegisterDefaultSOAPAction(__interfaceTypeinfo(wds9002extPortType), L"");
InvRegistry()->RegisterInvokeOptions(__interfaceTypeinfo(wds9002extPortType), ioDocument);
/* RealDataItem */
RemClassRegistry()->RegisterXSClass(__classid(RealDataItem), L"urn:wds9002ext", L"RealDataItem");
/* HisDataItem */
RemClassRegistry()->RegisterXSClass(__classid(HisDataItem), L"urn:wds9002ext", L"HisDataItem");
RemClassRegistry()->RegisterXSInfo(__arrayTypeinfo(HisDataItems), L"urn:wds9002ext", L"HisDataItems");
RemClassRegistry()->RegisterXSInfo(__arrayTypeinfo(ArrayOf96Float), L"urn:wds9002ext", L"ArrayOf96Float");
}
#pragma startup RegTypes 32
}; // wds9002ext
为什么调用getRealData时可以正常使用取到的TXSDateTime* 类型数据
但当给getHisData赋值时则不管使用AsDateTime还是Year等各分解时间赋值均抛出异常。
而用DateTimeToXSDateTime转换时取的时间均为1970-01-01
NS_wds9002ext::_di_wds9002extPortType wsdl_service;
NS_wds9002ext::RealDataItem *day_rain2;
TXSDateTime* AAA;
TXSDateTime* begin_1;
TXSDateTime* end_1;
day_rain2=wsdl_service->getRealData(111) ;
AAA= day_rain2->t;
//此时均正常
TDateTime dt_beg;
TDateTime dt_end;
dt_beg= StrToDateTime("2007-11-20 08:00:00");
dt_end= StrToDateTime("2007-11-21 08:00:00");
begin_1->AsDateTime=(dt_beg);end_1->AsDateTime =(dt_end); //使用此时编译通过,但运行到此抛出异常
begin_1=DateTimeToXSDateTime(dt_beg);end_1=DateTimeToXSDateTime(dt_end);//上句换作使用此时编译通过,运行getHisData时取时间均为1970-01-01
NS_wds9002ext::HisDataItems day_rain3;
day_rain3=wsdl_service->getHisData(6980109,1, begin_1,end_1);
即datetime类型直接赋值给TXSDateTime出现异常,将datetime类型转换成TXSDateTime不能成功。
如何给TXSDateTime赋值呢?