다음과 같은 함수를 하나 만듭니다.
function GetControlCount(AForm: TForm; AControl: TComponentClass): Integer;
var
i: Integer;
begin
Result := 0;
//
// 넘겨받은 폼에 컴포넌트가 몇개 있는지 파악한 후
// 원하는 컴포넌트인 경우 카운트 증가.
//
for i := 0 to AForm.ComponentCount-1 do
if (AForm.Components[i] is AControl) then
Inc(Result);
end;
//
// 호출은 이렇게..
//
procedure TForm1.Button1Click(Sender: TObject);
begin
Label1.Caption := IntToStr(GetControlCount(Form1, TLabel)); // 라벨의 갯수
Label2.Caption := IntToStr(GetControlCount(Form1, TEdit)); // 에디트 컨트롤의 갯수
Label3.Caption := IntToStr(GetControlCount(Form1, TComboBox)); // 콤보박스의 갯수
end;
질문하는 것은 좋으나, 절대 외계체 사용하지 말고 옳바르게 써주시길 바랍니다.
질문과 답에 올라오는 모든 글들은 향후 귀중한 자료가 됩니다.
바른말을 써서 자료로서의 가치가 더 높아지게 되길 바랍니다.
마룬타오 님이 쓰신 글 :
: 예)
: 폼에 에디트박스 7개 콤보박스5개 기타 여러가지
: 있는데 특정 원하는 컴포넌트갯수를 알수있는 방법이 있나요.......
:
: 제발 알려주셈....
|