안녕하십니까.
다름이 아니라 체크박스를 배열로 선언하고 동적으로 만들어 준후에 OnClick이벤트를 선언해 주었습니다. 물론 체크박스 이벤트에 모두 같은 이름으로.....
체크박스를 클릭할때마다 이벤트는 잘 발생 하는데 문제는 어느 체크박스를 선택했는지 알수가 없습니다.
어떻게 하면 알수가 있을까요?
===============================================
procedure TFMain.Layer_Index_InIt();
var
QDB : TQuery;
ft : TFont;
begin
ft := TFont.Create;
QDB := TQuery.Create(self);
QDB.DatabaseName := 'sample'; //local db
QDB.active := false;
QDB.SQL.Clear;
QDB.sql.add(' SELECT * FROM S_INDEX ');
QDB.Open;
if QDB.RecordCount > 0 then
begin
//APanel 은 전역으로 선언
//ACheckBox도 전역....
SetLength(APanel, QDB.RecordCount);
setLength(ACheckBox, QDB.RecordCount);
QDB.First;
ft.Name := QDB.FieldByName('FT_Name').AsString;
while not QDB.Eof do
begin
// DB에 있는 수만큼 만듭니다.
Index_Add(QDB.FieldByName('ID').AsInteger,
ft,
QDB.FieldByName('CHAR_CAP').AsString,
QDB.fieldByName('ATTRIBUTE').AsString);
QDB.Next;
end;
end;
end;
procedure TFMain.Index_Add(ICount : integer;
font : TFont;
fontIndex : string;
FCaption : String);
begin
APanel[ICount] := TPanel.Create(self);
APanel[ICount].Parent := SBLayerIndex;
APanel[ICount].Align := alTop;
APanel[ICount].Height := 33;
APanel[ICount].Alignment := taLeftJustify;
APanel[ICount].Caption := ' ' + FCaption;
ACheckBox[ICount] := TCheckBox.Create(self);
ACheckBox[ICount].Parent := APanel[ICount];
ACheckBox[ICount].Font := font;
ACheckBox[ICount].Caption := fontIndex;
ACheckBox[ICount].Top := 8;
ACheckBox[ICount].left := 8;
ACheckBox[ICount].Width := 57;
ACheckBox[ICount].Height := 17;
ACheckBox[ICount].Checked := true;
ACheckBox[ICount].OnClick := CheckBoxOnClick;
APanel[ICount].Show;
ACheckBox[ICount].Show;
end;
procedure TFMain.CheckBoxOnClick(Sender: TObject);
begin
//todo
end;
> procedure TFMain.CheckBoxOnClick(Sender: TObject);
> begin
> //todo
> end;
Sender를 이용해서,
예를 들어 클릭한 체크박스가 체크되어 있는지를 아는 코드를 만든다면
procedure TFMain.CheckBoxOnClick(Sender: TObject);
var
ifChecked:Boolean;
begin
ifChecked := (Sender as TCheckBox).Checked;
//그다음에 if Checked 어쩌고...
end;
잘될려나...되겠죠?