Board index » delphi » HelpMe!

HelpMe!

Please help,

I am trying to overcome the most basic of problems, yet to no avail!!! :(

If i design a procedure or function within a forms unit, whenever i reference
certain objects within that form I get an "Undeclared Identifier" compile
error.

below is a procedure that causes this error.

procedure changecolor;
begin
edit2.text := edit1.text;     <= the edit2 is an undeclared identifier.
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
changecolor;
end;

surely i should be able to do this, but i can not figure out the error, please
please please help

hope i have groveled enuf for assistance.

 

Re:HelpMe!


Quote
In article <4pt5rp$...@sirius.plain.co.nz> faz...@chch.planet.org.nz (Jason Fazackerley) writes:
>From: faz...@chch.planet.org.nz (Jason Fazackerley)
>Subject: HelpMe!
>Date: 15 Jun 1996 02:06:49 GMT
>Please help,
>I am trying to overcome the most basic of problems, yet to no avail!!! :(
>If i design a procedure or function within a forms unit, whenever i reference
>certain objects within that form I get an "Undeclared Identifier" compile
>error.
>below is a procedure that causes this error.
>procedure  TForm1.changecolor;

                     ^^^^^^^^^  you need to make this a method of the form
object - encapsulation means that the procs that are not methods do not know
of objects fields.

 >begin

Quote
>tform1.edit2.text := edit1.text;     <= the edit2 is an undeclared identifier.

  ^^^^^^^ or alternatively you can explicitly tell it which edit you mean ie
who owns it.

Quote
>end;

HTH

Boris Ingram, Cyborg Software
boris...@iafrica.com
100076.3...@compuserve.com
http://www.pcb.co.za/users/borising/cyborg.htm

Re:HelpMe!


In article <4pt5rp$...@sirius.plain.co.nz>, Jason Fazackerley
<faz...@chch.planet.org.nz> writes

Quote
>Please help,

>I am trying to overcome the most basic of problems, yet to no avail!!! :(

>If i design a procedure or function within a forms unit, whenever i reference
>certain objects within that form I get an "Undeclared Identifier" compile
>error.

>below is a procedure that causes this error.

>procedure changecolor;
>begin
>edit2.text := edit1.text;     <= the edit2 is an undeclared identifier.
>end;

>procedure TForm1.Button1Click(Sender: TObject);
>begin
>changecolor;
>end;

you'll probably kick yoursself but if the ChangeColour procedure isn't
one of TForms Modifier\Selector methods then it isn't part fot he TForm1
class and hence cannot access the forms attrributes.  What you could do
is:

  Make it a method of the form
or
  Access it via Form1.Edit1.Text ...

HTH
--
Nicholas Robinson

Re:HelpMe!


Quote
Jason Fazackerley wrote:

> Please help,

> I am trying to overcome the most basic of problems, yet to no avail!!! :(

> If i design a procedure or function within a forms unit, whenever i reference
> certain objects within that form I get an "Undeclared Identifier" compile
> error.

> below is a procedure that causes this error.

> procedure changecolor;
> begin
> edit2.text := edit1.text;     <= the edit2 is an undeclared identifier.
> end;

> procedure TForm1.Button1Click(Sender: TObject);
> begin
> changecolor;
> end;

> surely i should be able to do this, but i can not figure out the error, please
> please please help

> hope i have groveled enuf for assistance.Your procedure is declared outside the form-object.  All the

controls on the form are declared in the protected section and
therefore only available inside the object.
The solution is to declare the change color procedure inside
your form in the private, public or published sections:

TForm1=Tform
   .
   .
   .
private
procedure changecolor;

   .
   .
end;{TForm1}

In the implementation part you write:

procedure TForm1.changecolor;
begin
        edit2.text := edit1.text;  
end;

Hope this helps

Atle Hammer

Re:HelpMe!


In <4pt5rp$...@sirius.plain.co.nz> faz...@chch.planet.org.nz (Jason

Quote
Fazackerley) writes:

>Please help,

>I am trying to overcome the most basic of problems, yet to no avail!!!
:(

>If i design a procedure or function within a forms unit, whenever i
reference
>certain objects within that form I get an "Undeclared Identifier"
compile
>error.

>below is a procedure that causes this error.

>procedure changecolor;
>begin
>edit2.text := edit1.text;     <= the edit2 is an undeclared
identifier.
>end;

>procedure TForm1.Button1Click(Sender: TObject);
>begin
>changecolor;
>end;

>surely i should be able to do this, but i can not figure out the
error, please
>please please help

>hope i have groveled enuf for assistance.

It sounds like you dont have an edit2 box on your form just put it
there and it becomes a declared identifier.
Ben

Re:HelpMe!


On 15 Jun 1996 02:06:49 GMT, faz...@chch.planet.org.nz (Jason

Quote
Fazackerley) wrote:
>Please help,

>I am trying to overcome the most basic of problems, yet to no avail!!! :(

>If i design a procedure or function within a forms unit, whenever i reference
>certain objects within that form I get an "Undeclared Identifier" compile
>error.

>below is a procedure that causes this error.

>procedure changecolor;
>begin
>edit2.text := edit1.text;     <= the edit2 is an undeclared identifier.
>end;

>procedure TForm1.Button1Click(Sender: TObject);
>begin
>changecolor;
>end;

>surely i should be able to do this, but i can not figure out the error, please
>please please help

>hope i have groveled enuf for assistance.

Without the point of declaration it is difficult to ascertain exactly
what is going on.

I will make the assumption that you are declaring the function outside
of the OBJECT scope.

That is, you are not declaring the function as an encapsulated method
of the form itself.

If this is the case, you will need to fully qualify the name of the
buttons in order to reference their properties or methods.

Regards

Lawrence Walters
Senior Systems Engineer
Borland International (Australia) Pty Ltd

Regards

Lawrence Walters
Senior Systems Engineer
Borland International Australia Pty Ltd

Re:HelpMe!


On 15 Jun 1996 02:06:49 GMT, faz...@chch.planet.org.nz (Jason

Quote
Fazackerley) wrote:
>Please help,

>I am trying to overcome the most basic of problems, yet to no avail!!! :(

>If i design a procedure or function within a forms unit, whenever i reference
>certain objects within that form I get an "Undeclared Identifier" compile
>error.

>below is a procedure that causes this error.

>procedure changecolor;
>begin
>edit2.text := edit1.text;     <= the edit2 is an undeclared identifier.
>end;

>procedure TForm1.Button1Click(Sender: TObject);
>begin
>changecolor;
>end;

>surely i should be able to do this, but i can not figure out the error, please
>please please help

>hope i have groveled enuf for assistance.

Regards

Lawrence Walters
Senior Systems Engineer
Borland International Australia Pty Ltd

Other Threads