¿Hay alguna forma de usar la propiedad como comportamiento?
Tengo la siguiente formula
X := X + F*(1-i div n);
Dónde
X, F, i, n: integer;
El código que estoy usando es este
F := 7; // the initial speed with no friction.
n := 10; // the animation number of steps.
Hn := n * 2 ;
X := 0; // first Pos
i := 1;
J := 1;
while J < Hn do
begin
X := X + F * (1 - i div n);
if X > Xmax then X := 0; <-- line (1).
if i >= n then Dec(i)
else Inc(i);
Inc(J);
end;
Si fuera posible, me gustaría usar esto, pero sin implementación de clase / registro (no dentro de una implementación / método de clase / registro) .No la sintaxis exacta, solo el mismo principio, en lugar de la asignación directa a X, se llama a SetX el resultado se asigna a X.
X: integer write SetX; // This is not a correct delphi syntax. I added it to explain the behavior I want.
function SetX(aValue: integer): integer;
const
Xmax: SomeIntegerValue;
begin
if aValue > Xmax then result := 0
else result := aValue;
end;
Entonces podría omitir la línea (1). Si esto fuera posible, se omitirían todas las líneas después de la fórmula y el bucle while se vería así
while J < Hn do // J will be incremented each time the loop wants to read it.
begin
X := X + F * (1 - i div n);
end;
¿Hay alguna forma de usar la propiedad como comportamiento?
Nota: Estoy buscando una manera de alterar la asignación y las formas de lectura de una variable como lo hace en una propiedad de un registro / clase.