record
record is a declaration statement that defines a record data type containing one or more elements.
syntax
record name is fieldname: typename; [fieldname: typename;] end
- name is the record name that identifies this specific record type. Variable naming rules for identifiers apply.
- fieldname identifies this field of the record. Variable naming rules for identifiers apply.
- typename is any numeric data type, a buffer type or another record type.
See also struc, buffer type
details
A record data type is a user-defined type with a fixed length. Fields must be the size of their type, without descriptors or variable length. Therefore, both variable and fixed-length strings cannot be declared as record fields. The buffer type, which can also act as a string holder, should be used instead. If more flexibility is required, use a structure.
Records can be nested, as shown in the example below. However, a record field cannot be of the same type as its own record.
A record instance can be assigned to another instance of the same record type, in which case a full copy is performed.
Records are ideal for communicating with libraries of other languages to provide memory blocks with predefined fields of fixed length.
example
' SharpBASIC record programming example
' -------------------------------------
option strict;
incl "lib/sys.sbi";
record r_address is
street : byte * 24;
house : byte * 8;
zip : byte * 16;
phone : byte * 16;
email : byte * 32;
end
record r_person is
recordNumber : uint;
firstName : byte * 32;
lastName : byte * 24;
birthDate : byte * 10;
birthPlace : byte * 24;
address : r_address;
padded : byte * 2;
end
dim person, person_copy: r_person;
main do
person.recordNumber = 104;
person.firstName = "John";
person.lastName = "Smith";
person.birthDate = "1965-04-16";
person.birthPlace = "Denver";
person.address.street = "Clay Street";
person.address.house = 5025;
person.address.zip = "CO 80221";
person_copy = person;
print(person_copy.lastName);
end
Output:
Smith