Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie questio about procedures

Status
Not open for further replies.

skwattrinated

Technical User
Mar 2, 2005
7
0
0
IT
Hi!
Please don't blame me for my, I know, stupid question. I searched on the on-line help, the net and the forum, but I was not able to solve.
I have a procedure that just write something in a Memo when I press a Button, and it is called from inside the OnClick event procedure. I paste my code hereafter:

Code:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    EditElenco: TEdit;
    MemoOut: TMemo;
    Label2: TLabel;
    EditFasce: TEdit;
    Label3: TLabel;
    EditOut: TEdit;
    ButtonCalcola: TButton;
    procedure ButtonCalcolaClick(Sender: TObject);
    procedure LeggiElenco(FileElenco: AnsiString);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure LeggiElenco(FileElenco: AnsiString);
begin
  MemoOut.Lines.Add('Leggo elenco dei file da analizzare');
end;

procedure TForm1.ButtonCalcolaClick(Sender: TObject);
begin
  LeggiElenco(EditElenco.Text);
end;

end.

The problem is that when I compile this code, MemoOut object is not recognized inside LeggiElenco procedure [error: Undeclared identifier: MemoOut], and I can't understand why...

Could you help me, please?
Thanks
 
you just forget one thing :

Code:
//original code
procedure LeggiElenco(FileElenco: AnsiString);
begin
  MemoOut.Lines.Add('Leggo elenco dei file da analizzare');
end;

//must be

procedure [b]TForm1.[/b]LeggiElenco(FileElenco: AnsiString);
begin
  MemoOut.Lines.Add('Leggo elenco dei file da analizzare');
end;

that should do it :)

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
The compiler expects a link between Form1 and MemoOut


in the implementation section use:
procedure TForm1.LeggiElenco(FileElenco: AnsiString);


Steven
 
I'm using Delphi 6 and whenever I declare a new method of a class e.g.
Code:
procedure Test;
I leave the cursor on the same line and press <CTRL+SHIFT+C> and an empty framework for defining the method is filled out in the Implementation section of my unit as shown:
Code:
procedure TForm1.Test;
begin

end;
The advantage of this is that I don't risk forgetting to put the class name in front of the method name, as you did in your first post.

Clive
Runner_1Revised.gif

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"To err is human, but to really foul things up you need a computer." (Paul Ehrlich)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
To get the best answers from this forum see: faq102-5096
 
A procedure is not the same as a form's method.

If you omit "TForm1." then you are creating a stand-alone private procedure within the unit, which therefore has no knowledge of any of the object(s) defined in the unit. Legal, but probably not what you intended to do.
 
Thanks to everybody for your help.
Reading this forum is always very very helpful!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top