search an array

I want make a function that will search an array.
Can I make just one function to search all data types (using the variant
data type) or do I need to make a seperate function for each type. ie one
for string, longint, double, etc.
I would like to use just one function but am not sure how you distinguish what data type has been passed as the variant array - or if in fact you can do this. I am using delphi 3.02
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

jonnyfiveConnect With a Mentor Commented:
Hi everyone...

since clyde is using Delphi 3, he can't use overload. I don't know if the command "VarType" exists in D3, but you can check anyway. This would give you the type of the variant. If you want to convert your variant to a certain type, simply use the .AsInteger, .AsString, etc. after your variable. Like
"if MyVariant.AsString = 'Hello World' then DoSomething;"

Hope that helps...

Kind regards, Jonny...
You certainly could use variants, both for the thing you want to search for and for the array, however, even Borland points out that variants are not very effecient.  And as you get into them you will find them not easy either. I suggest you would be much better off doing several seperate functions within a single class and using overloaded methods.

TSearchClass = class
  function Search(ForAnInteger : integer; IntArray : array of Integer): boolean; overload;

  function Search(forAChar : string; CharArray : array of Char): boolean; overload;

All Courses

From novice to tech pro — start learning today.