2010-04-22 57 views
2

我正在讀取流中的組件,並希望能夠指定Owner屬性。如何指定從Delphi TStream讀取的組件的所有者?

var TComponent : comp; 

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

誰擁有comp,我該如何改變它?我希望readComponent的參數是所有者,但它似乎做了一些完全不同的事情!

回答

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; 
+0

完美,謝謝! – Roddy 2010-04-22 11:17:30

相關問題