Recent

Author Topic: DBLookupComboBox in Lazarus  (Read 9978 times)

Oscar

  • Newbie
  • Posts: 6
DBLookupComboBox in Lazarus
« 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
Take a homebrew !!
Creating software for it : http://home.planet.nl/~gerrl002/lazarus/index.htm

matthijs

  • Hero Member
  • *****
  • Posts: 537
RE: DBLookupComboBox in Lazarus
« Reply #1 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. :( )
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

Oscar

  • Newbie
  • Posts: 6
DBLookupComboBox in Lazarus
« Reply #2 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
Take a homebrew !!
Creating software for it : http://home.planet.nl/~gerrl002/lazarus/index.htm

matthijs

  • Hero Member
  • *****
  • Posts: 537
DBLookupComboBox in Lazarus
« Reply #3 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.
What's in a sig? Would my posting look less if it didnot have a sig? (Free after William S.) :)

:( Why cannot I upload my own Avatar? :(

 

TinyPortal © 2005-2018