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

偶尔善良 提交于 2019-12-11 00:23:58

问题


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!


回答1:


@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;


来源:https://stackoverflow.com/questions/2689982/how-can-i-specify-the-owner-of-component-read-from-a-delphi-tstream

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!