Recent

Author Topic: DBLookupCombobox Integer KEYFIELD returns Variant error  (Read 377 times)

ERICGUIL

  • New member
  • *
  • Posts: 6
DBLookupCombobox Integer KEYFIELD returns Variant error
« on: April 08, 2020, 06:22:42 pm »
Dear all,
I use Lazarus v 2.0.6 and a mysql 8.0 database. I have created a new form with a DBLookupCombobox. The table loaded  is having fields witht he tSQLQuery:
ID: integer with primary key,
NOM: varchar (20)
PRENOM : varchar (20)
Phone:: varchar (20)
Mail : varchar (20)
In the dbLookupCombobox, I have declared the datafield is NOM, the Data source : dbDataSource (as created in the form), Keyfield : NUM, Listfield : NOM and ListSource : dbDataSource.
With this config I always have an error Invalid Variant Type Cast just when I launch with the F9 key the execution. If I change the field NUM to mMAIL (for example), The result is OK.
It seems that when the returned field is an INteger, I have an error , with a string field there is no error.
Can you, please help me.
Nota : This table is visible with no error into the dbGrid , and I can use the NUM field for locate records.

Thanks in advance.
« Last Edit: April 08, 2020, 07:05:27 pm by ERICGUIL »

eljo

  • Sr. Member
  • ****
  • Posts: 354
Re: DBLookupCombobox Integer KEYFIELD returns Variant error
« Reply #1 on: April 09, 2020, 03:26:04 am »
probable cause of the problem : nill values in the num field in one record. At least it smells like it from a quick assesment.

GAN

  • Sr. Member
  • ****
  • Posts: 285
Re: DBLookupCombobox Integer KEYFIELD returns Variant error
« Reply #2 on: April 09, 2020, 05:22:09 am »
What kind of field is NUM?
Lazarus 1.8.4 FPC 3.0.4 Linux Mint Mate 17.2 x86_64 GTK-2
Zeos 7.1.3 - Sqlite 3.8.2

Foro Lazarus en español http://forum.lazarus.freepascal.org/index.php/board,73.0.html

ERICGUIL

  • New member
  • *
  • Posts: 6
Re: DBLookupCombobox Integer KEYFIELD returns Variant error
« Reply #3 on: April 09, 2020, 08:51:13 am »
I have created a new table with only 5 lines as shown before. The ID field is auto incremented so it's not possible to have a null field. What I would like to know is : Is it possible to return as KeyField an integer ? If it's not possible is it possible to cast an integer value to a string into the Lazarus interface ?
Many thanks in advance
PS: sorry for my poor english.

ERICGUIL

  • New member
  • *
  • Posts: 6
Sorry it's an error . The field I called NUM is ID.
Whith my trials, the field ID is integer, primary key nd auto incremented. The returned keyfield value with ID sends a variant error and if I chage the keyfield to a varchar one , the result is correct.
I have tried to debug the program. Pressing F8 key in the ID, the program goes to the customform.inc and generates the variant error (see attached Word document.
As I said before, if the keyfield is Varchar all is OK, isf the keyfield is Integer i have this variant error.
« Last Edit: April 09, 2020, 09:57:51 am by ERICGUIL »

GAN

  • Sr. Member
  • ****
  • Posts: 285
Re: DBLookupCombobox Integer KEYFIELD returns Variant error
« Reply #5 on: April 09, 2020, 11:02:17 pm »
In Object Inspector, DBlookUpComboBox:
DataSource and ListSource must have the same Data Source.
Also DatField and KeyField must be the same field and this field have to be unique, ID it's OK.
Then in ListField choice the field to be displayed in the combo.

I chequed with integer and string (VARCHAR (40)) and works fine.
If you need I can post the example here, but I use ZeosLib and SQLite.
Lazarus 1.8.4 FPC 3.0.4 Linux Mint Mate 17.2 x86_64 GTK-2
Zeos 7.1.3 - Sqlite 3.8.2

Foro Lazarus en español http://forum.lazarus.freepascal.org/index.php/board,73.0.html

ERICGUIL

  • New member
  • *
  • Posts: 6
Re: DBLookupCombobox Integer KEYFIELD returns Variant error
« Reply #6 on: April 10, 2020, 08:55:06 am »
OK, I have verified. there was a problem with datasource, Field was not unique. I have corrected and all is fine now.
MANY THANKS.


 

TinyPortal © 2005-2018