类 / 方法

type
  TCalc = class
  public
    LastSum: Integer;
    function GetSum(N1N2Integer): Integer;
  end;

function TCalc.GetSum(N1N2Integer): Integer;
begin
  LastSum := N1 + N2;
  Result := LastSum;
end;

var
  Calc: TCalc;
  Sum1, Sum2: Integer;
begin
  Calc := TCalc.Create;

  Sum1 := Calc.GetSum(53);
  //sum1 is 8

  Sum2 := Calc.GetSum(23);
  //sum2 is 5

  WriteLn('sum1 = ', Sum1);
  WriteLn('sum2 = ', Sum2);
  WriteLn('calc.LastSum = ', Calc.LastSum);
end.