Lazarus

Programming => Databases => Topic started by: ercolesptr on November 17, 2022, 04:16:25 pm

Title: Using MS Access with KADao
Post by: ercolesptr on November 17, 2022, 04:16:25 pm
I am trying to use KADao Lazarus component available from here( https://sourceforge.net/projects/ka-dao-for-lazarus/  (https://sourceforge.net/projects/ka-dao-for-lazarus/) )in order to use MS Access database with DAO. I installed the components without problem however when I try to make a project and use the components I get an error Class not registered. This error occurs when the program runs after compilation which occurs without errors. The error does not occur when I try to run the executable built but it does not seem to work or maybe I am not using it correctly. Can anyone help please?

Title: Re: Using MS Access with KADao
Post by: ercolesptr on November 17, 2022, 04:27:28 pm
I actually found that the program works well and was able to display the contents of the database in a grid, only thing is that this error occurs at when the program is executed from within lazarus IDE but not when the built exe file is run. Any idea why this is happenening?
Title: Re: Using MS Access with KADao
Post by: wp on November 17, 2022, 05:02:30 pm
I did this:
- Add a TKADaoDatabase to the form, set its Database property to one of my old Access-97 mdb files, set Connected = true --> ok.
- Add a TKADaoTable to the form, set its Database property to the KADaoDatabase instance added, property TableName lists the names of the tables found in the mdb file, select one of them, set Active = true --> ok.
- Add a TDatasource and a TDBGrid and connect them in the usual way --> DBGrid displays the data of the selected table --> fine!

BUT:
- Trying to compile the project --> Error "Module was not found", raised in TKADaoDatabase.CreateOleDBEngine_II. No idea what's missing... I'm on Win-11. Maybe it does not support DAO any more? But why does it work at designtime?
Title: Re: Using MS Access with KADao
Post by: dseligo on November 17, 2022, 06:08:44 pm
I actually found that the program works well and was able to display the contents of the database in a grid, only thing is that this error occurs at when the program is executed from within lazarus IDE but not when the built exe file is run. Any idea why this is happenening?

Maybe your Lazarus is 64-bit and you compile your program to 32-bit or vice versa and you have only 32-bit libraries (or 64-bit in other case).
Title: Re: Using MS Access with KADao
Post by: ercolesptr on November 17, 2022, 09:03:13 pm
Mine gives exception error "class not registered" when running from Lazarus IDE, but works fine otherwise and opens the database in the grid. Any idea how to register that class whichever it is?
Title: Re: Using MS Access with KADao
Post by: ercolesptr on November 17, 2022, 09:06:39 pm
No idea what's missing... I'm on Win-11. Maybe it does not support DAO any more? But why does it work at designtime?

I program with DAO on VB6 and my apps work fine on windows 11, so DAO is still supported.
Title: Re: Using MS Access with KADao
Post by: wp on November 17, 2022, 11:03:46 pm
Mine gives exception error "class not registered" when running from Lazarus IDE, but works fine otherwise and opens the database in the grid. Any idea how to register that class whichever it is?
Some more results from my experiments:

- Desparately I installed KADao in my 64-bit IDE and compiled my test application. Compilation ok, but after start there is now the "class not registered" error that you had reported. Running the application outside the IDE, however, yields a "Cannot find DAO on your system" error.
- Returning to the 32-bit IDE I verified the already reported "Module not found" error inside the IDE. However, when I run the application outside the IDE (I had not done this before) everything is ok now: no error, the DBGrid appears with the expected data...
Title: Re: Using MS Access with KADao
Post by: Zvoni on November 18, 2022, 09:25:42 am
AFAIK, there is no DAO 64-Bit
Quote
I program with DAO on VB6
DAO is 32-Bit exclusively.
If your Lazarus is 64-Bit, but you compile to 32-Bit Target.....

Bottom Line: Scrap DAO, and move on
Title: Re: Using MS Access with KADao
Post by: Thaddy on November 18, 2022, 12:26:44 pm
AFAIK, there is no DAO 64-Bit
Quote
I program with DAO on VB6
DAO is 32-Bit exclusively.
If your Lazarus is 64-Bit, but you compile to 32-Bit Target.....

Bottom Line: Scrap DAO, and move on
Nope, DAO is 32 bit and 64 bit. E.g. if a 64 bit version of Excel or Access is installed, DAO works in 64 bit too.
The limitation is likely using VB6 which is I believe restricted to 32 bit. VB6 was declared legacy in 2008.
See https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/database-object-dao for examples that work in 32 and 64 bit.. Note that 32 bit will possibly be dropped in the future.

Title: Re: Using MS Access with KADao
Post by: Zvoni on November 18, 2022, 01:29:24 pm
AFAIK, there is no DAO 64-Bit
Quote
I program with DAO on VB6
DAO is 32-Bit exclusively.
If your Lazarus is 64-Bit, but you compile to 32-Bit Target.....

Bottom Line: Scrap DAO, and move on
Nope, DAO is 32 bit and 64 bit. E.g. if a 64 bit version of Excel or Access is installed, DAO works in 64 bit too.
The limitation is likely using VB6 which is I believe restricted to 32 bit. VB6 was declared legacy in 2008.
See https://learn.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/database-object-dao for examples that work in 32 and 64 bit.. Note that 32 bit will possibly be dropped in the future.
Yes, you're right, IF you have Office 64-Bit installed.
I came from OP's comment coming from vb6, and that's definitely 32-Bit
Title: Re: Using MS Access with KADao
Post by: Thaddy on November 18, 2022, 01:48:51 pm
Yes, you're right, IF you have Office 64-Bit installed.
I came from OP's comment coming from vb6, and that's definitely 32-Bit
You have to jump through hoops to install a 32 bit office nowadays....
Title: Re: Using MS Access with KADao
Post by: Zvoni on November 18, 2022, 01:53:19 pm
Yes, you're right, IF you have Office 64-Bit installed.
I came from OP's comment coming from vb6, and that's definitely 32-Bit
You have to jump through hoops to install a 32 bit office nowadays....
since there is still Windows 10 32-Bit available, so is Office 32-Bit. (and yes, Win 11 is 64-Bit only).
If you have to jump through hoops to install Office/Anything 32-Bit on Windows 64-Bit, then you have to decide,
if it's Microsoft's Sales-Department giving good directions to their programmers (to force people to buy a new 64-Bit Office),
or if it's just bad programming on Microsoft's part.
*shrug*
Title: Re: Using MS Access with KADao
Post by: ercolesptr on November 18, 2022, 03:41:58 pm
Mine gives exception error "class not registered" when running from Lazarus IDE, but works fine otherwise and opens the database in the grid. Any idea how to register that class whichever it is?
Some more results from my experiments:

- Desparately I installed KADao in my 64-bit IDE and compiled my test application. Compilation ok, but after start there is now the "class not registered" error that you had reported. Running the application outside the IDE, however, yields a "Cannot find DAO on your system" error.
- Returning to the 32-bit IDE I verified the already reported "Module not found" error inside the IDE. However, when I run the application outside the IDE (I had not done this before) everything is ok now: no error, the DBGrid appears with the expected data...

For the class not registered error prompt looks like ticking that "ignore this exception type" checkbox is the only solution, after all it does not occur in the build binary.

With regards to the other error you are getting "Cannot find DAO on your system", I never got that, maybe because I had registered dao360.dll using regsvr32 previously in an effort to remove the "class not registered" error. To do this, do a search on your hard drive for dao360.dll and when you find it open a command prompt in admin mode and go to the path of that dll and type:

regsvr32 dao360.dll

That should remove the bug in win 64
Title: Re: Using MS Access with KADao
Post by: ercolesptr on November 22, 2022, 09:03:20 pm
This link here sheds some more light on the class not registered bug. I know this is for Delphi but I think the fix should work for Lazarus too.

http://mc-computing.com/Databases/delphi/KADao.html
Title: Re: Using MS Access with KADao
Post by: ercolesptr on November 23, 2022, 01:30:22 pm
Also for missing DAO error message it can be fixed by installing one of these:

https://www.microsoft.com/en-us/download/details.aspx?id=10910
Title: Re: Using MS Access with KADao
Post by: wp on November 23, 2022, 02:21:20 pm
How is DAO performing in comparison with ODBC? DAO has the disadvantage that it works only on Windows.
Title: Re: Using MS Access with KADao
Post by: Thaddy on November 23, 2022, 03:31:14 pm
There is not much difference in performance except DAO has - just a few - more features.
That said it is really old technology and not worth any effort in upgrading.
If it is in fpcupdeluxe please mark it as deprecated. That is, not many people understand "deprecated"...
ODBC is of course not deprecated and works X platform.
TinyPortal © 2005-2018