type
Myrec = record
ID: Integer;
NAME: string;
WERT: Double;
end;
var
tst: Myrec;
VarValue: Variant;
procedure RecordToVarArray(var vData: Variant; rcd: Myrec);
begin
vData := VarArrayCreate([0, 2], varVariant);
with rcd do begin
vData[0] := ID;
vData[1] := NAME;
vData[2] := WERT;
end;
end;
// VarArray erzeugen
procedure TForm1.Button1Click(Sender: TObject);
begin
with tst do begin
ID := 12345;
NAME := 'TEST';
WERT := 13.98;
end;
RecordToVarArray(VarValue, tst);
end;
// Zugriff auf Element 3 (Wert)
procedure TForm1.Button2Click(Sender: TObject);
begin
if TVarData(VarValue).VType = varEmpty then
showmessage('Variant ist noch nicht gefüllt') else
showmessage(VarValue[2]);
end;