Lena Posted April 4, 2015 Share Posted April 4, 2015 Where more correct to open a database connection? In UniGUIMainModuleCreate or in UniFormShow? Thanks. //in UniMainModule void __fastcall TUniMainModule::UniGUIMainModuleCreate(TObject *Sender) { //FireDAC FDQuery1->Active = true; FDQuery1->FetchAll(); FDQuery1->First(); } //then in main form void __fastcall TMainForm::UniFormShow(TObject *Sender) { if(UniMainModule()->FDQuery1->RecordCount == 0) { ShowMessage(L"No data"); return; } UniMainModule()->ClientDataSet1->Active = true; } //************************************************* //Or all code in main form void __fastcall TMainForm::UniFormShow(TObject *Sender) { //FireDAC UniMainModule()->FDQuery1->Active = true; UniMainModule()->FDQuery1->FetchAll(); UniMainModule()->FDQuery1->First(); if(UniMainModule()->FDQuery1->RecordCount == 0) { ShowMessage(L"No data"); return; } UniMainModule()->ClientDataSet1->Active = true; } Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted April 4, 2015 Administrators Share Posted April 4, 2015 Both are valid. FormCreate or FormBeforeShow is preferred over FormShow. Quote Link to comment Share on other sites More sharing options...
Lena Posted April 4, 2015 Author Share Posted April 4, 2015 Thank you very much! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.