1

I want to display certain integers in a memo, listbox or whatever. I've tried a memo, listbox and showmessage() but each throws incompatibility error between string and integers.

This is where it starts going wrong:

Memo1.Lines.Add('Physical Functioning: '+PhysFunc div PhysCount);

PhysFunc and PhysCount are integers calculated further up. I've tried, e.g.:

Memo1.Lines.Add('Physical Functioning: '+IntToStr(PhysFunc div PhysCount));

and:

Memo1.Lines.Add(IntToStr('Physical Functioning: '+PhysFunc div PhysCount));

and:

Memo1.Lines.Add(('Physical Functioning: '+PhysFunc div PhysCount).AsString);

And the same things with a ListBox and showmessage(). But none work. IntToStr returns E2003 undeclared identifier and .AsString returns the error, integer does not contain a member 'AsString'. Are there any alternatives?

I'm using an SDI application in Delphi - could that be the problem?

Thanks

4

3 に答える 3

6

You are calling the Add method of TStrings which receives a single parameter of type string. You need to concatenate a string and an integer. In order to do so you must convert the integer into a string.

You attempted to do that using IntToStr which is a perfectly reasonable approach. But that failed because the compiler could not locate IntToStr. Now, IntToStr is declared in the SysUtils unit and so you must add that unit to your uses clause.

However, I'd probably use Format here. Like IntToStr, this function is declared in SysUtils which you must use.

Memo1.Lines.Add(Format('Physical Functioning: %d', [PhysFunc div PhysCount]));

For more details on format read the documentation for format strings.

于 2013-02-07T09:00:50.017 に答える
0

The first line of code doesn't work because PhysFunc div PhysCount is an integer and it is not converted to a string.

The second line of code should work, but I would check the actual values of PhysFunc and PhysCount. Is it possible that PhysCount is, somehow, equal to 0?

The third line of code doesn't work because IntToStr expects integers and you gave him, among others, a string.

The fourth line of code doesn't work because, as you said, integer does not contain a member 'AsString'

You also said:

IntToStr returns E2003 undeclared identifier

That could also be the problem: one of the two variables is not declared. Make sure that both of them are declared in the var section.

To conclude:

  1. Check to see if both variables are declared;
  2. Check to see if PhysCount <>0 at the time of the evaluation.

Good luck!

于 2013-02-07T09:00:14.900 に答える
0

Just look at the uses if there is the SysUtils included.

于 2018-07-11T13:32:37.270 に答える