Thanks Taaz for the insight, which is perhaps the most detailed I've read so far. But, alas, I am still confused.
That should clear any misunderstandings you might have if not then ask more questions
Sorry!
I'm guessing then the two key elements here are the DataSource, which you say should be one per form, and I guess the SQLQuery?
So I tried creating a secondary Datasource that I linked to the same SQLite3Connection and a secondary SQLQuery instance that I linked to the Datasource. I then I adjusted my code for all the routines that involved my second database table (TBL_COPY) to use the second SQLQuery and Datasource. The result then was an empty grid in the second form :-(
So I guess I'm still not grasping how this all interlinks. Sorry.
In my head, theres a database over there with data in it - several tables full of rows of data. To get that data, you use SELECT statements and to put data in it, you use INSERT statements, which are forumlated by SQLQuery
So then there is the SQQuery which directs what values are retrieved from what parts of the database and what values are put in it, and where.
Then there is an SQLite3Connection, which is a mechanical system for joining the database line to the program - the means in which data is sent to and retrieved from the database.
Then there is the SQLTransaction, which I still don't get.
Then there is the DBGrid which is used to render the result from SQLQuery.Open. So whatever it gets back from the database, it displays in the appropriate grid. So if you have two separate queries and two separate grids, data from the same database can be directed to each I thought (following the replies from you two). But in my test, that has not happened. So either I'm on the right lines and just missed a final step somewhere or I am on the wrong lines! :-(
So then I tried creating a second SQLTransaction. Set the SQLIte3Connection as database. But it generated an error : "cannot start a transaction within a transaction" at one of my other routines (an INSERT procedure, with an SQLQuery.ExecSQL line generates it). So I tried setting the SQLTransaction1.Active to false, and SQLTransaction2.Active := True; but same error :-(
I'm getting very disheartened. I thought implementing SQLIte was supposed to be quite straight forward.
The full code, if it helps people see the wider context of what I am doing, is here :
https://github.com/tedsmith/quickhash/blob/v3Branch/dbases_sqlite.pas The two procedures below show what I have just tried (which is not committed to GIT).
// MainForm has one DBGrid in it
procedure TfrmSQLiteDBases.UpdateGridFILES(Sender: TObject);
begin
try
SQLQuery1.Close;
SQLQuery1.SQL.Text := 'SELECT * FROM TBL_FILES';
SQLite3Connection1.Connected := True;
SQLTransaction1.Active := True;
SQLQuery1.Open;
// Allow the DBGrid to view the results of our query
DataSource1.DataSet := SQLQuery1;
MainForm.RecursiveDisplayGrid1.DataSource := DataSource1;
MainForm.RecursiveDisplayGrid1.AutoFillColumns := true;
except
on E: EDatabaseError do
begin
MessageDlg('Error','A database error has occurred. Technical error message: ' + E.Message,mtError,[mbOK],0);
end;
end;
end;
// frmDisplayGrid1 is the second form that shows different data.
// After execution of this, the results also appear in MainForm.RecursiveDisplayGrid1
procedure TfrmSQLiteDBases.UpdateGridCOPYTAB(Sender: TObject);
begin
try
SQLQuery2.Close;
SQLQuery2.SQL.Text := 'SELECT * FROM TBL_COPY';
SQLite3Connection1.Connected := True;
SQLTransaction1.Active := True; / And tried with a second transaction object, called SQLTransaction2, same problem
SQLQuery2.Open;
// Allow the DBGrid to view the results of our query
DataSource2.DataSet := SQLQuery2;
frmDisplayGrid1.RecursiveDisplayGrid_COPY.DataSource := DataSource2;
frmDisplayGrid1.RecursiveDisplayGrid_COPY.AutoFillColumns := true;
except
on E: EDatabaseError do
begin
MessageDlg('Error','A database error has occurred. Technical error message: ' + E.Message,mtError,[mbOK],0);
end;
end;
end;