Delphi: Passing Tobject in a Variants array

I have a program that requires a parameter of type TObject, as shown below:

MyProcedure (const AValue: TObject );

I have a Variant array, and I am calling the procedure in a loop, as shown below:

for i:=0 to High(myArray) do
MyProcedure (myArray[i]);

The compiler gives an error saying: “Incompatible types: TObject and Variant”.

How can I do it? solve this problem?

More information: So far, I have been passing simple types (strings, numbers, dates) in variable arrays (arrays are usually a mix of different types-I ended up passing them as parameters to the database Stored procedure). Now I still need (in some cases) to pass a TObject.

What is the most suitable data type/structure for passing the value, it can contain simple types and objects? I think I can create my own TParam type, it has two fields, but I am not sure of the exact syntax. Does anyone have an example of this?

Variant cannot save objects, it can only contain basic types such as integers and strings.

I recommend changing your array to the type you want instead of a variant. If you are not sure of the type of object you need, create a TObject array or the lowest base class of the object that the array will hold .

I have a program that requires a parameter of type TObject, as shown below:

MyProcedure (const AValue: TObject);

I have a Variant array, and I am calling the procedure in a loop, as shown below:

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 solve this problem?

More information: So far, I have been passing simple types (strings, numbers, dates) in variable arrays (arrays are usually a mix of different types-I ended up passing them as parameters to the database Stored procedure). Now I still need (in some cases) to pass a TObject.

What is the most suitable data type/structure for passing the value, it can contain simple types and objects? I think I can create my own TParam type, it has two fields, but I am not sure of the exact syntax. Does anyone have an example of this?

Variant cannot save objects, it can only contain basic types such as integers and strings.

I suggest that your Change the array to the type you want instead of a variant. If you are not sure about the type of object you need, create a TObject array or the lowest base class of the object that the array will hold.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3170 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.