type
TVarRec = record
Data: record case Integer of
0: (L: LongInt);
1: (B: Boolean);
2: (C: Char);
3: (E: ^Extended);
4: (S: ^String);
5: (P: Pointer);
6: (X: PChar);
7: (O: TObject);
end;
Tag: Byte;
Stuff: array[0..2] of Byte;
end;
function PtrToStr(P: Pointer): String;
const
HexChar: array[0..15] of Char = '0123456789ABCDEF';
function HexByte(B: Byte): String;
begin
Result := HexChar[B shr 4] +
HexChar[B and 15];
end;
function HexWord(W: Word): String;
begin
Result := HexByte(Hi(W)) + HexByte(Lo(W));
end;
begin
Result := HexWord(HiWord(LongInt(P))) + ':' + HexWord(LoWord(LongInt(P)));
end;
procedure Display(X: array of const);
var
I: Integer;
begin
for I := 0 to High(X) do
with TVarRec(X[I]), Data do
begin
case Tag of
0: ShowMessage('Integer:
' + IntToStr(L));
1: if B then
ShowMessage('Boolean: True')
else ShowMessage('Boolean:
False');
2: ShowMessage('Char:
' + C);
3: ShowMessage('Float:
' + FloatToStr(E^));
4: ShowMessage('String:
' + S^);
5: ShowMessage('Pointer:
' + PtrToStr(P));
6: ShowMessage('PChar:
' + StrPas(X));
7: ShowMessage('Object:
' + O.ClassName);
end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
P: array[0..5] of Char;
begin
P := 'Привет'#0;
Display([-12345678, True, 'A', 1.2345, 'ABC', Ptr($1234, $5678), P,
Form1]);
end;