I have a procedure that expects a parameter of type TObject, something like this:
MyProcedure (const AValue : TObject);
I have an array of Variant that I'm looping through to call the procedure, something like this:
for i:=0 to High(myArray) do
MyProcedure (myArray[i]);
The compiler gives an error saying: "Incompatible types: TObject and Variant".
What can I do to get around this?
More information: Up until now, I have been passing simple types (strings, numbers, dates) in variant arrays (the arrays are typically a mix of different types -- I'm eventually passing them as parameters to a database stored procedure). Now I need to also (in certain cases) pass a TObject.
What is the most appropriate data type/structure to pass the values, that can hold both simple types and objects? I guess I could create my own TParam type that has a field for both, but I am not sure of the exact syntax. Anyone has an example of this?
A Variant cannot hold objects, it can only contain primitive types such as integer and string.
I would suggest changing your array to be of the type you want rather than variant. If you are not sure of the object type you want then create an array of TObject or the lowest possible base class of the objects that your array will hold.