You'll learn, but to explain a bit more:
The big thing that I learned is the Data Module HAS TO be created in your app.lpr BEFORE you create your main form.
If your forms do not access anything in data module at the creation of forms, data module doesn't have to be created before forms. In your case, I think datasets (TSQLQuery, TBufDataSet, etc.) are on data module, TDataSource and data controls (TDBGrid, TDBEdit, etc.) are on forms, and your datasource's dataset is pointing to datasets on the data module (hard coded). In this case, at the creation of forms, it tries to access data module, and data module should have been created before the creation of forms. But if you assign datasource's dataset property at runtime, you may created data module within the forms. For example,
procedure TForm1.FormCreate(Sender: TObject);
begin
DM1 := TDM1.Create (nil);
DataSource1.DataSet := DM1.SQLQuery1;
DM1.SQLQuery1.Open;
end;
Also, putting the Data Module as your first USE unit in your data forms.
Generally this is not important.
ShowModal was a bit of an issue for Data forms. Non-Data forms, i.e. an About (your app.) form I use ShowModal. I just changed the data forms to just form.show.
With ShowModal, the modal form is not destroyed at close until you free it explicitly. I made following example:
procedure TForm1.Button1Click(Sender: TObject);
begin
with Tform2.create (nil) do begin
ShowModal;
if ModalResult = mrOK // this form is closed at this point
then showmessage(Edit1.Caption); // Edit1 is on TForm2, because of "with"
Free; // and form is freed here.
// if edit1.caption = .. // this will cause invalid access, because the form has been freed.
end;
end;
I attached the sample project. Here, you have to notice:
1) In project options, form1 is auto-created while form2 is just available.
2) On TForm2, btn1.ModalResult = mrOK, and btn2.ModalResult = mrCancel (at object inspector).