Is there anyway to use the property like behavior?

前端 未结 3 1299
终归单人心
终归单人心 2021-01-29 12:11

I have the following formula

X := X + F*(1-i div n);

Where

X, F, i, n: integer;

The code I\'m using is this<

3条回答
  •  悲哀的现实
    2021-01-29 12:54

    You can use local function like

    procedure YourProcedure;
    
    var
      X: Integer;
      LJ: Integer;
    function J: Integer;
    begin
      Inc(LJ);
      Result := LJ;
    end; 
    procedure SetX(const AValue: Integer);
    const
      Xmax: SomeIntegerValue;
    begin
      if aValue > Xmax then X := 0  
      else X := aValue; 
    end;
    //...
    begin
      while J < Hn do  // J will be incremented each time the loop wants to  read it.    
      begin
         SetX(X + F * (1 - i div n));
      end
    end.
    

提交回复
热议问题