Board index » delphi » recursive COM/DCOM object passing via streaming

recursive COM/DCOM object passing via streaming

Hello,
I have adapted the David W. Body article on DCom Streaming for my
application, I want to pass a structure over DCOM with streaming :

TReport = class(TComponnent)
    Title : string;
end;

TConfig = class(TComponent)
    Path : string;
    Report : TReport;
end;

The Report member is created : Report := TReport.Create(self) (where self is
an instance of Config)

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 ?

Any help appreciated,
Jean-Michel

 

Re:recursive COM/DCOM object passing via streaming


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

Quote
<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 ?

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 ?

Re:recursive COM/DCOM object passing via streaming


Without digging into the code, I have a suspicion that you'll need to move
your properties into the published section of the component for this to
work. Otherwise, you'll have to write your own recursive code.

--
have fun
Binh Ly
www.techvanguards.com

Quote
<jm.biol...@hexalog.com> wrote in message news:3b0140b4_2@dnews...
> 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

Other Threads