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


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

Re: display array values in a label

From "Alan Lloyd" <alanglloyd@NotThisBitbtinternet.com>
Newsgroups comp.lang.pascal.delphi.misc
References <917dbf9e-f5aa-4a84-ba56-b1c1ff3e354e@googlegroups.com> <sKidnUMJuvQ2br7JnZ2dnUVZ8lKdnZ2d@bt.com> <61ad2631-66ee-4223-8b83-3edac5bc79ba@googlegroups.com>
Subject Re: display array values in a label
Date 2014-09-26 19:53 +0100
Message-ID <-qSdnV6jAf-4K7jJnZ2dnUVZ8gSdnZ2d@bt.com> (permalink)

Show all headers | View raw


Sandeepan

When you define & use a procedure you must :

1) Specify the names and types of the parameters and the type of method
(procedure or function) in the interface section of the unit; either in the
class definition (TSomthing = Class (ancestor) . . . end; if its a class
method, or just in the section (if its not a class method). For this general
procedure it must be
     procedure Procname(Para1 : Paratype1; Para2: Para2type; etc etc );

2) Specify in the implementation section a repeat of the interface
definition) with the same number & type of parameters, but with the class of
the procedure prefixing the name of the procedure -
        procedure TSomething.Procname(Para1 : Paratype1; Para2: Para2type;
etc etc );
If it is not a class procedure (ie the previous definition is in the
interface section but not in a class definition) then the class name prefix
is ommitted -
        procedure Procname(Para1 : Paratype1; Para2: Para2type; etc etc );

3) Then this procedure definition in the implementation section must be
followed by var;, const, begin (your code) end; as
procedure TSomething.Procname(Para1 : Paratype1; Para2: Para2type; etc
etc );
var
  MyVar : MyVarType;
  etc, etc,
const
  MyConst = MyConstValue;
  etc, etc
begin
  my code for the procedure
  etc etc
end;

 or if the procedure is not a class method
procedure Procname(Para1 : Paratype1; Para2: Para2type; etc etc );
var
  MyVar : MyVarType;
  etc, etc,
const
  MyConst = MyConstValue;
  etc, etc
begin
  my code for the procedure
  etc etc
end;

When you call the procedure to be run, you omit the parameter types in the
call, just using the name of the item which is the input value to the
procedure. If the types or number of parameters are different between the
definition and the call, then an error will be raised (this is what happened
in your list of errors).

Try & get hold of a good book on Delphi, even if it is for an earlier
version it will be simpler and the examples should run in a later version of
Delphi.

Alan Lloyd

"Sandeepan Kashyap" <sandeepan1982@gmail.com> wrote in message 
news:61ad2631-66ee-4223-8b83-3edac5bc79ba@googlegroups.com...
> Thanks Alan for making me understand the code in a better way. 
> Evidentially, the above code makes better sense to me. There is one thing, 
> while trying to implement the above code, I am getting the below error.
>
> If I pass the parameters in the below way, I am getting error at 58 line.
> procedure ShowDigits(Edit1,Label3,Sender: TObject); //getting [Error] 
> Final.pas(58): then getting too many parameters
> procedure ShowDigits(Edit1,Label3);     //getting [Error] Final.pas(58): 
> Missing parameter type
> procedure ShowDigits(Sender: TObject);              //getting [Error] 
> Final.pas(58): Too many actual parameters.
> begin
>    Form1.Color := clCream;
>    ShowDigits(Edit1,Label3); //58 line where I am getting error
> end;
> procedure ShowDigits(AnEdit : TEdit; ALabel : TLabel);
> begin
> .
> .
> end;
>
> I guess, I am missing either the correct way of declaring the procedure or 
> may be the correct way of Type of parameters.
> Please suggest
>
> Thanks again for you help.
>
> Sandeepan.
>
>
> On Thursday, September 25, 2014 4:21:24 PM UTC+5:30, Alan Lloyd wrote:
>> 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 | NextPrevious 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