如何指定从Delphi TStream读取的组件的所有者?

Rod*_*ddy 2 delphi streaming components

我正在从流中读取组件,并希望能够指定Owner属性.

  var TComponent : comp;

  stream.Seek(0, soFromBeginning);
  comp := stream.ReadComponent(nil);
Run Code Online (Sandbox Code Playgroud)

谁拥有comp,我该如何改变呢?我希望readComponent的参数是所有者,但它似乎做了一些完全不同的事情!

RRU*_*RUZ 5

@Roddy,您可以使用InsertComponent过程来设置组件的所有者.

检查这个样本

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;
Run Code Online (Sandbox Code Playgroud)