Save variant value in properties of TStringList object

I need to save the option value in a TStringList while I try this

 var list : TStringList; v : OleVariant; List..AddObject('Item1',v); 

or

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

but in both cases the code does not compile because the type is invalid or the types are incompatible.

so the question is, how can I save the value of a variant in a TStringlist?

+4
source share
2 answers

I think the only way would be to turn your variant into a class and put a reference to the object in the object of the stringlist element. Of course, you should make sure that the wrapper instances are correctly freed when the string list is freed. Using the recent version of Delphi, which is easy to do using the "OwnsObjects" parameter of the string list.

+8
source

I believe that you need to save the address of the option record:

  List..AddObject ('Item1', TObject (@v));
+1
source

All Articles