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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...