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
Post by Sandeepan KashyapThanks 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
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.
Post by Alan LloydYou'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
Post by Sandeepan KashyapHello,
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;