Recent

Author Topic: Everything DBNavigator  (Read 580 times)

pixelink

  • Hero Member
  • *****
  • Posts: 943
    • Pixelink Media
Everything DBNavigator
« on: April 26, 2019, 01:56:51 pm »
Okay...

Using a DBNavigator and DBGrid, using SQLLite3

Everything is working with the grid.
The navigator works as expected!

Question...

How do I capture the delete buttons Confirmation (OK& Cancel) response by user?
Also, can I change the buttons to 'Yes' "No" instead of "OK" & "Cancel"?

Thanks
Can't Type - Forgetful - Had Stroke = Forgive this old man!


Pixelink Media •  Pixelink Forum
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

devEric69

  • Jr. Member
  • **
  • Posts: 90
Re: Everything DBNavigator
« Reply #1 on: April 26, 2019, 03:19:02 pm »
You can code the confirmation question in the onBeforeDelete, etc, events of your TDataset, with...

Code: Pascal  [Select]
  1. if MessageDlg('....', mtConfirmation, [mbOK,mbCancel], 0) = mrCancel then begin
  2.     raise; // silent exception
  3. else Begin
  4.    .../...
  5. end;
use: Ubuntu 18.04 + Laz. 1.8.5 + FPC 3.0.5 (64 bits).

pixelink

  • Hero Member
  • *****
  • Posts: 943
    • Pixelink Media
Re: Everything DBNavigator
« Reply #2 on: April 26, 2019, 03:55:27 pm »
You can code the confirmation question in the onBeforeDelete, etc, events of your TDataset, with...

Code: Pascal  [Select]
  1. if MessageDlg('....', mtConfirmation, [mbOK,mbCancel], 0) = mrCancel then begin
  2.     raise; // silent exception
  3. else Begin
  4.    .../...
  5. end;

1) I don't see a "onBeforeDelete" event on the Datasource or DBNav component.
2) I also need to capture the AFTER delete too... sorry failed to mention that.
Can't Type - Forgetful - Had Stroke = Forgive this old man!


Pixelink Media •  Pixelink Forum
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

hrayon

  • Full Member
  • ***
  • Posts: 100
Re: Everything DBNavigator
« Reply #3 on: April 26, 2019, 03:57:57 pm »
If you want capture events using DBNavigator, use BeforeAction procedure.
And verify the pressed button... see:


Code: Pascal  [Select]
  1. ...
  2. procedure TForm_Test.DBNavigator_TestBeforeAction(
  3.   Sender: TObject; Button: TDBNavButtonType);
  4. begin
  5.   if (Button = nbDelete) then
  6. ...

pixelink

  • Hero Member
  • *****
  • Posts: 943
    • Pixelink Media
Re: Everything DBNavigator
« Reply #4 on: April 26, 2019, 03:59:50 pm »
If you want capture events using DBNavigator, use BeforeAction procedure.
And verify the pressed button... see:


Code: Pascal  [Select]
  1. ...
  2. procedure TForm_Test.DBNavigator_TestBeforeAction(
  3.   Sender: TObject; Button: TDBNavButtonType);
  4. begin
  5.   if (Button = nbDelete) then
  6. ...

I don't see those Before/After events properties in the DBNaviagtor
Where are they?
Can't Type - Forgetful - Had Stroke = Forgive this old man!


Pixelink Media •  Pixelink Forum
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

hrayon

  • Full Member
  • ***
  • Posts: 100
Re: Everything DBNavigator
« Reply #5 on: April 26, 2019, 04:06:16 pm »
I was replying reading before you post about then "after" event request.
BeforeAction is the first event when you go to respective tab in object inspector.
But "after" events aren't implemented there.
Probably you need use the dataset component to use them.

pixelink

  • Hero Member
  • *****
  • Posts: 943
    • Pixelink Media
Re: Everything DBNavigator
« Reply #6 on: April 26, 2019, 05:12:23 pm »
I was replying reading before you post about then "after" event request.
BeforeAction is the first event when you go to respective tab in object inspector.
But "after" events aren't implemented there.
Probably you need use the dataset component to use them.

I know what before/after are

And I am using the DB components for SQL

But, I don't see the Before/After on the events panel for DBNavigator or SQQLQuery or SQLDatasource components.
Can't Type - Forgetful - Had Stroke = Forgive this old man!


Pixelink Media •  Pixelink Forum
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

devEric69

  • Jr. Member
  • **
  • Posts: 90
Re: Everything DBNavigator
« Reply #7 on: April 26, 2019, 05:21:04 pm »
Quote
1) I don't see a "onBeforeDelete" event on the Datasource or DBNav component.

It is an event in TQuery, TTable, etc, ie in components descending from TDataset

Quote
2) I also need to capture the AFTER delete too... sorry failed to mention that.

In TDataset, there are many events like AfterDelete, AfterPost, etc.
There is an error in the code I wrote. You have to use it instead, if you want:
Code: Pascal  [Select]
  1. if MessageDlg('....', mtConfirmation, [mbOK,mbCancel], 0) = mrCancel then begin
  2.     Abort; // (<==!!!) silent exception  :-[
  3. else Begin
  4.    .../...
  5. end;
« Last Edit: April 26, 2019, 05:26:24 pm by devEric69 »
use: Ubuntu 18.04 + Laz. 1.8.5 + FPC 3.0.5 (64 bits).

pixelink

  • Hero Member
  • *****
  • Posts: 943
    • Pixelink Media
Re: Everything DBNavigator
« Reply #8 on: April 26, 2019, 05:30:15 pm »
Quote
1) I don't see a "onBeforeDelete" event on the Datasource or DBNav component.

It is an event in TQuery, TTable, etc, ie in components descending from TDataset

Quote
2) I also need to capture the AFTER delete too... sorry failed to mention that.

In TDataset, there are many events like AfterDelete, AfterPost, etc.
There is an error in the code I wrote. You have to use it instead, if you want:
Code: Pascal  [Select]
  1. if MessageDlg('....', mtConfirmation, [mbOK,mbCancel], 0) = mrCancel then begin
  2.     Abort; // (<==!!!) silent exception  :-[
  3. else Begin
  4.    .../...
  5. end;

Id there documentation that list all these unseen procedures someplace?
Can't Type - Forgetful - Had Stroke = Forgive this old man!


Pixelink Media •  Pixelink Forum
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

devEric69

  • Jr. Member
  • **
  • Posts: 90
Re: Everything DBNavigator
« Reply #9 on: April 26, 2019, 05:55:04 pm »
See https://lazarus-ccr.sourceforge.io/docs/rtl/sysutils/eabort.html.

So, you can code:

Code: Pascal  [Select]
  1. uses
  2.   sysutils;
  3. .../...
  4.   sysutils.Abort;
« Last Edit: April 26, 2019, 06:03:29 pm by devEric69 »
use: Ubuntu 18.04 + Laz. 1.8.5 + FPC 3.0.5 (64 bits).

lucamar

  • Hero Member
  • *****
  • Posts: 1829
Re: Everything DBNavigator
« Reply #10 on: April 26, 2019, 06:33:42 pm »
Id there documentation that list all these unseen procedures someplace?

While the documentation is still somewhat lacking, it's steadily getting better. One thing I always recomending to our newbies is to open the chms and read them through or, if they have no time, at least the lists of of classes and procedures/functions, at a minimum for the RTL and FCL. And, of course, the Reference manual, if not the Users and Programmers ones.

If later one needs a class or function doing something, one always thinks: "Hmm... I kind of remember having seen something like that in the docs..." :)
« Last Edit: April 26, 2019, 06:37:19 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 1.8.4 & 2.0.2 w/FPC 3.0.4 on:
(K|L)Ubuntu 12..16, Windows XP SP3, various DOSes.

pixelink

  • Hero Member
  • *****
  • Posts: 943
    • Pixelink Media
Re: Everything DBNavigator
« Reply #11 on: April 27, 2019, 01:17:42 am »
If you want capture events using DBNavigator, use BeforeAction procedure.
And verify the pressed button... see:


Code: Pascal  [Select]
  1. ...
  2. procedure TForm_Test.DBNavigator_TestBeforeAction(
  3.   Sender: TObject; Button: TDBNavButtonType);
  4. begin
  5.   if (Button = nbDelete) then
  6. ...

Hey @hrayon

I am trying what you suggested.
But, I keep getting "Class identifier expected"

I have doubled and triple checked that  everything is in place. (yes, Form5 is correct)
But, I am missing something.

I usually don't have problems with procedures, but this one is not working.

Code: Pascal  [Select]
  1.  
  2. type
  3.    procedure DBNavigator1BeforeAction(Sender: TObject; Button: TDBNavButtonType);
  4.  
  5.  
  6. procedure Form5.DBNavigator1BeforeAction(Sender: TObject; Button: TDBNavButtonType);
  7. begin
  8.   code.....
  9. end;  
  10.  
  11.  
« Last Edit: April 27, 2019, 01:19:18 am by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!


Pixelink Media •  Pixelink Forum
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060

hrayon

  • Full Member
  • ***
  • Posts: 100
Re: Everything DBNavigator
« Reply #12 on: April 29, 2019, 04:04:28 pm »
@pixelink,

I've attached a sample project to help you.

pixelink

  • Hero Member
  • *****
  • Posts: 943
    • Pixelink Media
Re: Everything DBNavigator
« Reply #13 on: April 29, 2019, 05:14:27 pm »
@pixelink,

I've attached a sample project to help you.


Thank You.
I was missing the T in front of Form1.DbNa....

Sorry, O had a stroke 2 months ago and I can'r concentrate very well.
Can't Type - Forgetful - Had Stroke = Forgive this old man!


Pixelink Media •  Pixelink Forum
LAZ 2.02 • Win10 • 16G RAM • Nivida GForce RTX 2060