Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.pascal.delphi.misc > #632
| From | "Alan Lloyd" <alanglloyd@NotThisBitbtinternet.com> |
|---|---|
| Newsgroups | comp.lang.pascal.delphi.misc |
| References | <917dbf9e-f5aa-4a84-ba56-b1c1ff3e354e@googlegroups.com> |
| Subject | Re: display array values in a label |
| Date | 2014-09-25 11:51 +0100 |
| Message-ID | <sKidnUMJuvQ2br7JnZ2dnUVZ8lKdnZ2d@bt.com> (permalink) |
You've got an excess begin / end so the last three lines are outside the
procedure, its a wonder it compiled.
You'd be better indenting your code appropriately.
But your basic error is not inserting carriage returns (#13) between each
character.
In any case, why transfer the edit.text to integers & then back to text. A
simpler code is below, and an ever better coding which is more OO is after
that, using an independent procedure called from the On Click.
procedure TForm1.Button2Click(Sender: TObject);
var
i : integer;
Txt: string;
const
CR = #13;
begin
Self.Color := clAqua;
Txt := '';
for i := 1 to Length(Edit1.Text) do begin
Txt := Txt + Edit1.text[i] + CR
end;
SetLength(Txt, Length(Txt) - 1);
Label3.Caption := Txt;
end;
// better coding
procedure TForm1.Button3Click(Sender: TObject);
begin
Self.Color := clAqua;
ShowDigits(Edit1, Label3);
end;
procedure TForm1.ShowDigits(AnEdit : TEdit; ALabel : TLabel);
var
i : integer;
Str: string;
const
CR = #13;
begin
Str := '';
for i := 1 to Length(AnEdit.Text) do begin
Str := Str + AnEdit.Text[i] + CR
end;
// remove final CR - easier & quicker than condition coding above
SetLength(Str, Length(Str) - 1);
ALabel.Caption := Str;
end;
Alan Lloyd
"Sandeepan Kashyap" <sandeepan1982@gmail.com> wrote in message
news:917dbf9e-f5aa-4a84-ba56-b1c1ff3e354e@googlegroups.com...
> Hello,
>
> I am new to Delphi and trying to learn it through internet.
> Could you please refer some good links for basic Delphi to learn it?
>
> Trying - While hitting button1 and it should display all the arrays values
> in defined LABEL in a form of 1,2,3... etc. every digit should come
> beneath to each other in new line.
> 1
> 2
> 3
>
> Issue - It's only displaying the last value, like if you enter 3, it's
> just displaying only 3. Please suggest what wrong I am doingg? Below Is my
> code.
>
> procedure TForm1.Button1Click(Sender: TObject);
> var
> x,y,i,Leng : integer;
> txt: string;
> MyMatrix: packed array of char;
> begin
> Form1.Color := clGreen;
> x := StrToInt(Edit1.Text);
> y := StrToInt(Edit2.Text);
>
> Leng := Length(Edit1.Text);
> SetLength(MyMatrix, leng);
> for i := 1 to 3 do begin
> begin
> MyMatrix[i] := Edit1.text[i];
> end;
> end;
> end;
> for i:= 1 to leng do begin
> txt := txt + MyMatrix[i];
> end;
> Label3.caption := txt;
Back to comp.lang.pascal.delphi.misc | Previous | Next — Previous in thread | Next in thread | Find similar
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