본문 바로가기
Delphi Tip/+Tip

하위폼 종료 감지

by MonoSoft 2024. 3. 4.
728x90
반응형

하위폼 종료 감지

하위폼의 종료시 메인폼에서 정보 감지하는방법

 

728x90

 

 

 

하위폼의 종료시 메인폼에서 정보 감지하는방법(Notification)

 

컴포넌트인(폼)경우 자신이 owner로 생성한 컴포넌트의

참조카운팅하는 메카니즘을 가지고 있는것 같은데 뒤져보면

Notificaton, FreeNotification 있는데 Notification을 오버라이딩하여 사용했다

 

type

TForm1 = class(TForm)

Button1: TButton;

procedure Button1Click(Sender: TObject);

//하위폼 생성버튼

//.하위폼은 OnClose이벤트에서 action:=cafree하며 자기소멸시키며나옴

procedure Notification(Acomponent:Tcomponent;operation:Toperation);override;

end;

 

var

Form1: TForm1;

 

implementation

 

uses Unit2; //하위폼유닛

 

var iCount:integer ; //그냠 하위폼 구분위한 변수

 

{$R *.dfm}

 

procedure TForm1.Button1Click(Sender: TObject);

var f:Tform2;

begin

inc (iCount);

f:=Tform2.Create(self); //여기서 하위폼만들고

f.Caption :='폼'+intToStr(iCount); //하위폼 소멸시 구분하기 위한 어떤작업.

f.Show ;

end;

 

procedure TForm1.Notification(Acomponent: Tcomponent; operation: Toperation);

begin

inherited Notification(Acomponent,Operation) ;

if (Acomponent is Tform2) and (operation = opremove) then

showMessage((Acomponent as Tform2).caption+' 종료됨') ; //여기서

//소멸된 폼의 정보를 알수있다..

end;

 

728x90
반응형

댓글