Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

putting db text into button captions

Status
Not open for further replies.

mdomeyko

Programmer
Sep 26, 2006
7
0
0
I have a form with 190 buttons and have to use only a group about 34. I have a DB with the text to be used.

Is there any way to put db text into each selected button caption dynamicly with out doing it one-by-one?
I'm a delphi rockie, so please help!

I've tried doing the following but get invalid access error...

var ctxt : string; i : integer;

while NOT q_main_buts.EOF do begin
for i := 74 to 100 do begin
ctxt := 'XiButton' + trim(inttostr(i)); // dynamic assign
TXiButton(ctxt).caption := q_main_butsCategory.asstring;
end;
q_main_buts.next;
end;
 
ctxt" is a string variable, you can't cast it to an object.

The form where the buttons are have a method named FindChildControl; it is a function receiving the control name and returning a pointer to it.

Try something like this code:

Code:
var
  ...
  Btn : TControl;

     ...
     Btn := FindChildControl(ctxt);
     if Btn <> nil then Btn.Caption := name_from_the_db;
     ...

On a side note, you don't need Trim when using IntToStr:
ctxt := 'XiButton' + trim(inttostr(i)) is the same as ctxt := 'XiButton' + IntToStr(i).

buho (A).





 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top