SystemSizeOf (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

This example makes a record, reports the size of the record, fills it, and reports the contents.

Code

type
  CustRec = record
    Name: string[30];
    Phone: string[14];
  end;

procedure TForm1.Button1Click(Sender: TObject);
 var
  P: ^CustRec;
  size: Integer;
begin
  GetMem(P, SizeOf(CustRec));
  Canvas.TextOut(10, 10, 'The size of the record is ' + IntToStr(SizeOf(CustRec)));
  P.Name := 'a12345678901234567890123456789';
  P.Phone := '9,1,4085551212';
  Canvas.TextOut(10, 40, 'Name was assigned this string: ' + P.Name);
  Canvas.TextOut(10, 70, 'Phone was assigned this string: ' + P.Phone);
  size := SizeOf(CustRec);
  FreeMem (P, size);
end;

Uses