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 October 31st, 2012, 09:56 AM
DLPB DLPB is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 19 DLPB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 58 m 49 sec
Reputation Power: 0
FindComponent problem

Solved. There was nothing wrong with the code.

I have 4 edit boxes named:

Player1_Edit
Player2_Edit
Player3_Edit
Player4_Edit

I am doing this the short way and using FindComponent (I have other edit boxes which will also need it).

If box is empty on form show, the box should be filled with corrosponding text "Playerx" where x is a number. The first part of this code works fine. It finds the boxes. But it is NOT updating them. Why?


Code:
for i:=1 to 4 do
  if TEdit(FindComponent('Player'+inttostr(i)+'_Edit')).text='' then
  TEdit(FindComponent('Player'+inttostr(i)+'_Edit')).text:='Player'+inttostr(i);

Reply With Quote
  #2  
Old October 31st, 2012, 11:13 AM
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 4 sec
Reputation Power: 5
Code:
for i:=1 to 4 do
  if TEdit(FindComponent('Player'+inttostr(i)+'_Edit')).text='' then
  TEdit(FindComponent('Player'+inttostr(i)+'_Edit')).text:='Player'+inttostr(i);


I couldn't find anything obviously wrong with the code so I tested it, and works as expected. The only other possibility is that the edit controls are not empty making the if statement fail, even though it finds the control.

Reply With Quote
  #3  
Old October 31st, 2012, 11:51 AM
DLPB DLPB is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 19 DLPB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 58 m 49 sec
Reputation Power: 0
I've worked it out. Ugh.

For some reason I am using a TLMDedit not a Tedit. I did make this project a long time ago so... didn't see I had changed it.

The code is fine. I do wish this findcomponent thing gave an error though... it should have done given the boxes are not Tedit.

Anyway thanks!

Reply With Quote
  #4  
Old October 31st, 2012, 02:28 PM
clivew clivew is offline
Contributing User
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jan 2006
Location: Carlsbad, CA
Posts: 2,045 clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level)clivew User rank is Major (30000 - 40000 Reputation Level) 
Time spent in forums: 1 Week 6 Days 2 h 37 m
Reputation Power: 382
Quote:
I do wish this findcomponent thing gave an error though... it should have done given the boxes are not Tedit.

Not if TLMDedit is a descendant of TEdit.
However, in that case one would assume it would work unless TLMDedit overrides the setText method somehow.

Clive

Reply With Quote
  #5  
Old November 1st, 2012, 11:59 AM
emailx45 emailx45 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2008
Posts: 44 emailx45 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 h 7 m 32 sec
Reputation Power: 5
Thumbs up

Read this before:

http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/Controls_TWinControl.html


http://delphi.about.com/od/vclusing/a/parent_enabled.htm

In essence, the TWinControl is the base class for all Delphi control that can accept focus. For example, TEdit is a descendant of the TWinControl, TLabel is not.

Another way for your needed:

procedure or functions
//////////////////////////////
var
xCmp:TComponent;
For I:= n1 TO nZ do
begin
xCmp:= nil; //for better control of "conditions"
xCmp:= FindComponent(format('Player%d_edit',[i]));
if (xCmp<>nil) and (xCmp is TCustomEdit) then
xCmp.Text := Format('Player%d', [i]);
end;

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreDelphi Programming > FindComponent problem

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