Re:recursive COM/DCOM object passing via streaming
I enclose the VariantToCompoent and ComponentToVariant methods from the
David W. Body article.
These methods are recursive on a TForm component (I have the TButton, ...),
why they don't work on my own component ?
Jean-Michel
function TCompStream.ComponentToVariant(Component: TComponent): Variant;
var
BinStream: TMemoryStream;
Data: Pointer;
begin
BinStream := TMemoryStream.Create;
try
BinStream.WriteComponent(Component);
Result := VarArrayCreate([0, BinStream.Size - 1], varByte);
Data := VarArrayLock(Result);
try
Move(BinStream.Memory^, Data^, BinStream.Size);
finally
VarArrayUnlock(Result);
end;
finally
BinStream.Free;
end;
end;
function TCompStream.VariantToComponent(Value: Variant): TComponent;
var
BinStream: TMemoryStream;
Data: Pointer;
begin
BinStream := TMemoryStream.Create;
try
Data := VarArrayLock(Value);
try
BinStream.WriteBuffer(Data^, VarArrayHighBound(Value, 1) + 1);
finally
VarArrayUnlock(Value);
end;
BinStream.Seek(0, soFromBeginning);
Result := BinStream.ReadComponent(nil);
finally
BinStream.Free;
end;
end;
"Binh Ly" <b...@castle.net> a crit dans le message news:
3b00a917$1_2@dnews...
Quote
> I don't know what VariantToComponent does, but it is likely that you'll
have
> to write more code to stream recursively into sub objects.
> --
> have fun
> Binh Ly
> www.techvanguards.com
> <jm.biol...@hexalog.com> wrote in message news:3afb95b4$1_1@dnews...
> > When I use the VariantToComponent, like
> > Config := VariantToComponent(OCDMConfig.Config) as TSystemConfig;
> > and I want to access to Config.Report I get an error violation, because
> > Config.Report is nil.
> > Is the VariantToComponent Streaming not recursive ? How can I have
> recursive
> > behavior in streaming ?