Sandeepan Kashyap schrieb:
> Thanks DoDi,
>
> I am actually an experienced Mumps/Cache developer and have to learn
> Delphi for a new project. I am actually trying to print a series of
> number in ascending order, e.g. 1,2,3,4,5,6,7,8,9 but in every number
> should print in new followed line. like
> 1
> 2
> 3
> ..
Let's look into this later, it depends on what you mean by "printing".
When you want to show multiple lines on a form, use a TListBox or TMemo,
not an TLabel.
> I tried the below code. But the below code printing '0' always inside Label3, don't know why? what's is wrong with the code. Please enlighten me.
>
> type
> TIntegerArray = Array[1..9] of Integer;
> var
> x,y : integer;
> txt: string;
> i: integer;
> arrayOfIntegers : TIntegerArray;
> begin
> Form1.Color := clGreen;
> x := StrToInt(Edit1.Text);
> y := StrToInt(Edit2.Text);
>
> i := 1 ;
> begin
> while (i = 9) do
> arrayOfIntegers[i] := i;
> Inc(i);
> end;
Can you answer these questions:
What's the value of i here?
What's the value of arrayOfIntegers[i]?
> Label3.Caption := IntToStr(arrayOfIntegers[i]);
Please try to learn how to use the Delphi debugging features. When you
put an breakpoint somewhere in this procedure, e.g. on "i := 1;", you
can step through the following code and inspect all variables by moving
the mouse pointer over the name of a variable. It even will show you the
content of arrayOfIntegers[i], depending on the current value of i.
Then you'll find that the array is not initialized, because the condition in
while (i = 9) do ...
is never True.
Okay, this may be a typo, should read (i <= 9) instead?
Please fix this and try again.
Finally I assume that you expect too much from IntToStr(), in case you
want to display *all* array elements at once. That doesn't work, for two
reasons:
- IntToStr only converts an single value
- arrayOfInteger[i] is a single value, not the entire array
You need another loop over the array, adding the values to an result
string or to a ListBox control.
DoDi