TARec=record
a:widestring;
b:widestring;
c:widestring;
end
// TARec ---> Variant
function RecordToVariant(value:TARec):OleVariant;
var
P:Pointer;
begin
Result := VarArrayCreate([0,sizeof(TARec)],varByte);
P := VarArrayLock(Result);
Move(value,P^,sizeof(P));
VarArrayUnlock(Result);
end;
// OleVariant ----> TARec
function VariantToRecord(value:OleVariant):TARec;
var
P:Pointer;
begin
P:= VarArrayLock(value);
Move(P^,Result,sizeof(TARec));
VarArrayUnlock(value);
end;
By default, Variants can hold values of any type except records, sets, static arrays, files, classes, class references, and pointers. In other words, variants can hold anything but structured types and pointers. They can hold interfaces, whose methods and properties can be accessed through them. (See Object interfaces.) They can hold dynamic arrays, and they can hold a special kind of static array called a variant array. (See Variant arrays.) Variants can mix with other variants and with integer, real, string, and Boolean values in expressions and assignments; the compiler automatically performs type conversions.