Roddy
Roddy

Reputation: 68053

How can I specify the Owner of component read from a Delphi TStream?

I'm reading a component from a stream, and want to be able to specify the Owner property.

  var TComponent : comp;

  stream.Seek(0, soFromBeginning);
  comp := stream.ReadComponent(nil);

Who owns comp, and how can I change it? I'd hoped the parameter to readComponent would be the owner, but it seems to do something totally different!

Upvotes: 2

Views: 886

Answers (1)

RRUZ
RRUZ

Reputation: 136421

@Roddy, you can use the InsertComponent procedure for set the owner of an component.

check this sample

procedure TForm1.Button1Click(Sender: TObject);
var
  Stream : TFileStream;
  Comp   : TComponent;
begin
  Stream := TFileStream.Create('Myfiile', fmOpenRead);
  try
    Comp := Stream.ReadComponent(nil);
    if Comp <> nil then
        InsertComponent(Comp);   //this make the form the owner of the component
  finally
    Stream.Free;
  end;
end;

Upvotes: 5

Related Questions