Recent

Author Topic: After Add Record procedure  (Read 2171 times)

dsyrios

  • Jr. Member
  • **
  • Posts: 57
After Add Record procedure
« on: November 26, 2018, 06:10:27 pm »
Hi,
I need help using sqlite/zeos.
I want... after add a record using only DBnavigator
and if the result is OK, then run something like
"procedure After_Add_Record;"

p.s.
I've allready try with DBnavigator and ZQuery events
but without success, maybe the solution is combine them somehow.
Win32/Laz1.8.2
Laz 2.0.2/FPC 3.0.4/ win10/64
Laz 2.0.0/FPC 3.0.4/ mint-mate 19.1

GAN

  • Sr. Member
  • ****
  • Posts: 252
Re: After Add Record procedure
« Reply #1 on: November 27, 2018, 12:00:31 am »
Why don't make your own navigator? It's very simple and you control all.
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

lucamar

  • Hero Member
  • *****
  • Posts: 2274
Re: After Add Record procedure
« Reply #2 on: November 27, 2018, 12:14:55 am »
If you want to react to changes in the data, use the events of the data source in YourDBNavigator.Datasource. The DBNavigator control is just a UI widget.

Or make your own navigator, as GAN said :)
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.4/2.0.6  - FPC 3.0.4 on:
(K|L)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

BSaidus

  • Sr. Member
  • ****
  • Posts: 314
  • lazarus 1.8.4 Win8.1 / cross FreeBSD
Re: After Add Record procedure
« Reply #3 on: November 27, 2018, 09:40:48 am »
Hi,
I need help using sqlite/zeos.
I want... after add a record using only DBnavigator
and if the result is OK, then run something like
"procedure After_Add_Record;"

p.s.
I've allready try with DBnavigator and ZQuery events
but without success, maybe the solution is combine them somehow.
Win32/Laz1.8.2

Why not use AfterPost event of dataSet (Query or Table)

Code: Pascal  [Select]
  1. procedure TMyForm.qryListClientsAfterPost(DataSet: TDataSet);
  2. begin
  3.   // put here your code .....
  4. end;
  5.  




lazarus 1.8.4 Win8.1 / cross FreeBSD
dhukmucmur vernadh!

dsyrios

  • Jr. Member
  • **
  • Posts: 57
Re: After Add Record procedure
« Reply #4 on: November 27, 2018, 08:00:00 pm »
Thanks all for your answers.
@Gan... It's for an old existing code and it's difficult for me to change it.
@Lucamar & @ BSaidus... I've tried, but I failed.

I attach a very simple project to understand the procedure that I need.
Laz 2.0.2/FPC 3.0.4/ win10/64
Laz 2.0.0/FPC 3.0.4/ mint-mate 19.1

HeavyUser

  • Sr. Member
  • ****
  • Posts: 273
Re: After Add Record procedure
« Reply #5 on: November 27, 2018, 09:44:09 pm »
Thanks all for your answers.
@Gan... It's for an old existing code and it's difficult for me to change it.
@Lucamar & @ BSaidus... I've tried, but I failed.

I attach a very simple project to understand the procedure that I need.
as far as I can see from the code posted the afterscroll event is called after inserting / appending a new record but before the user selects the post or cancel actions. This means that the check of known record count and new record count will always be the same on the after post event. try to remove the check from the CheckChangeRecs method and only call CheckChangeRecs from the afterpost event only.

dsyrios

  • Jr. Member
  • **
  • Posts: 57
Re: After Add Record procedure
« Reply #6 on: November 28, 2018, 03:48:41 am »
@HeavyUser Thanks for your attention,
 The code is demo, I agree/know that AfterScroll() is useless for the main problem,  it's just only a way to update the ComboBox.Text
 The main problem is to have the deleted or new record,
 so that I can remove it or add it to the ComboBox.Items.
 I've try to catch something like  TUpdateKind = (ukModify, ukInsert, ukDelete)
 and combine with AfterPost() or BeforePost() event, but I failed.
Laz 2.0.2/FPC 3.0.4/ win10/64
Laz 2.0.0/FPC 3.0.4/ mint-mate 19.1

HeavyUser

  • Sr. Member
  • ****
  • Posts: 273
Re: After Add Record procedure
« Reply #7 on: November 28, 2018, 04:00:32 am »
@HeavyUser Thanks for your attention,
 The code is demo, I agree/know that AfterScroll() is useless for the main problem,  it's just only a way to update the ComboBox.Text
 The main problem is to have the deleted or new record,
 so that I can remove it or add it to the ComboBox.Items.
 I've try to catch something like  TUpdateKind = (ukModify, ukInsert, ukDelete)
 and combine with AfterPost() or BeforePost() event, but I failed.
so? Doesn't any of my recommendations work?

mangakissa

  • Hero Member
  • *****
  • Posts: 962
Re: After Add Record procedure
« Reply #8 on: November 28, 2018, 08:51:04 am »
The main problem is to have the deleted or new record,
 so that I can remove it or add it to the ComboBox.Items.
 I've try to catch something like  TUpdateKind = (ukModify, ukInsert, ukDelete)
 and combine with AfterPost() or BeforePost() event, but I failed.
Read the post of BSaidus.
For deleting record use the BeforeDelete and AfterDelete events to modify the combobox.
For modifying /adding records use AfterPost event. TCombobox.items.indexof(<value : string>) is your best friend.
TUpdatekind has nothing to do in this case.
Lazarus 1.84 (32b) / FPC 3.0.4
Windows 10

dsyrios

  • Jr. Member
  • **
  • Posts: 57
Re: After Add Record procedure
« Reply #9 on: November 28, 2018, 05:18:01 pm »
 Thank you all for your help,
 maybe I wasn't so clear
 the solution to my problem is to replace the class of the TComboBox to TDBLookupComboBox,
 but WITHOUT affection to the datasource I use...
     DataSource :=nil;
     DataField :='';
 so I have an updating list at the box.
 Now I'll try to apply this to my main project.
 thanks again
 p.s. I attach the new simple demo
Laz 2.0.2/FPC 3.0.4/ win10/64
Laz 2.0.0/FPC 3.0.4/ mint-mate 19.1