Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Procedure / Function question 1

Status
Not open for further replies.

Destruktion

Programmer
Mar 18, 2011
28
GB
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
 
I haven't used it yet, if you get it working, please post your solution, it'll be interesting to see it in action.
 
I will check it out, and will post back if I manage to work it out.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top