Recent

Author Topic: [Solved] TDBLookupComboBox selected value  (Read 14958 times)

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
[Solved] TDBLookupComboBox selected value
« on: March 04, 2018, 06:29:41 pm »
I have a DBLookupComboBox which i uses to select things.
When i use the OnChange-Event handler. I always get the previous selection.


How can i get the current selection?
Code: Pascal  [Select][+][-]
  1.  DBLCB.KeyValue
Does not work.


This is the complete code i use:
Code: Pascal  [Select][+][-]
  1. procedure TForm_WedstrijdInformatie.CB_TeamAChange(Sender: TObject);
  2. var pi,ta: integer;
  3. begin
  4.   pi := MLookup('Team_Plaats_ID','tbl_Teams','Team_ID='+IntToStr(CB_TeamA.KeyValue));
  5.   TQ_Wedstrijd.FieldByName('Wed_Plaats').AsInteger := pi;
  6. end;     // CB_TeamAChange


P.S. MLookUp is my variant of the Delphi DLookUp
« Last Edit: March 07, 2018, 10:04:39 pm by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: TDBLookupComboBox selected value
« Reply #1 on: March 04, 2018, 06:31:54 pm »
There were a lot of changes with the db comboboxes recently. Please try Laz 1.8.2 (or trunk).

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TDBLookupComboBox selected value
« Reply #2 on: March 04, 2018, 06:33:50 pm »
i am using 1.8.2
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: TDBLookupComboBox selected value
« Reply #3 on: March 04, 2018, 06:49:24 pm »
I thought I saw 1.8.0 in your signature...

Anyway. Are you using the DBLookupCombobox correctly? It has two Datasources, the "normal" DataSource attached to the dataset that you want to change, and the "ListSource" from which you get the lookup values, as well as fields DataField (belonging to DataSource), KeyField and ListField (belonging to ListSource). ListField will be displayed, and the DataField and Keyfield values must match.

From your code snippets I guess must make these assignments within TDBLookupCombobox
- DataSource --> TQ_Wedstrijd
-  DataField --> Wed_Plaats
- ListSource --> tbl_Teams
- KeyField --> Team_Plaats_ID
- ListField --> (I don't know your fields. It is the field in tbl_Teams which you want to display in the combobox.

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TDBLookupComboBox selected value
« Reply #4 on: March 04, 2018, 08:49:41 pm »
DataSource = DS_Wedstrijd
DataField = Wed_TeamA
ListSource = DS_Teams
KeyField = Team_ID
ListField = Team_Naam


What i do is depending on the team i select. I then determine the place of the ice rink where they play their home games (with the function MLookUp).
In previous version of Lazarus this always worked as i have done in the example i posted.


What has changed then in Lazarus 1.8.2.
« Last Edit: March 05, 2018, 02:13:42 am by madref »
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TDBLookupComboBox selected value
« Reply #5 on: March 05, 2018, 02:14:37 am »
All set with this code
Code: Pascal  [Select][+][-]
  1.   CB_TeamA.ListSource := DS_Teams;
  2.   CB_TeamA.ListField := 'Team_Naam';
  3.   CB_TeamA.KeyField := 'Team_ID';
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TDBLookupComboBox selected value
« Reply #6 on: March 05, 2018, 11:43:20 pm »
What has changed in de DBLookupCombobox in 1.8.2. to 1.8.0?
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TDBLookupComboBox selected value
« Reply #7 on: March 06, 2018, 12:16:25 am »
I switched back to 1.8.0 and everything works fine again
I think theres a big in it.

You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: TDBLookupComboBox selected value
« Reply #8 on: March 06, 2018, 12:21:46 am »
You should try to separate the issue into a minimal project which you upload here.

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TDBLookupComboBox selected value
« Reply #9 on: March 06, 2018, 12:37:01 am »
Here is an older version but with the same problem in 1.8.0 (working correctly) vs 1.8.2 (working weird).
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: TDBLookupComboBox selected value
« Reply #10 on: March 06, 2018, 12:46:57 am »
I'm on Windows, had to remove one of the units, and now the program does not even start. Giving up here. I don't have the time to debug a foreign program, sorry.

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TDBLookupComboBox selected value
« Reply #11 on: March 06, 2018, 07:40:20 am »
I really don't know why it doesn't work.
But i have removed some redundant code and units.


Hope it works now.
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: TDBLookupComboBox selected value
« Reply #12 on: March 06, 2018, 09:26:58 am »
No chance, still the same: Crashing the debugger, and when run without the debugger I get "A reference evaluation was sent back by server" (whatever that means...). Further reduce the project. Remove unnecessary sqlqueries, try to avoid the two-stage layout of main form -> second form, put everything needed into the same form. Yes, that takes some time, but I will spend my time on that, too.

rvk

  • Hero Member
  • *****
  • Posts: 6944
Re: TDBLookupComboBox selected value
« Reply #13 on: March 06, 2018, 10:07:07 am »
I got it working here om Windows after fiddling with some options.

So what is the problem? If I put a Showmessage() in CB_DivisieChange() it gives me the value I choose.

Code: Pascal  [Select][+][-]
  1. procedure TForm_Wedstrijden_Overzicht.CB_DivisieChange(Sender: TObject);
  2. begin
  3.   Showmessage(CB_Divisie.KeyValue); // <---- works fine
  4.   WedstrijdenSelectie;
  5. end;     // CB_DivisieChange

madref

  • Hero Member
  • *****
  • Posts: 1116
  • ..... A day not Laughed is a day wasted !!
    • Nursing With Humour
Re: TDBLookupComboBox selected value
« Reply #14 on: March 06, 2018, 12:40:13 pm »
When i run this code in a Mac with Lazarus 1.8.2 i get the old value of the combobox when i change it.
In 1.8.0 i get the chosen value.


That is the problem i have. I posted this so anyone else can try and get the same result as i have. Then we know that it is a bug

You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Main Platform:
--------------
Mac OS X Tahoe 26.2
Lazarus 4.99 (rev main_4_99-3149-g7867f6275c) FPC 3.3.1 x86_64-darwin-cocoa

Windows 10 Pro
Lazarus 3.99 (rev cbfd80ce39)

 

TinyPortal © 2005-2018