Lazarus

Programming => Databases => Topic started by: Oscar on June 13, 2006, 10:00:24 pm

Title: DBLookupComboBox in Lazarus
Post by: Oscar on June 13, 2006, 10:00:24 pm
A Few homebrewers in The Netherlans are trying to write a Homebrewing program with the TDBF as Database system. But to make some essential features we need a DBLookupCombobox so we can transfer Data from one table to another.

This is nog yet supported bij Lazarus or is there another way...??  :roll:

Greetins Oscar
Title: RE: DBLookupComboBox in Lazarus
Post by: matthijs on June 14, 2006, 07:56:32 am
Of course: Zelf schrijven. :)
What you could do is use a LookupComboBox and populated this with the values of the field you want displayed. At the same time maintain a list of the indexfield of the lookuptable. When the users picks a value from your combobox, find the corresponding indexfield in the other list.

It works both ways. When a record is displayed, search in your list for the value to show in the combobox and set its itemindex accordingly.

This will give you an idea of the direction you could take, I may be able to give you an example tonight (dutch time :) ) or else tomorrow. (Ik heb helaas geen Lazarus op mijn werk. :( )
Title: DBLookupComboBox in Lazarus
Post by: Oscar on June 14, 2006, 07:31:52 pm
Quote
Of course: Zelf schrijven. Smile


I'm not that good in programming. But does sombody know is this element is somewhere on the project roadmap ..? So that i can expect is in future comming versions..? Ik do not see it on the website project roadmap...

Greetings Oscar
Title: DBLookupComboBox in Lazarus
Post by: matthijs on June 15, 2006, 05:10:08 pm
To fill the combobox try the following:
Code: [Select]

  myDataSet.Open;
  while not myDataSet.Eof do begin
    AString := myDataSet.Fields[x].AsString;  // The value you want to display
    AInteger := myDataSet.Fields[0].AsInteger; // This should be your primary key
    ComboBox1.AddItem(AString, Object(AInteger));
    myDataSet.Next;
  end;

When the user selects an item you can add the desired value to the table like:
Code: [Select]

  myDataSet2.Fields[2].Value := Integer(ComboBox1.Items.Objects[ComboBox1.ItemIndex]);

where myDataSet2.Fields[2] is the field holding the foreign key.
TinyPortal © 2005-2018