Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.pascal.delphi.misc > #625

Re: display array values in a label

Newsgroups comp.lang.pascal.delphi.misc
Date 2014-09-15 02:34 -0700
References <917dbf9e-f5aa-4a84-ba56-b1c1ff3e354e@googlegroups.com> <c7dncrFmuvU1@mid.individual.net> <adf4df8d-e0b5-4e07-ac77-01d76a5a83ad@googlegroups.com> <c7gkjuFnou9U1@mid.individual.net>
Message-ID <c40318a8-ab31-4ee2-9b8d-2d12e60bb490@googlegroups.com> (permalink)
Subject Re: display array values in a label
From Sandeepan Kashyap <sandeepan1982@gmail.com>

Show all headers | View raw


On Friday, September 12, 2014 9:47:04 PM UTC+5:30, Hans-Peter Diettrich wrote:
> 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

Thanks DoDi, I tried few things last Friday and it worked for me. the below code worked for me. 

There are other things that I will be learning gradually. Dodi, could you please share some good Delhpi coding links (where I can get the coding content). 
Also, I am looking to learn debugging.
    Form1.Color := clCream;
      k := StrToInt(Edit1.Text);
    {$R+}   // Set range checking on
    For j := 1 to k do
    begin
    TIntegerArray[j] := ' '+IntToStr(j);  // ' ' to get the data in the next line
    end;
    For i := 1 to k do
    begin
               If i = 1
                then result :=  TIntegerArray[i]
                else result :=  result + TIntegerArray[i];
    end;
        Label3.Caption := result+sLineBreak;

Back to comp.lang.pascal.delphi.misc | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

display array values in a label Sandeepan Kashyap <sandeepan1982@gmail.com> - 2014-09-11 04:02 -0700
  Re: display array values in a label Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2014-09-11 15:44 +0200
    Re: display array values in a label Sandeepan Kashyap <sandeepan1982@gmail.com> - 2014-09-11 23:24 -0700
      Re: display array values in a label Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2014-09-12 18:01 +0200
        Re: display array values in a label Sandeepan Kashyap <sandeepan1982@gmail.com> - 2014-09-15 02:34 -0700
          Re: display array values in a label Sandeepan Kashyap <sandeepan1982@gmail.com> - 2014-09-15 02:36 -0700
          Re: display array values in a label Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2014-09-15 14:14 +0200
  Re: display array values in a label "Alan Lloyd" <alanglloyd@NotThisBitbtinternet.com> - 2014-09-25 11:51 +0100
    Re: display array values in a label Sandeepan Kashyap <sandeepan1982@gmail.com> - 2014-09-26 05:58 -0700
      Re: display array values in a label "Alan Lloyd" <alanglloyd@NotThisBitbtinternet.com> - 2014-09-26 19:53 +0100

csiph-web