No..
procedure TFrmCntksMgt.FormShow(Sender: TObject);
begin
QueryContacts.SQL.Text:= 'SELECT * FROM CONTACTS';
QueryClients.SQL.Text:= 'SELECT * FROM CLIENTS';
QueryStprovcodes.SQL.Text:= 'SELECT * FROM STPROVCODES';
QueryCouuntries.SQL.Text:= 'SELECT * FROM COUNTRIES';
QueryContacts.open;
QueryClients.OPpen;
QueryStprovcodes.Open;
QueryCouuntries.Open;
// I think you'd better do followings with DBGrid
// DSStates.DataSet.FieldByName('STPROVCODE').DisplayWidth:= 2;
// DSStates.DataSet.FieldByName('STPROVNAME').DisplayWidth:= 12;
DGStates.Columns[3].DisplayFormat :=...; // DGStates is DBGrid, and TDBGrid.columns are 0-based indexes.
DGStates.Columns[3].Width :=...;
DGStates.Columns[4].DisplayFormat :=...;
DGStates.Columns[4].Width :=...;
//---------------------------- the same as above as well.
DGCountries.Columns[0].width := 50;
// .........
// DSCountries.DataSet.FieldByName('CODE').DisplayWidth:= 2;
// DSCountries.DataSet.FieldByName('COUNTRY').DisplayWidth:= 10;
// DSClients.DataSet.FieldByName('CUSTOMER').DisplayWidth:= 12;
{...Fix this later for counting total Contacts records with a SELECT COUNT or the like}
// should look like:
with queryTemp do begin
SQL.Text = 'select count (*) from contacts where client_id=:cid';
Params[0].AsInteger := QueryClients.fieldByName('Client_id').AsInteger;
Open;
tcount := Fields[0].AsInteger; // tcount is an integer variable.
Close;
end;
// And tcount is the total number of contacts for the selected client.
EditTTLContacts.ReadOnly:= False;
IntRecCount:= DSContacts.ExactRecordCount;
EditTTLContacts.Text:= IntToStr(IntRecCount);
EditTTLContacts.ReadOnly:= True;}
JvDBSrchByIndex.Text:= '';
BitBtnSaveCntk.Enabled:= False;
BitBtnCancelCntk.Enabled:= False;
Screen.Cursor:= crDefault;
DBGridCntks.SetFocus;
end;
Focus on datasets, like TSQLQuery, TSQLite3DataSet, etc., not DBGrid or Datasource.
You do this:
1. Drop TSQLite3Connection component and TSQLTransaction component on a datamodule, DmPMSDataBase in your case.
- Set database of TSQLite3Connection to your DB file,
- set transaction to the transaction component.
try to "connect" by clicking the checkbox in the object inspector. Should be stay in "checked" state.
2. Create a form, add dmPMSDataBase in the "uses" clause of the form. Then,
- drop TSQLQuery, Tdatasource, TDBGrid, and TDBEdit, TDBLabel, TDBMemo as you need.
- Set TSQLquery.Database to dmPMSDataBase.SQLite3Connection.
- Set TDataSource.DataSet to the SQLQuery.
- Set the datasource of all the data controls (DBGrid, DBEdit, DBMemo, DBLabels, etc.) to the datasource on the form.
- Type in SQL property of TSQLQuery as "Select * from Clients"
- Try to Open it clicking "Active" at the object inspector.
If everything is OK, you should be able to see the contents of the table at the design time -- without running the application.
3. Create second form, and to the same things as step 2, using different tables. You can add more forms.
Every form will have the same names by default, SQLQuery1, DataSource1, DBGrid1, etc. , unless you rename them. Doesn't matter.
4. Once you have made a few forms, then Set all the "active" components to inactive state. SQLite3Connection, and TSQLQueries of every form. And write some codes:
at DataModuleCreate
SQLite3Connection.Connected := true; at Forms' FormShow events:
SQLQuery1.Active := True; That's all. Be careful that datamodule is created first.
And run the application. Then if everything is OK, you must be able to see the contents of the first form.
You can add a main form, add some menus, and when click a menu, each form will be shown.
Then add more forms as necessary.
This is the most basic approach.