Reputation: 43
I need a class similar to TStringList that could manage name & value pairs, but the value part is variant. Or perhaps it has a property like TStringList.Object but holds variants instead of objects.
Could anyone please point me to a free or open source implementation? I use Delphi 7.
Thank you.
Upvotes: 0
Views: 1957
Reputation: 114
PVariantRec = ^TVariantRec;
TVariantRec = record
Value : Variant;
end;
var
lItem : PVariantRec;
lMyStringList : TStringList;
lMyStringList := TStringList.Create;
lMyStringList.Sorted := true;
lMyStringList.OwnObjects := false;
//add
New(lItem);
lItem.Value := 'zzz';
lMyStringList.Add('name', TObject(lItem));
//remove
lItem := PVariantRec( lMyStringList.Objects[0] );
Dispose(lItem);
lMyStringList.Delete(0);
Upvotes: 1
Reputation: 47758
You can derive from TStringList and use the Objects property to hold a wrapper object for a variant.
Upvotes: 3
Reputation: 84590
If you have Delphi 2009 or 2010, you can use the TStringList<T>
class in DeHL to create a TStringList<Variant>
. (You could also use TDictionary, but TStringList has a lot of extra functionality that you might not want to lose.)
Upvotes: 3
Reputation: 32334
You have not given the Delphi version this is intended to be used with, but starting with Delphi 2009 you can use a TDictionary<string, Variant>
.
Upvotes: 4