1

我想创建一个函数,它应该支持 TListbox 或 TChecklistBox 作为调用参数

 MyUISupportFunction ( ......  ; aListBox : TObject);


 if (aListBox as  TObject) is TListBox  then (aListBox as  TListbox).Items.Clear;
 if (aListBox as  TObject) is TCHeckListBox  then (aListBox as  TCheckListbox).Items.Clear;

我想知道我可以在 UI(TListBox 和 TChechecklist Box)上更高效地编写我的代码

4

1 回答 1

7

两者都继承自 TCustomListBox

Procedure MyUISupportFunction (aListBox : TCustomListBox);
begin
   aListBox.Items.Clear;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  MyUISupportFunction(Listbox1);
  MyUISupportFunction(CheckListBox1);
end;
于 2013-03-26T13:42:17.497 回答