Incompatible types: 'Integer' and 'procedure, untyped pointer or untyped parameter'

StackOverflow https://stackoverflow.com/questions/21802534

  •  12-10-2022
  •  | 
  •  

Question

I'm getting an error giving a variable a counting value (Don't know if that makes sense).

iCount := inc(iCount,1);

Here's my code:

var
  iCount : Integer;
procedure TForm1.FormActivate(Sender: TObject);
begin
  edtOutput.SelAttributes.size := 10;
  edtOutput.SelAttributes.name := 'Courier';
  edtOutput.Lines.Add(('Name') + #9 + #9 + ('Age') + #9 + #9 + ('Child or adult'));
end;

procedure TForm1.btnOKClick(Sender: TObject);
var
  sName     :String;
  iAge      :Integer;
begin
  iCount := inc(iCount,1);   // <--- HERES THE ERROR
  sName := edtName.text;
  iAge := edtAge.value;

When I give iCount its value, I get this error :

Incompatible types: 'Integer' and 'procedure, untyped pointer or untyped parameter'

oh, and edtOutput is a RichEdit. I have copied it exactly how my textbook says I must (Not the whole program, just the iCount thing)

Any advice on how to fix this would be greatly appreciated!

Était-ce utile?

La solution

The signature of inc is described in the documentation:

procedure Inc(var X: Ordinal; [ N: Integer]); overload;
procedure Inc(var X: Ordinal; [ N: Integer]); overload;

In other words it is a procedure that receives the variable to be incremented as a var parameter. It is not a function and does not return a value.

Your code should be:

inc(iCount);

Autres conseils

Inc(ICount, 1); is all you need.

alternative:

ICount := ICount + 1;
Inc(iCount); // This increases by one, by default.
Inc(iCount, x); // This increases by x, where x is an integer.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top