SystemVarClear (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example shows how to use the TVarData type in typecasts of Variant variables to access the internals of a variable.

Code

procedure TForm1.Button1Click(Sender: TObject);
var
  V: Variant;
  mystr: string;
  MyBuffer: PChar;
begin
  if TVarData(V).VType = varEmpty then
    ListBox1.Items.Add('Variants start empty.');
  VarClear(V);
  TVarData(V).VType := varString;
  mystr := 'Here is my string';
  MyBuffer:= GetMemory(Length(mystr));
  StrCopy(MyBuffer, PChar(mystr));
  TVarData(V).VString := MyBuffer;
  ListBox1.Items.Add('This variant is now a string: ' + PChar(TVarData(V).VString));
  VarClear(V);
  TVarData(V).VType := varInteger;
  TVarData(V).VInteger := 1234567;
  ListBox1.Items.Add('This variant is now an integer: ' + IntToStr(TVarData(V).VInteger));
end;

Uses

Personal tools
Assistance