Parámetros const y var en Delphi
Tune lee un nombre de emisora const y escribe de vuelta por un parámetro var.
program ParamsConstVar;
// const promises the callee will not change the argument.
// var passes the caller's variable itself, so writes stick.
procedure Tune(const Station: string; var Dial: Integer);
begin
WriteLn('tuning to ', Station);
Dial := Dial + 3;
end;
var
Dial: Integer;
begin
Dial := 88;
WriteLn('before: ', Dial);
Tune('Radio Orkney', Dial);
WriteLn('after: ', Dial);
end.
Cómo funciona
procedure Tune(const Station: string; var Dial: Integer);mezcla las dos clases.Dial := Dial + 3;cambia la variable del llamador y no una copia.- Imprimir
Dialantes y después de la llamada muestra el 88 volviéndose 91.
Palabras clave y builtins usados aquí
IntegerWriteLnbeginconstendprocedureprogramstringvar
El intento, en números
- Líneas
- 18
- Caracteres a escribir
- 388
- Tokens
- 78
- Ritmo de tres estrellas
- 75 tpm
Al ritmo de tres estrellas de 75 tokens por minuto, este intento toma unos 62 segundos.
Paso 3 de 3 en Procedimientos y funciones; paso 12 de 27 en Fundamentos del lenguaje.