TDBCkeckBox lazarus / 61-Beginners ---------------------------------------------------------------------- vks · 2015-03-03 11:02 Hello, I need to generate checkboxes in delphi based on the number of data in database. and the caption has to to given to checkbox as customized by us from a database field. It works if there is one value which is being retrieved. suppose its a table 'crncy' with 'country' and 'currency_of_country' as columns, and a SQL query like: select country from currency where currency_of_country='yen';  it retrieves Japan from database(i have stored it in database in prior). I have code to display it to a TDBCheckBox component: procedure Thome_trainee.btn_listClick(Sender: TObject); var   c : string; begin   SQLiteLibraryName:='sqlite3.dll';   SQLite3Connection1.DatabaseName := 'testdbase.db';   SQLite3Connection1.Transaction := SQLTransaction1;   SQLTransaction1.DataBase := SQLite3Connection1;   SQLite3Connection1.Connected:=true;   SQLTransaction1.Database:=SQLite3Connection1;   SQLQuery1.Database:=SQLite3Connection1;   SQLQuery1.SQL.text:='Select country FROM crncy';   SQLQuery1.open;  DataSource1.DataSet:=SQLQuery1;  c:= SQLQuery1.fieldbyname('country').AsString;  DBCheckBox1.DataSource:=DataSource1;  DBCheckBox1.Caption:=c; end; Problem is: when i need to display array of string to different checkboxes as its caption, which is being generated dynamically, (I know how to dynamically generate checkboxes but not its caption)  what do you suggest me to do? ---------------------------------------------------------------------- flamer0n · 2015-03-03 11:25 So you want to generate controls based on table data not on table structure right? ---------------------------------------------------------------------- vks · 2015-03-03 12:05 Ya exactly. What datatype is required to store the result of the SQLQuery? I mean the resultset. ---------------------------------------------------------------------- flamer0n · 2015-03-03 12:19 tdataset, but this question doesn't seem related to the previous one or maybe I misunderstood. I thought you wanted to generate controls based on the field.Value , I imagined some csv string content in a field and you trying to split to stringArray and generate controls looping through that assigning string values to captions etc.. nevermind ---------------------------------------------------------------------- vks · 2015-03-03 13:00 That was an extended question about resultset. I need to generate checkboxes with its label as in database. if database table 'crncy' is like below: c_no(PK)   |   country     |   currency --------------------------------------- 1                |   India          |   Rupee 2                |   US             |   USD 3                |   Japan         |   Yen            when i give:    select country from crncy; 3 checkboxes must be generated with its label  --- India,US,Yen respectively. to store the result of the query, do we have any data type like 'string array', so that i can then assign values to the checkboxes within a 'for loop' after this query execution?? ---------------------------------------------------------------------- vks · 2015-03-03 13:02 oh ok.. tdataset will store the query result? thanks a lot..    will come back to you after trying this.. or if you have better solutions, please post.. ---------------------------------------------------------------------- flamer0n · 2015-03-03 13:07 I think you want to access the result returned from the sqlquery right? it's in the query's dataset.  read data from the query like this Code: [Select]query.Open; while not query.Eof do begin  {Generate your checkboxes and assign captions yourCheckBox.Caption := query.FieldByName('India').AsString}  query.Next; end; ---------------------------------------------------------------------- vks · 2015-03-04 06:48 Hello.. I tried your code..its working super fine.. thanq so much.. here is what i have written: Code: [Select]N:=DataSource1.DataSet.RecordCount;    for I:=1 to N do    begin    DBCheckBox:=TDBCheckBox.Create(Self);    DBCheckBox.DataSource:=DataSource1;    DBCheckBox.Visible:=False;    CheckBox:=TCheckBox.Create (Self);    CheckBox.Parent := ts_enrol;    CheckBox.Caption := SQLQuery1.FieldByName('Country').AsString;    CheckBox.Top := Top;    CheckBox.Width:=400;    CheckBox.Left := 86 + I*86;    SQLQuery1.Next;    end ---------------------------------------------------------------------- vks · 2015-03-04 07:29 The generated checkboxes appear one after the other..(horizontally) I need vertical arrangement. Which property to set? ---------------------------------------------------------------------- howardpc · 2015-03-04 09:04 Instead of giving each checkbox a fixed Top, and varying its Left, give each checkbox a fixed Left, and vary its Top property suitably. ---------------------------------------------------------------------- vks · 2015-03-04 09:50 @flamerOn @howardpc.. thank you so much :-) ^_^