Lazarus

Programming => Databases => Topic started by: bill0287 on May 04, 2015, 04:25:20 am

Title: (solved) TDataSet.Locate field value from a combobox
Post by: bill0287 on May 04, 2015, 04:25:20 am
This code works, where the field value is hard coded into the locate statement:

Code: [Select]
if not (dbData.Locate('NAME', DBLookupComboBox.Text,[loCaseInsensitive])) then
      MessageDlg('No matching record found.', mtInformation, [mbOK],0);

This code does not does work, where I am setting the field value in a combobox:

Code: [Select]
if not (dbData.Locate(DataFieldComboBox.Text, DBLookupComboBox.Text,[loCaseInsensitive])) then
      MessageDlg('No matching record found.', mtInformation, [mbOK],0);


Title: Re: TDataSet.Locate field value from a combobox
Post by: BitBangerUSA on May 04, 2015, 04:43:47 am
ah...

if not (dbData.Locate(DataFieldComboBox.Text, DBLookupComboBox.Text,[loCaseInsensitive])) then
      MessageDlg('No matching record found.', mtInformation, [mbOK],0);

should be

if not (dbData.Locate(DBComboBox.DataField, DBLookupComboBox.Text,[loCaseInsensitive])) then
      MessageDlg('No matching record found.', mtInformation, [mbOK],0);

perhaps? you get no compile error?
Title: Re: TDataSet.Locate field value from a combobox
Post by: bill0287 on May 04, 2015, 05:59:47 pm
not working for me.
Title: Re: TDataSet.Locate field value from a combobox
Post by: BitBangerUSA on May 04, 2015, 06:07:43 pm
could be this... 'The implementation in TDataset always returns False. It is up to TDataset descendents to implement this method and return an appropriate value.'

see http://www.freepascal.org/docs-html/fcl/db/tdataset.html (http://www.freepascal.org/docs-html/fcl/db/tdataset.html)
Title: Re: TDataSet.Locate field value from a combobox
Post by: rvk on May 04, 2015, 06:43:38 pm
If the first works and the second fails there must be something wrong with the value in DataFieldComboBox.Text.

Did you try a Showmessage('|'+DataFieldComboBox.Text+'|'); just before the call?
Is the result exactly |NAME| (all caps, no spaces etc).

Title: Re: TDataSet.Locate field value from a combobox
Post by: BitBangerUSA on May 04, 2015, 06:53:24 pm
silly me. rvk is of course right.

sorry bill0287.
Title: Re: TDataSet.Locate field value from a combobox
Post by: bill0287 on May 04, 2015, 07:21:50 pm
the error was in my code, the statement in the first post works.  Sorry
TinyPortal © 2005-2018