Error showing local variable in Delphi: "Record, object or class type required"

1

I'm trying to show a local variable in a message, but I'm not clear on the concept.

Code:

procedure TForm1.Button1Click(Sender: TObject);
var
 i:integer;
begin
 i:=1;
 ShowMessage(i.AsString);
end;

Error:

[Error] Unit1.pas(31): Record, object or class type required
    
asked by Goerman 23.02.2016 в 13:16
source

1 answer

1

On the Embarcadero documentation on this error , it is specified that it can happen for one of these two reasons:

  • When applying the notation '.' to an element that is not an object, record, or class variable.
  • When using a variable with the wrong type in a WITH command.

It is not the second case, but the first, because you try to apply .AsString to a variable of type int that is not an object or record.

A quick solution would be to use inttostr(i) instead of i.AsString :

ShowMessage(inttostr(i));
    
answered by 23.02.2016 / 14:08
source