부모form에서 버튼을 클릭하면 자식 form이 생성되고
자식 form에서 부모 폼의 프로퍼티를 콘트롤 하거나 프로시져를 호출하고 싶습니다.
하지만 자식에서는 부모를 알 수가 없으니 어지해야 할지 모르겠네요.
childForm := TchildForm .Create(self);
childForm .show;
를 통해 자식을 생성하고,
if (Self.Owner<>nil) and (Self.Owner is TForm) then
begin
form:=TForm(Self.Owner);
end;
로 부모를 가져고는데까진 성공 했습니다.
그치면 여기서 부모의 프로퍼티나 프로시져를 사용할 방법이 없더군요.
검색해봐도 안나오고...
제가 원하는 것은 원하는 작업을 하기 위한 창을 띄워서
작업을 진행하고 창을 닫으면 그 결과가 아래에 뜨는 방식입니다.
예를 들어 새폴더를 만들고 싶다면 창을 띄워서 그곳에 이름이나 속성 등을 넣고
창을 닫으면 부모 폼에 있는 리스트 뷰에 반영이 되는 그런 식으로요.
어떻게 하면 될지 아시는 분은 답변해 주세요. 감사합니다.
차일드폼에 코딩으로 명시적으로 부모폼을 선언하여 사용하시면 됩니다.
예로는
===========================
var
차일드폼: T차일드폼;
implementation
uses 부모폼유닛명;
============================
다른 방법으로는 다음을 참고하세요.
차일드폼이 생성되고...부모폼의 버튼클릭이벤트를 가지는 차이트폼의 버튼생성입니다.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, Buttons;
type
TForm1 = class(TForm)
BitBtn1: TBitBtn;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.BitBtn1Click(Sender: TObject);
var form2 : TForm;
button: TButton;
begin
form2 := Tform.Create(Self);
form2.show;
form2.Onclose := FormClose;
button:= TButton.Create(form2);
button.Parent := form2;
button.Caption :='test';
button.width:=100;
button.left:=10;
button.Top := 50;
button.OnClick := BitBtn1Click;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := cafree;
end;
end.