Recent

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

ERICGUIL

  • Newbie
  • 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: 468
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: 370
Re: DBLookupCombobox Integer KEYFIELD returns Variant error
« Reply #2 on: April 09, 2020, 05:22:09 am »
What kind of field is NUM?
Lazarus 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

ERICGUIL

  • Newbie
  • 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

  • Newbie
  • 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: 370
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 2.0.8 FPC 3.0.4 Linux Mint Mate 19.3
Zeos 7̶.̶2̶.̶6̶ 7.1.3a-stable - Sqlite 3.32.3 - LazReport

ERICGUIL

  • Newbie
  • 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