Records in Delphi - ablealias/Delphi GitHub Wiki
Records provide a very neat way of having named data structures - groups of data fields. Unlike arrays, a record may contain different types of data. Records are fixed in size - the definition of a record must contain fixed length fields. We are allowed to have strings, but either their length must be specified (for example a : String[20]), or a pointer to the string is stored in the record. In this case, the record cannot be used to write the string to a file.
type
TCustomer = record
name : string[30];
age : byte;
end;
var
customer : TCustomer;
begin
// Set up our customer record
customer.name := 'Fred Bloggs';
customer.age := 23;
end;
with
keyword
Using the When we are dealing with large records, we can avoid the need to type the record variable name. This avoidance, however, is at a price - it can make the code more difficult to read:
type
TCustomer = record
name : string[30];
age : byte;
end;
var
John, Nancy : TCustomer;
begin
// Set up our customer records
with John do
begin
name := 'John Moffatt'; // Only refer to the record fields
age := 67;
end;
with Nancy do
begin
name := 'Nancy Moffatt'; // Only refer to the record fields
age := 77;
end;
end;