Recent

Author Topic: Configuring and using DBNavigator SQLite3  (Read 2451 times)

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Configuring and using DBNavigator SQLite3
« on: September 04, 2020, 02:39:40 am »
I have read thru the Database form and tried several thing but can't get DBNavigator to work.

My Database loads and displays in the Grid but nothing from DBNavigator.

Would like to edit, delete, and insert

Need help.

Thanks
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1186
    • Burdjia
Re: Configuring and using DBNavigator SQLite3
« Reply #1 on: September 04, 2020, 12:00:23 pm »
You forgot the DBNavigator.DataSource. Do not create a new DataSource, it is not necessary.

BTW, why do you set the properties in run-time instead of in design-time?
« Last Edit: September 04, 2020, 12:02:28 pm by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Configuring and using DBNavigator SQLite3
« Reply #2 on: September 04, 2020, 12:03:34 pm »
Yea, I did at one point it was set to DataSource1. Ot wasn't set in what I posted.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

wp

  • Hero Member
  • *****
  • Posts: 11915
Re: Configuring and using DBNavigator SQLite3
« Reply #3 on: September 04, 2020, 12:25:03 pm »
Yea, I did at one point it was set to DataSource1. Ot wasn't set in what I posted.
I don't understand what this means...

Change your FormCreate method as follows:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.FormCreate(Sender: TObject);
  2. begin
  3.   DBConnection               := TSQLConnector.Create(nil);
  4.   DBConnection.ConnectorType := 'SQLite3';
  5.   DBConnection.DataBaseName  := 'Flights.DB';
  6.  
  7.   {* -- Setup a transaction *}
  8.   DBTransaction              := TSQLTransaction.Create(DBConnection);
  9.   DBTransaction.Database     := DBConnection;
  10.  
  11.   {* -- Setup a query *}
  12.   DBQuery                    := TSQLQuery.Create(DBConnection);
  13.   DBQuery.DataBase           := DBConnection;
  14.   DBQuery.TransAction        := DBTransaction;
  15.   {* We need to make some adjustments to avoid strings being displayed as
  16.     (memo) in a grid and we do that at the afteropen event  *}
  17.   DBQuery.AfterOpen          := @DBQueryAfterOpen;
  18.  
  19.  {* -- Setup the datasource *}
  20.   DataSource                 := TDataSource.Create(Self);
  21.   DataSource.DataSet         := DBQuery;
  22.  
  23.   {* -- Connect the grid to the datasource  *}
  24.   DBGrid1.DataSource         := DataSource;
  25.  
  26.   (* -- Connect the DBNavigator to the datasource *)
  27.   DBNavigator1.DataSource    := DataSource;      // <----------------- ADD
  28. end;  

Normally it is not needed to write an OnClick handler for DBNavigator because inserting, editing, or deleting of records is built into the navibator.

BTW, if you use only a DBGrid on the form, not any other DB-aware controls for editing, adding, deleting of records, then you don't need a navigator at all because these features can be done with the DBGrid as well.

JLWest

  • Hero Member
  • *****
  • Posts: 1293
Re: Configuring and using DBNavigator SQLite3
« Reply #4 on: September 04, 2020, 12:51:08 pm »
Yea, I did at one point it was set to DataSource1. Ot wasn't set in what I posted.

It means at one point I tested with setting the DataSourse1 in DBNavagator. When I posted the code  it was removed.

It appears I can delete a row but not insert a row or edit a row with that line in the Oncreate.

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018