C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 팁&트릭
C++Builder Programming Tip&Tricks
[940] [Forms] GetParentForm
장성호 [nasilso] 17192 읽음    2009-12-10 00:46
음...

특정 컨트롤을 포함하고 있는 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에서도 거의 찾아보기 힘들어  .. 한번 올려봅니다.

그럼..

+ -

관련 글 리스트
940 [Forms] GetParentForm 장성호 17192 2009/12/10
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.