2010-04-22 8 views
2

스트림에서 구성 요소를 읽고 있는데 Owner 속성을 지정할 수 있기를 원합니다.Delphi TStream에서 읽은 구성 요소 소유자를 어떻게 지정할 수 있습니까?

var TComponent : comp; 

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

누구가 소유하고 있으며 어떻게 변경할 수 있습니까? 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

관련 문제