Reputation: 1621
I want to create a function which should give a support to TListbox or TChecklistBox as a calling parameter
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;
I wonder I could write my code working on both UI (TListBox and TChechecklist Box) more efficient
Upvotes: 1
Views: 137
Reputation: 27384
Both inherit from TCustomListBox
Procedure MyUISupportFunction (aListBox : TCustomListBox);
begin
aListBox.Items.Clear;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
MyUISupportFunction(Listbox1);
MyUISupportFunction(CheckListBox1);
end;
Upvotes: 7