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

I am reading a component from a stream and want 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 was hoping the readComponent parameter would be the owner, but there seems to be something completely different!

+2
source share
1 answer

@Roddy, you can use the InsertComponent procedure to set the owner of the 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;
+5
source

All Articles