* * *

Author Topic: How to make record (string/int/value) data mysql into caption TLabel/TButton  (Read 1425 times)

om.ndoet

  • New member
  • *
  • Posts: 5
Hi i am Indonesian, sorry about my English first... it s bad.
I am beginner in programming..

First, i have problem to make a dinamicly TButton into form (but i have idea to solve this)
Second, i would to make a caption TButton from record data mysql (use zeos) ex. First record on scond field, scond  record on scond field... anyone can help me? To give me example code? Thanks before...

howardpc

  • Hero Member
  • *****
  • Posts: 2243
First question: unzip and try the attached project.

Second question: I'm not clear what you are asking.

om.ndoet

  • New member
  • *
  • Posts: 5
 i would to insert caption TLabel with a value data

ex.

procedure TMainForm.FormCreate(Sender: TObject);
begin
  BitBtn1.Caption:=ZQuery1.RecNo.....???? //
end;

so i want to insert caption button dynamicly from database... thanks before...

miab3

  • Jr. Member
  • **
  • Posts: 92
Code: Pascal  [Select]
  1. var j:integer;
  2.     btn:TButton;
  3. begin
  4. ZQuery1.First;
  5. for j:=1 to 10 do
  6.     begin
  7.     btn := (FindComponent('Button'+IntToStr(j)) as TButton);
  8.     btn.Caption := ZQuery1.Fields[1].AsString;
  9.     ZQuery1.Next;
  10.     end;
  11. end;
  12.  

Michal

howardpc

  • Hero Member
  • *****
  • Posts: 2243
Or if your dataset is called MyDataset with a string field called ButtonCaptions, and the dynamic button is a field FButton on your form you could add an OnAfterScroll event for the dataset like this:
Code: Pascal  [Select]
  1. procedure TForm1.MyDatasetAfterScroll(DataSet: TDataSet);
  2. begin
  3.   if Assigned(FButton) then
  4.     FButton.Caption:=MyDataset.FieldByName('ButtonCaptions').AsString;
  5. end;  

Well, your dataset will probably be dropped on a datamodule, not on the form, but you get the idea.

om.ndoet

  • New member
  • *
  • Posts: 5
Thanks all.. in fact, me use data modul to insert zeos component..
I will try later...

om.ndoet

  • New member
  • *
  • Posts: 5
First question: unzip and try the attached project.

Second question: I'm not clear what you are asking.

DynamicButton.lpr(20,1) Error: Can't open resource file "\\published\DynamicButton.res"

sorry  %)

Code: Pascal  [Select]
  1. var j:integer;
  2.     btn:TButton;
  3. begin
  4. ZQuery1.First;
  5. for j:=1 to 10 do
  6.     begin
  7.     btn := (FindComponent('Button'+IntToStr(j)) as TButton);
  8.     btn.Caption := ZQuery1.Fields[1].AsString;
  9.     ZQuery1.Next;
  10.     end;
  11. end;
  12.  

Michal

i try, but found error 'External SIGSEGV' in dm.Query1.First;
sorry  %)

jacmoe

  • Sr. Member
  • ****
  • Posts: 255
    • Jacmoe's Cyber SoapBox
Look at the code and use it in your own way in your own project  ;)
more signal - less noise

miab3

  • Jr. Member
  • **
  • Posts: 92
Probably missing:

ZQuery1.Open;

Michal

om.ndoet

  • New member
  • *
  • Posts: 5
ok... thanks all...

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus