怎样把一个对象转换为TStream?(100分)

  • 主题发起人 主题发起人 liao-li-jian
  • 开始时间 开始时间
L

liao-li-jian

Unregistered / Unconfirmed
GUEST, unregistred user!
怎样把一个对象转换为TStream?
怎样把一个对象转换为Variant?
 
OLE对象有相关的函数,看书吧。
 
ObjectBinaryToText procedure
Converts the binary representation of an object into more readily understandable text.

ObjectResourceToText procedure
Converts the binary representation of an object resource into more readily understandable text.

ObjectTextToBinary procedure
Converts a symbolic text representation of an object into the binary version that is used to save the object to files or memory streams.

ObjectTextToResource procedure
Converts a symbolic text representation of an object into an internal binary representation.

ReadComponentRes function
Reads components and their properties from a specified Windows resource.

ReadComponentResEx function
Reads a component from a resource
.
ReadComponentResFile function
Reads components and their properties from a specified Windows resource file.

RegisterClass procedure
Registers a class of persistent object so that it's class type can be retrieved.
 
变成流之后,再变成Variant应该没何问题了吧
 
你应该知道怎么做了
function ComponentToString(Component: TComponent): string;
var
BinStream:TMemoryStream;
StrStream: TStringStream;
s: string;
begin
BinStream := TMemoryStream.Create;
try
StrStream := TStringStream.Create(s);
try
BinStream.WriteComponent(Component);
BinStream.Seek(0, soFromBeginning);
ObjectBinaryToText(BinStream, StrStream);
StrStream.Seek(0, soFromBeginning);
Result:= StrStream.DataString;
finally
StrStream.Free;
end;
finally
BinStream.Free
end;
end;
 
后退
顶部