Delphi 7:将对象转换(序列化?)到TByteDynArray(用于SOAP) [英] Delphi 7 : Converting (serializing?) an object to TByteDynArray (for SOAP)

查看:293
本文介绍了Delphi 7:将对象转换(序列化?)到TByteDynArray(用于SOAP)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Delphi 7并从WDL文件导入以创建SOAP客户端。 Delphi使用WSDL中发布的函数以及这些函数的参数类型(类)来生成接口代码。

I use Delphi 7 and import from a WDL file to create a SOAP client. Delphi generates interface code with the published functions from the WSDL and the types (classes) of parameters for those functions.

Delphi已确定类似这样的东西

Delphi has determined that something like this

  Message = class(TRemotable)
  private
    FMessageID: Int64;
    Ftimestamp: TXSDateTime;
    Fevent: eventType;
    FmagicNumber: WideString;
    FDataPart: DataPart;
  published
    property MessageID: Int64 read FMessageID write FMessageID;
    property timestamp: TXSDateTime read Ftimestamp write Ftimestamp;
    property event: eventType read Fevent write Fevent;
    property magicNumber: WideString read FmagicNumber write FmagicNumber;
    property DataPart: DataPart read FDataPart write FDataPart;
  end;

应作为TByteDynArray发送...

should be send as a TByteDynArray ...

function  sendMessage(const theMessage: TByteDynArray; 
                      const data: DataPart): WideString; stdcall;

这需要我将对象转换为TByteDnyArray,这-众生Delphi n00b-我这样做是

which necessitates me converting an object to a TByteDnyArray, which - beings Delphi n00b - I am doing this by

  theMessageArray := TByteDynArray(theMessage);

当我在调试器中查看对象时,它包含指针(指向 Ftimestamp Ftimestamp ),当我查看TByteDynArray时,我看到了自己相同的指针值。因此,似乎铸造不是我想要的。如何将我的对象转换为所需的TByteDynArray? (并且大概内联了指针所指向的对象)

When I look at the object in the debugger, then it contains pointers (to the Ftimestamp and Ftimestamp), and when I look in the TByteDynArray I see the self same pointer values. So, it seems that "cast" is not what I wanted. How do convert my object to the TByteDynArray which is required? (and which, presumably "inlines" the objects pointed to by pointers)

我认为对此有一种标准方法...

I presume that there is a standard approach for this ...

推荐答案

在父类中查找流数据的方法。 objectinstance.savetostream左右。

Look in the parent class for a way to stream the data. objectinstance.savetostream or so. It probably will iterate over the published membes and write them to a stream.

使用它来将其写入内存流,这大概是围绕内存块的一个类(像tdynbytearray)。然后使用memorystream.size和setlength将tbytedynarray分配给适当的大小,并将字节从memorystream复制到新创建的数组:

Use this to write it to a memory stream, which is roughly a class around a memory block (like tdynbytearray). Then use memorystream.size and setlength to allocate the tbytedynarray to the proper size, and copy the bytes from the memorystream to the newly created array:

 // (Untested)

 memstream:=TMemoryStream.Create;
 objectinstance.SaveToStream(memstream);
 setlength(mybytearray,memstream.size);
 if memstream.size>0 then
    move (pansichar(memstream.memory)^,mybytearray[0],memstream.size);

这篇关于Delphi 7:将对象转换(序列化?)到TByteDynArray(用于SOAP)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆