I am developing an application that uses multiple SQLite tables from a single database. These tables are not related to each other in any way. I have a TFDConnection
for the database, TDBGrid
and TDBNavigator
controls for each table, TFDQuery
and TDataSource
for each table.
The TFDQuery
for each table is: SELECT * FROM MRSales
and SELECT * FROM MRCogs
The following is the main forms create code that contains the code to open the tables.
procedure TForm1.MainFormCreate(Sender: TObject);
begin
left:=(Screen.Width-Width) div 2;
top:=(Screen.Height-Height) div 2;
MrsalesTable.open;
MrcogsTable.open;
LoadCombos;
end;
When I run the application I get records to display in DBGrid1
from the first table MrSalesTable
, but none display in DBGrid2
from the second table MrcogsTable
. The DBGrid2 and DBNavigator2 appear to recognize the table and act as if there are records in the table (there are two actual records in the table) but nothing shows up.
Each DBGrid
has the OnColExit
event set to perform some computations and save the results to the table. This event code seems to be working just fine when operating on the first DBGrid1
. Below is the code for DBGrid1
. DBGrid2
is identical but DBGrid1
is replaced with DBGrid2
.
procedure TForm1.Grid1OnColExit(Sender: TObject);
var
i,ccode : integer;
amt1,amt2 : currency;
begin
// zero the variables and retrive the number of months our P&L has
//amt1:=0;
//amt2:=0;
val(cbModelMonths.text,i,ccode);
// check if the val() function had an error. If so, display a message
// and exit the function, otherwise continue on
if ccode <> 0 then
begin
MessageDlg('Error at Position: ' + IntToStr(ccode) +
', i='+IntToStr(i),mtwarning,[mbok],0,mbok);
exit;
end;
// determine which column we are dealing with
case DBGrid1.SelectedIndex of
// this is the amount value column
2: begin
if i < 12 then
begin
if DBGrid1.Fields[2].asCurrency > 0 then
begin
amt1:=DBGrid1.Fields[2].asCurrency;
amt2:=(amt1 / i) * 12;
DBGrid1.Fields[3].asCurrency:=amt2;
end;
end
else
if DBGrid1.Fields[2].asCurrency > 0 then
DBGrid1.Fields[3].asCurrency:=DBGrid1.Fields[3].asCurrency;
end;
// this is the adjustment value column
4: begin
if DBGrid1.Fields[3].asCurrency > 0 then
DBGrid1.Fields[5].AsCurrency:=DBGrid1.Fields[3].AsCurrency+
DBGrid1.Fields[4].AsCurrency
else
DBGrid1.Fields[5].AsCurrency:=0;
end;
end;
end;
The rest of the applications setup is done via the object inspector and data explorer.