I'm trying to display 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;
Mistake:
[Error] Unit1.pas(31): Record, object or class type required
Embarcadero 's documentation on this error specifies that it can occur for one of two reasons:
It is not the second case, but the first, because it is intended to apply
.AsString
to a variable of typeint
that is not an object or record.A quick fix would be to use
inttostr(i)
instead ofi.AsString
:In modern versions of Delphi, you can use a notation quite similar to the one that is giving you the error, as long as you have included the unit
system.sysutils
within the unit clauseuses
that contains the code, you can call the methodToString()
on an integer variable, which, behind the scenes, will pull the type helperTIntegerHelper
, the correct syntax is:In the documentation you can find more examples of the methods available in integer type helpers and more information about type helpers in general.
If you don't include the unit
sysutils
in the uses clause, these helpers won't be available to your code.All links take you to resources in English.
I think what you need to do is change the:
For: