Jump to content

Where is correct to open a database connection?


Lena

Recommended Posts

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;
}
Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...