Recent

Author Topic: (solved) TDataSet.Locate field value from a combobox  (Read 2538 times)

bill0287

  • Full Member
  • ***
  • Posts: 146
(solved) TDataSet.Locate field value from a combobox
« 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);


« Last Edit: May 04, 2015, 07:22:30 pm by bill0287 »

BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: TDataSet.Locate field value from a combobox
« Reply #1 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?
Lazarus Ver 1.4.0 FPC Ver 2.6.4 SVN 48774 32-bit
Windows 7 U 64-bit

bill0287

  • Full Member
  • ***
  • Posts: 146
Re: TDataSet.Locate field value from a combobox
« Reply #2 on: May 04, 2015, 05:59:47 pm »
not working for me.

BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: TDataSet.Locate field value from a combobox
« Reply #3 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
Lazarus Ver 1.4.0 FPC Ver 2.6.4 SVN 48774 32-bit
Windows 7 U 64-bit

rvk

  • Hero Member
  • *****
  • Posts: 4386
Re: TDataSet.Locate field value from a combobox
« Reply #4 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).


BitBangerUSA

  • Full Member
  • ***
  • Posts: 183
Re: TDataSet.Locate field value from a combobox
« Reply #5 on: May 04, 2015, 06:53:24 pm »
silly me. rvk is of course right.

sorry bill0287.
Lazarus Ver 1.4.0 FPC Ver 2.6.4 SVN 48774 32-bit
Windows 7 U 64-bit

bill0287

  • Full Member
  • ***
  • Posts: 146
Re: TDataSet.Locate field value from a combobox
« Reply #6 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