#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2002
    Posts
    86
    Rep Power
    13

    Form can't see components without full path...


    Probably a stupid question but I'm stumped...

    Why on all my other forms I can...

    Code:
    Procedure changeLabelname;
    begin
        label1.caption := 'New Caption';
    end;
    But on a new form I've just added I have to declare the full path i.e.

    Code:
    Procedure changeLabelName;
    begin
         form1.label1.caption := 'New Caption';
    end;
    Without the "form1" it gives an undeclared identifier error? I'm sure this is simple but I'm stumped...
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    350
    Rep Power
    7
    Note the difference in your procedure header:

    Yours:
    Procedure changeLabelName;

    As part of your Form Object (assuming form is called Form1)

    Procedure TForm1.changeLabelName;

    As declared, ChangeLabelName has no reference to your form, it is in essence a global procedure, not a method of your form. Caption is a property of TForm, which your form is derived from.

    So, if you are adding ChangeLabelName as a procedure to your form, you need to add it to your form's declaration (presumably in the private section - unless you want to be able to call it from another form)
    Code:
    TForm1 = class(TForm)
    ...
    private
       procedure ChangeLabelName;
       ...
    end;
    After declaring it in the Form's object, you can use the keyboard shortcut Ctrl-Shift-C, and it will add the method's stub into your code.
    Last edited by majlumbo; July 25th, 2012 at 12:44 PM.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2012
    Posts
    151
    Rep Power
    3
    Originally Posted by dlumley
    Probably a stupid question but I'm stumped...

    Why on all my other forms I can...

    Code:
    Procedure changeLabelname;
    begin
        label1.caption := 'New Caption';
    end;
    But on a new form I've just added I have to declare the full path i.e.

    Code:
    Procedure changeLabelName;
    begin
         form1.label1.caption := 'New Caption';
    end;
    Without the "form1" it gives an undeclared identifier error? I'm sure this is simple but I'm stumped...
    I believe the first ChangeLabelName procedure is a method of class TForm1. It's accurate declaration should be:

    Code:
    procedure TForm1.ChangeLabelName;
    The second one might be an "independent"/"ordinary" procedure or a method of another class.

IMN logo majestic logo threadwatch logo seochat tools logo