28

I have a some numbers stored in a Integer called mode, but I need to use they in a TProcess. For this I need to convert the Integer into a String, because if I don't do this, I got the error:

Incompatible types: got "LongInt" expected "AnsiString"

Then I want to know how I can convert a Integer into a String?

Nathan Campos
  • 28,769
  • 59
  • 194
  • 300
  • 5
    I'd like the two people who voted down this question to come forward. What's not useful about this question? Is it unclear? What part of *No question is too trivial or too "newbie"* do you not understand? – Rob Kennedy Dec 31 '09 at 20:52
  • 1
    http://www.google.pl/search?client=opera&rls=pl&q=delphi+integer+to+string&sourceid=opera&ie=utf-8&oe=utf-8 - and you have answer after 1 sec – inzKulozik Dec 31 '09 at 21:12
  • 3
    @inzKulozik, I would love SO to be the first link when someone else googles it! – notnoop Dec 31 '09 at 23:12

2 Answers2

45

You can use IntToStr:

A:=IntToStr(123)
notnoop
  • 58,763
  • 21
  • 123
  • 144
3

I just did my first steps with a 30day test version of Delphi XE8 and figured out that one has to write e.g.

  Ticks: integer;
  LabelTicks: TLabel;
  (...)
  LabelTicks.Text:= System.SysUtils.IntToStr( Ticks);

But: The variable 'Ticks' seems to be an object! I did not expect that, but you can also write

  LabelTicks.Text:= Ticks.ToString;

To me that seems to be much more elegant.

  • 1
    `Ticks` is not an object. You stumbled on the intrinsic record helper for simple types, see [Integer Type Helpers](http://docwiki.embarcadero.com/CodeExamples/en/Integer_Type_Helpers_(Delphi)). – LU RD Jun 15 '15 at 18:59