Registros en Delphi
Un registro TShelter une un nombre con un conteo de camas y viaja entero hacia una función.
program RecordsBasics;
type
TShelter = record // a record groups named fields into one value
Name: string;
Beds: Integer;
end;
function Roomy(const S: TShelter): Boolean;
begin
Result := S.Beds >= 12; // fields are reached through the dot
end;
var
Corrour: TShelter;
begin
Corrour.Name := 'Corrour Bothy';
Corrour.Beds := 14;
WriteLn(Corrour.Name, ' roomy: ', Roomy(Corrour));
end.
Cómo funciona
TShelter = recorddeclara los camposName: string;yBeds: Integer;.Corrour.NameyCorrour.Bedsse asignan a través del punto.Roomy(const S: TShelter)recibe el registro completo y evalúaS.Beds >= 12.
Palabras clave y builtins usados aquí
BooleanIntegerResultWriteLnbeginconstendfunctionprogramrecordstringtypevar
El intento, en números
- Líneas
- 19
- Caracteres a escribir
- 391
- Tokens
- 82
- Ritmo de tres estrellas
- 75 tpm
Al ritmo de tres estrellas de 75 tokens por minuto, este intento toma unos 66 segundos.
Paso 3 de 3 en Arreglos y registros; paso 15 de 27 en Fundamentos del lenguaje.