Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

store variant value in object property of TStringList

i need store a variant value in a TStringList, so far i try this

var
 list : TStringList;
 v   : OleVariant;

  List..AddObject('Item1',v);

or

  List..AddObject('Item1',TObject(v));

but in both cases the code not compile because the typecast is invalid or the types are incompatibles.

so the question is, how i can store a variant value in a TStringlist ?

like image 462
Salvador Avatar asked Jan 21 '23 22:01

Salvador


1 Answers

I think the only way would be to wrap your variant in a class and put a reference to that in the object of the stringlist item. You would of course need to take care that the wrapper instances are properly freed when freeing the stringlist. Using the recent Delphi version's that would easily be done by using the "OwnsObjects" parameter of the stringlist.

like image 108
Marjan Venema Avatar answered Feb 04 '23 06:02

Marjan Venema