Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 07-26-2012, 03:36 AM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default Syntax for substuition

I can't get this correct and I'm not sure where to look.

Code:
   for i:=1 to 6 do begin
      'sCat'+IntToStr(i):=tDataSet(FindComponent('dm.tblRaceBIKECAT'+IntToStr(i)).asString;
   end;
Reply With Quote
  #2  
Old 07-26-2012, 06:52 AM
Donovan Donovan is offline
Senior Member
 
Join Date: Jan 2011
Posts: 150
Send a message via Skype™ to Donovan
Default

without compiling I think your problem is here

tDataSet(dm.FindComponent('tblRaceBIKECAT'+IntToSt r(i)).asString;

But also, you are assigning it to what exactly?

'sCat'+IntToStr(i) is not a VAR so not sure how this is suppose to work.

Tell us what you are trying to do rather that posting snippits of code :-)

Regards

Donovan
Reply With Quote
  #3  
Old 07-26-2012, 07:44 AM
Norrit Norrit is offline
Moderator
 
Join Date: Aug 2001
Location: Landgraaf
Posts: 6,707
Default

Code:
FindComponent('dm.tblRaceBIKECAT'+IntToStr(i))
This will ALWAYS return nil, you cannot find a component on another form (guessing this is a datamodule) this way, you must use something like
Code:
dm.FindComponent('tblRaceBIKECAT'+IntToStr(i))
Ow, and read Donovan, he explained the other problem aswell

Last edited by Norrit; 07-26-2012 at 07:46 AM. Reason: Read Donovan, he explained the other problem aswell
Reply With Quote
  #4  
Old 07-26-2012, 09:13 AM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

You are correct, I'm not sure what I was doing. I had a brain freeze, my app is very complex with a lot of linking between many tables and my concentration was diverted.

All I doing is reading values into variables.

Code:
procedure TfRaceManual.Button3Click(Sender: TObject);
var
   sCat1,sCat2,sCat3,sCat4,sCat5,sCat6:String;
   i:integer;
begin
   for i:=1 to 6 do begin
     'sCat'+IntToStr(i):=dm.tblRace.FieldByName('BIKECAT'+IntToStr(i)).asString;
   end;;
This is an alternate way which works but I would like to know how to make the above one work.

Code:
procedure TfRaceManual.Button3Click(Sender: TObject);
var
   sCat:Array[1..6] of String;
   i:integer;
begin
   for i:=1 to 6 do begin
     sCat[i]:=dm.tblRace.fieldByName('BIKECAT'+IntToStr(i)).asString;
   end;
Reply With Quote
  #5  
Old 07-26-2012, 09:51 AM
Marsheng Marsheng is offline
Senior Member
 
Join Date: Nov 2008
Posts: 205
Default

I might as well add the next bit now

I have 20 database edit boxes on the screen with values, they are dbePoints1 ... dbePoints20

I need to transfer the value in the edit box into my table RaceResults,
depending on the value of i

something like

dm.tblRaceResultsPOINTS.AsString:=tdbEdit(FindComp onent('dbePoints'+IntToStr(i))).text;
Reply With Quote
Reply

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:34 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.