Recent

Author Topic: [SOLVED] Index selection via a TComboBox  (Read 2101 times)

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 279
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
[SOLVED] Index selection via a TComboBox
« on: December 15, 2023, 03:38:22 pm »
I've seen this design in other apps such as MyDBF Studio.  This is the way I designed a TComboBox for selecting/changing the index for a particular table. This app is designed with dBase v7, see below the Case statement allowing the user to select a sort/index stored in the Items/TStrings. Compiles but when I run it, it's not selecting what I selected or rather the Case statement I wrote is not right. When I test, it's not executing the Case selections, it's dropping into the ELSE. Should I be using DBListBox or combo instead?

procedure TFrmCntksMain.CmboBxIndexBySelect(Sender: TObject);
begin
  Case CmboBxIndexBy.SelText of
    'Contact ID#':DbfContacts.IndexName:= 'CONTACTID';
    'Name(L,F,M)':DbfContacts.IndexName:= 'CNTKNAME';
    'Category':DbfContacts.IndexName:= 'CATEGORY';
    'State/Province':DbfContacts.IndexName:= 'STATPROV';
    'Country':DbfContacts.IndexName:= 'CNTRYCODE';
  else
    WriteLn('Index value not selected...');
  end;
  DbfContacts.Refresh;
end;
« Last Edit: December 15, 2023, 08:14:40 pm by 1HuntnMan »

wp

  • Hero Member
  • *****
  • Posts: 12525
Re: Index selection via a TComboBox
« Reply #1 on: December 15, 2023, 04:06:56 pm »
Combobox.SelText? This is the text currently highlighted in the combobox's edit field in the csDropDown style. Be aware that items may be selected in the combobox, but necessarily highlighted! Or what if the combobox is switched to csDropDownList style?

You probably mean the Combobox.Text which behaves more in the way you are expecting.

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 279
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Index selection via a TComboBox
« Reply #2 on: December 15, 2023, 06:15:55 pm »
Okay WP, thanks.  I'll rework this a bit from your suggestion after I mop the kitchen! My better half is a slave driver! LoL

1HuntnMan

  • Sr. Member
  • ****
  • Posts: 279
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: Index selection via a TComboBox
« Reply #3 on: December 15, 2023, 08:14:08 pm »
Ok WP,
  That works perfectly...

cdbc

  • Hero Member
  • *****
  • Posts: 1784
    • http://www.cdbc.dk
Re: Index selection via a TComboBox
« Reply #4 on: December 15, 2023, 08:14:41 pm »
Hi
Have you considered "TComboBox.ItemIndex"?!?
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

 

TinyPortal © 2005-2018