代码之家  ›  专栏  ›  技术社区  ›  Roddy

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

  •  2
  • Roddy  · 技术社区  · 14 年前

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

    1 回复  |  直到 14 年前
        1
  •  5
  •   RRUZ    14 年前

    @罗迪,你可以用 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;