Recent

Author Topic: Problems with the standard (database) components of lazarus  (Read 1486 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 1991
    • Lazarus and Free Pascal italian community
Problems with the standard (database) components of lazarus
« on: December 02, 2019, 11:27:53 am »
Hi guys, I need help with the standard components of the lazarus databases. For years I used zeoslib but now for another project I want to use the standard components.
I am attaching an example based on a sqlite database

First problem: if when the grid with the data appears you right-click on the grid and say "Insert a new line" a new window appears that allows you to add a record.
Fill in the data and then give "save"

You will see that the program goes into error because it says that the table in the database does not contain the "category" field. This is true because it is a fklookup field added on the dataset to make the grid graphically usable. How can I save by telling him to ignore that field?

Second problem: if you compile the project by changing the custom options from

-dNoRefreshAfterInsert
-dNoRefreshAfterEdit
-dNoRefreshAfterDuplicate
-dNoRefreshAfterDelete
-dNoActualRowPosition


to

-dRefreshAfterInsert
-dRefreshAfterEdit
-dRefreshAfterDuplicate
-dRefreshAfterDelete
-dActualRowPosition

and try to insert a new record or modify an existing one you will see that the program goes into error because of the TBookMark that no longer refers to a valid data after the refresh. This is very strange because with zeos it works very well.
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 1991
    • Lazarus and Free Pascal italian community
Re: Problems with the standard (database) components of lazarus
« Reply #1 on: December 03, 2019, 08:40:42 am »
No solutions?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

madref

  • Hero Member
  • *****
  • Posts: 700
  • ..... A day not Laughed is a day not Lived !!
    • Nursing With Humour
Re: Problems with the standard (database) components of lazarus
« Reply #2 on: December 03, 2019, 12:04:53 pm »
...
You will see that the program goes into error because it says that the table in the database does not contain the "category" field. This is true because it is a fklookup field added on the dataset to make the grid graphically usable. How can I save by telling him to ignore that field?
...
To solve this problem just assign 0 to the category field before you save it.
But keep in mind that 0 means then there is no category assigned to it
You treat a disease, you win, you lose.
You treat a person and I guarantee you, you win, no matter the outcome.

Lazarus 2.0.2 / FPC 3.0.4
Lazarus Trunc / FPC 3.0.4
Mac OS X Mojave

xinyiman

  • Hero Member
  • *****
  • Posts: 1991
    • Lazarus and Free Pascal italian community
Re: Problems with the standard (database) components of lazarus
« Reply #3 on: December 04, 2019, 11:46:11 pm »
First problem solved with this:

Code: Pascal  [Select]
  1. Self.Q_Grid_t_prodotti.FieldByName('business_unit').ProviderFlags:=Self.Q_Grid_t_prodotti.FieldByName('business_unit').ProviderFlags - [pfInUpdate];
  2.      

Idea to second problem?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

tonyw

  • Full Member
  • ***
  • Posts: 152
    • MWA Software
Re: Problems with the standard (database) components of lazarus
« Reply #4 on: December 05, 2019, 11:31:03 am »
I think your problem may be due to changing from one set of database components to another and then assuming that it will work the same way.

For example, I don't recognise compile time options such as "-dNoRefreshAfterInsert". Are these zeos specific? This symbol is not present in the DB unit, and I don't know zeos.

You seem to finding problems with FieldDefs. Again, these may change between database access libraries. FieldDefs are object oriented and are often sub-classed by a database driver. For example, IBX has its own extended TIBStringField for string types so that it can correctly transliterate to and from the database character set. The information is passed to the TIBStringField by a TIBFieldDef = class(TFieldDef).

You will typically need to delete and re-create any fielddefs created in the Lazarus IDE Field Editor when you move between database drivers.

TBookmark is always dependent on the database driver. TDataset does not define its semantic. It could be a record number or a pointer to a buffer, etc. If you refresh a row then a TBookmark should not change, but if you refresh a dataset then... refer to your database driver documentation to see what happens next.


xinyiman

  • Hero Member
  • *****
  • Posts: 1991
    • Lazarus and Free Pascal italian community
Re: Problems with the standard (database) components of lazarus
« Reply #5 on: December 05, 2019, 01:53:26 pm »
Quote
For example, I don't recognize compile time options such as "-dNoRefreshAfterInsert".

No, the -dNoRefreshAfterInsert and other custom options have been added by me to let you compile the program to generate the problem in the test example. In the end my goal is to be able to reposition myself on the same line as a dbgrid (including the right scrollbar position) after a refresh. If there are other solutions, they are welcome
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1