Destruktion
Programmer
Hey, another question I hope someone can help with.
Over the years I have been using Delphi I have created some units that contain procedures and functions that are reusable, for example:
function ListBoxIsSelected(ListBox: TListBox): Boolean;
begin
Result:= ListBox.ItemIndex <> -1;
end;
just an example, the above returns true if an item in a TListBox is selected. Now onto my problem/question...
The above uses TListBox as a parameter, so whenever the above function is used I must supply a listbox that is of TListBox class.
Ok, now suppose I have some other component libraries that could work with the same function, For example the Jedi component classes.
How could I use the above function, when the Jedi listbox is TJvListBox class, my function is looking for TListBox class. Although both components are practically the same, the class names are different. If I provided the same function specifically for the TJvListBox it would likely work:
function ListBoxIsSelected(ListBox: TJvListBox): Boolean;
begin
Result:= ListBox.ItemIndex <> -1;
end;
Now, I have whole load of procedures and functions written in the same kind of way where I need to pass a component as a parameter. I guess my problem and question is, is it possible to pass any other component type to my original function, even though I have it looking for TListBox?
Easier still, instead of having to rewrite my function to allow TJvListBox be used, be able to pass a TJvListBox to the function that looks for the TListBox.
Hope thats make sense?!
Thanks
Over the years I have been using Delphi I have created some units that contain procedures and functions that are reusable, for example:
function ListBoxIsSelected(ListBox: TListBox): Boolean;
begin
Result:= ListBox.ItemIndex <> -1;
end;
just an example, the above returns true if an item in a TListBox is selected. Now onto my problem/question...
The above uses TListBox as a parameter, so whenever the above function is used I must supply a listbox that is of TListBox class.
Ok, now suppose I have some other component libraries that could work with the same function, For example the Jedi component classes.
How could I use the above function, when the Jedi listbox is TJvListBox class, my function is looking for TListBox class. Although both components are practically the same, the class names are different. If I provided the same function specifically for the TJvListBox it would likely work:
function ListBoxIsSelected(ListBox: TJvListBox): Boolean;
begin
Result:= ListBox.ItemIndex <> -1;
end;
Now, I have whole load of procedures and functions written in the same kind of way where I need to pass a component as a parameter. I guess my problem and question is, is it possible to pass any other component type to my original function, even though I have it looking for TListBox?
Easier still, instead of having to rewrite my function to allow TJvListBox be used, be able to pass a TJvListBox to the function that looks for the TListBox.
Hope thats make sense?!
Thanks