2013-05-05 2 views
0

디자인 타임에 두 번 클릭하면 다른 폼이 만들어지는 구성 요소를 만들었습니다. 내가 주요 설계 형태의 구성 요소를 얻을 수있는 새로운 형태에서디자인 타임에 폼의 구성 요소를 가져옵니다.

function TMyComponentTest1.Execute: Boolean; 
var 
    Form: TMyComponentTest1Form; 
begin 
    try 
    Form := TMyComponentTest1Form.Create (nil); 
    Form.ShowModal; 
    finally 
    Form.Free; 
    end; 
end; 

,하지만 난 사람이 나는 것을 달성 할 수있는 방법에 대한 아이디어가 않습니다, 그렇게 할 수없는 : 그에 대한 코드는 다음과 같다 ? 또한 "자체"로 만들려고했지만 더블 클릭하면 델파이가 충돌합니다 ...

+0

이'Create' 즉시해야한다 * 전에 * 당신은'try'를 입력합니다. –

답변

0

다음은 작동하지 않을 것 같은 테스트되지 않은 코드입니다. TMyComponent 컴포넌트를 호출하자. 구성 요소 편집기 및/또는 등록 정보 편집기의 일부로 TMyComponent의 designtime 패키지에 반드시 TMyComponentTest1Form을 작성해야합니다.

그런 다음이 같은 TMyComponentTest1Form를 만들어보십시오 :

function TMyComponentTest1.Execute: Boolean; 
var 
    aForm: TMyComponentTest1Form; 
    OwnerForm: TForm; 
    aMyComponent: TMyComponent; 
begin 
    {OwnerForm is your main design form} 
    OwnerForm := nil; 

    {Get your component on the main design form} 
    aMyComponent := TMyComponent(GetComponent(0)) 

    {Make sure your component's owner is a TForm} 
    if (aMyComponent.Owner is TForm) then 
    OwnerForm := TForm(aMyComponent.Owner); 

    {You problem may be solved by making component form owner the Application} 
    aForm := TMyComponentTest1Form.Create(Application); 
    try 
    { 
    Now you should be able iterate the components owned by OwnerForm 
    right here. If you do not want to do it here, add a TForm property 
    to your component and assign OwnerForm to it. 
    } 
    aForm.ShowModal; 
    finally 
    aForm.Free; 
    end; 
end;