Topic: Combobox

Hello Dimitri

I'm making a test on my VDB about birds.

To reduce many forms I have, I'm testing 2 comboboxes populated
with 2 text files (orders and families ) through a script :

Affichage.ComboBox1.Items.LoadFromFile(Chemin + 'Ordres_Oiseaux.txt');
Affichage.ComboBox2.Items.LoadFromFile(Chemin + 'Familles_Oiseaux.txt');

That's works fine (the loadings).

But I would  Combobox.Text be filled by the user's choice from file loaded (i.e Orders).
I'm not very good with Items.Index.
Have you any ideas about the way to succeed ?
And how to save those selection through a Save button (directly or with a script) ?

Another error message : Compilation tells me "no such columns" .
So I'v declared in my main table called Oiseaux those 2 fields : Order and Family.
It occurs when I want modify a record already saved

Thanks for your help

Best regards

Jean B.

Re: Combobox

Hello,

You should load information directly in database, not in ComboBox.
Here example, how to import text file to database:

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
var
     SL: TStringList;
     i,c: integer;
     SQL: string;
begin
     SL := TStringList.Create;
     SL.LoadFromFile ('d:\1.txt');
     c := SL.Count - 1;

     for i := 0 to c do
     begin
          SQL := 'INSERT INTO main (name) VALUES ("' + SL[i] + '");';
          SQLExecute (SQL);
     end;

     SL.Free;
end;

But you can see your information in database, only after restart project.




Please, send me project with description, where you get error message "no such columns"


Thanks.

Dmitry.

Re: Combobox

HEllo

Thanks for your answer.
In fact my way loading comboboxes works fine.
What I want : to transform the value entered in combox as a string in order to save it in my main database,
Something as this :

ComboBox1.Items.Add(Query1.Fields[1].AsString); (in my case there is no Query used).
See joined file

Thanks

Re: Combobox

jean.brezhonek

I don't see your joined file )

Dmitry.

Re: Combobox

Hello

Sorry for this missing file
I've made a "tricky code" to resolve my case
(Get the value of a combox, hide this one, make visible the Edit component to get the value of the CB)
Th'at works wel but i get an error message 'List index out of bound (0) or (1)'

Jean B.

Post's attachments

Attachment icon Combo.jpg 22.87 kb, 336 downloads since 2014-08-23 

Re: Combobox

jean.brezhonek
Please, send me your project to support@drive-software.com



But, what you are trying to do is against the second normal form (2nf)
http://en.wikipedia.org/wiki/Second_normal_form

Dmitry.