我想创建一个函数,它应该支持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)上更有效地编写我的代码
答案 0 :(得分:7)
两者都继承自TCustomListBox
Procedure MyUISupportFunction (aListBox : TCustomListBox);
begin
aListBox.Items.Clear;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyUISupportFunction(Listbox1);
MyUISupportFunction(CheckListBox1);
end;