Delphi Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreDelphi Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 25th, 2012, 11:16 AM
dlumley dlumley is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Posts: 86 dlumley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 29 m 26 sec
Reputation Power: 12
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...

Reply With Quote
  #2  
Old July 25th, 2012, 12:37 PM
majlumbo majlumbo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2008
Posts: 255 majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level)majlumbo User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 3 Days 2 m 15 sec
Reputation Power: 5
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.

Reply With Quote
  #3  
Old July 25th, 2012, 11:24 PM
Luthfi Luthfi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 140 Luthfi User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 4 h 58 m 17 sec
Reputation Power: 2
Quote:
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > Form can't see components without full path...

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap