음...
특정 컨트롤을 포함하고 있는 Form을 구해야 할 작업이 필요한 경우가 있을까요?
평소엔 별로 필요 없을것 같은데..
Component같은 것을 만드는 경우 현재control이 어떤 폼에 올려질지 모르니 필요한 경우가 있을것입니다.
간단히 만들어 보았습니다.
TForm * __fastcall GetParentForm(TControl *ctrl)
{
if(ctrl==NULL || ctrl->Parnet==NULL)return NULL;
while(ctrl->Parent!=NULL)ctrl=(TWinControl *)ctrl->Parent;
if(ctrl->InheritsFrom(__classid(TCustomForm)))return ctrl;
else return NULL;
}
...
그런데 이미 VCL에 위와똑같은 기능을 하는 함수가 있습니다.
GetParentForm 이라는 함수가 Forms유닛에 있습니다.
function GetParentForm(Control: TControl): TCustomForm;
begin
while Control.Parent <> nil do Control := Control.Parent;
if Control is TCustomForm then
Result := TCustomForm(Control) else
Result := nil;
end;
function ValidParentForm(Control: TControl): TCustomForm;
begin
Result := GetParentForm(Control);
if Result = nil then
raise EInvalidOperation.CreateFmt(SParentRequired, [Control.Name]);
end;
이함수에 대해 tip게시판에도 없고..
Q&A에서도 거의 찾아보기 힘들어 .. 한번 올려봅니다.
그럼..
|