MDI 또는 SDI 에서 새로운 폼을 생성 할때 폼의 이름으로 생성하면 편리 할 때가 있습니다.
1. 우선 생성 될 폼을 [Project > Options... > forms] 에서 해당 폼을 Avaiable forms: 에 등록합니다.
2. 해당 폼 Unit 에서
initialization
RegisterClasses([TfrmChild]);
를 아래 쪽에 추가합니다.
3. 생성되는 폼의 OnClose 에서
procedure TfrmChild.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action:= caFree;
end;
3. 폼을 생성 하는 메인 폼에서
function TfrmMain.CreateChild(iClass: string): Boolean;
var
iMyFormClass: TFormClass;
iWorkform: TForm;
iHnd: THandle;
idx: integer;
begin
result := True;
iHnd := 0;
for idx := 0 to Screen.FormCount - 1 do begin
if UpperCase('T' + Screen.Forms[idx].Name) = UpperCase(iClass) then begin
iHnd := Screen.Forms[idx].Handle;
Break;
end;
end;
if iHnd = 0 then begin
iMyFormClass := TFormClass(GetClass(iClass));
if iMyFormClass <> nil then begin
iWorkform := iMyFormClass.Create(Application.MainForm)
end
else result := False;
end
else begin
if IsIconic(iHnd) then ShowWindow(iHnd, SW_SHOWNORMAL)
else BringWindowToTop(iHnd);
end;
end;
을 선언 하여 주고
4. 폼 생성시 frmChild:= TfrmChild.Create(Self); 대신
CreateChild('TFrmChild');
을 사용하여 생성하거나 보여주거나, 최상위 위치로 올려 주면 됩니다.
댓글 없음:
댓글 쓰기