Get value of Tdblookupcombobox lazarus / 16-Databases ---------------------------------------------------------------------- BezNalogov · 2009-08-06 18:35 I have been able to install the rx/dblookupcombobox without any problem. Also been able to use it in my program without a problem. I only don't get one thing and I can't find an answer on internet, it seems there is no manual for this component. What I want is quite simple: How can I get the value of the datafield that was set after somebody selected something? And how can I force a certain value of the datafield into the box? Fe with a normal dbedit I can get the value entered via dbedit.text, also I can force a value with dbedit.text :=. How to accomplish this with the dblookupcombobox is a big riddle to me. I hope somebody can tell me how to do this. Thanks in advance! ---------------------------------------------------------------------- BezNalogov · 2009-08-13 14:03 Just to make things clear: I am talking about the dblookupcombobox in rx_new ---------------------------------------------------------------------- davesimplewear · 2009-08-15 00:00 Hi, The rxDbLookup component doesn't expose the text property, the only other property that I have seen that is anything like it is the caption property, but I haven't been able to use it the same as the Text property, but it may work with what you are trying to do. ---------------------------------------------------------------------- oraitecamonyes · 2009-08-18 14:57 excuse me, in the new TDBLookupComboBox (from Lazarus 0.9.27 21240) is it possible to get the value of the KeyField correspondent to the value that is selected in the TDBLookupComboBox? ---------------------------------------------------------------------- DougNettleton · 2009-08-19 01:05 Maybe, I'm missing something here.  I posted a somewhat long-winded reply to the thread "parameters not working" - with a silly example.  The DataField of whatever Datasource you point the DBLookupComboBox to "changes" to the KeyField of whichever item is selected.  You can see the change if the Datafield is displayed in a DBGrid, or is connected to a DBEdit component or using something like ... SQLQuery2.FieldByName('COUNTRY').Value where the 'COUNTRY' is the DataField the DBLookupComboBox is connected to. Good Luck, Doug P.S. I really happy to see the "new" DBLookupComboBox working so well. ---------------------------------------------------------------------- BezNalogov · 2009-08-22 10:11 Reading the value of the dblookupcombobox in rxnew works fine via the dataset indeed. Setting the value of the keyfield  via the dataset works. I mean with works that the value is actually set. But the problem still is that the wrong thing is displayed. Let me tell what I am trying to do: In the OnEnter event of the dblookupcombobox I store the current value of the Dataset in a variable called ostatus. Let's say for this example ostatus = 10, which is the status called 'EDIT' In the OnChange event of the dblookupcombobox I do a check to see if all fields needed for that particular status are actually filled in properly, if not the change has to be undone. It's the part to undo the change where I am having problems. So if one changes to the status 12 (ACTIVE), but forgot to fill in the contact's birthdate an error will be displayed and the old status (in this example 10 - EDIT) has to be set again. I do this to undo the change of the dblookupcombobox:   DsContacts.DataSet.FieldByName('status_id').AsInteger := ostatus;   DsContacts.DataSet.UpdateRecord;   FldStatusID.Refresh; // Refresh the dblookupcombobox so the old status will be displayed again However, in the dataset the value is put back to the old value, but the vblookupcombobox will, in this example, still show 'ACTIVE', while in the dataset the value is 10, which represents the 'EDIT' status. I added the refresh, but that also doesn't help much. I hope I made a bit clear what my problem is here. ---------------------------------------------------------------------- DougNettleton · 2009-08-23 01:09 Hi Again: I don't know if I can help you but consider the following.  In most gui applications you don't want to restrict the way in which your user uses the application, so I would recommend that you only do field level editing as the user leaves a field he / she has just changed and do "multi-field" consistency checking - across fields - in a "BeforePost" event. In the example I wrote about in "parameters not working" ... Say you wanted to restrict changing the "country" of Alberta to anything other than Canada.  Either of the following: procedure TForm1.ZQuery1BeforePost(DataSet: TDataSet); begin   if ZQuery1.FieldByName('CODE').Value = 'AB' then     ZQuery1.FieldByName('COUNTRY').Value := 'CAN'; end; or procedure TForm1.ZQuery1BeforePost(DataSet: TDataSet); begin   if ZQuery1.FieldByName('CODE').Value = 'AB' then     ZQuery1.Cancel; end; work fine You can also try something like ... procedure TForm1.DBLookupComboBox1Exit(Sender: TObject); begin   if ZQuery1.FieldByName('CODE').Value = 'AB' then     begin       ZQuery1.FieldByName('COUNTRY').Value := 'CAN';       DBLookupComboBox1.Refresh;     end; end; which will also do what you're describing.  I don't think you should expect to do what your trying while in the OnChange event of DBLookupComboBox. Good Luck, Doug P.S. You don't even need ...     DBLookupComboBox1.Refresh;  in the last case.