Custom ConnectDlg with C++Builder

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
pterblan
Posts: 6
Joined: Thu 22 Jul 2010 15:19

Custom ConnectDlg with C++Builder

Post by pterblan » Thu 22 Jul 2010 15:46

Does anyone have an example of using one's own connect dialog in Builder? I need to use a themed one but can't figure it out from the Delphi example.
Thanks
Piet

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 26 Jul 2010 11:56

You can see an example of using own connect dialog in Delphi MyDAC Demo.
Also you can see below the example of the CustomConnectForm unit on C++. The CustomConnectForm.dfm file is the same as in the Delphi demo.

Code: Select all

//---------------------------------------------------------------------------
#include 
#pragma hdrstop
#include "CustomConnectForm.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TfmCustomConnect *fmCustomConnect;
//---------------------------------------------------------------------------
__fastcall TfmCustomConnect::TfmCustomConnect(TComponent* Owner)
	: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TfmCustomConnect::DoInit()
{
  FRetry = False;
  FRetries = FConnectDialog->Retries;
  Caption = FConnectDialog->Caption;

  lbUsername->Caption = FConnectDialog->UsernameLabel;
  lbPassword->Caption = FConnectDialog->PasswordLabel;
  lbServer->Caption = FConnectDialog->ServerLabel;
  btConnect->Caption = FConnectDialog->ConnectButton;
  btCancel->Caption = FConnectDialog->CancelButton;

  TStringList* List = new TStringList();
  try {
	FConnectDialog->GetServerList(List);
	AssignStrings(List, edServer->Items);
  }
  __finally {
	List->Free();
  }

  edUsername->Text = FConnectDialog->Connection->Username;
  edPassword->Text = FConnectDialog->Connection->Password;
  edServer->Text = FConnectDialog->Connection->Server;

  if (edUsername->Text != "" && edPassword->Text == "")
	ActiveControl = edPassword;
}
//---------------------------------------------------------------------------
void __fastcall TfmCustomConnect::DoConnect()
{
  FConnectDialog->Connection->Password = edPassword->Text;
  FConnectDialog->Connection->Server = edServer->Text;
  FConnectDialog->Connection->Username = edUsername->Text;
  TMyConnection* MyConnection = (TMyConnection*)FConnectDialog->Connection;
  MyConnection->Port = StrToInt(edPort->Text);
  FConnectDialog->Connection->Database = edDatabase->Text;
  try {
	FConnectDialog->Connection->PerformConnect(FRetry);
	ModalResult = mrOk;
  }
  catch (EMyError &exception) {
	FRetries--;
	FRetry = true;
	if (FRetries == 0)
	  ModalResult = mrCancel;
	if (exception.ErrorCode == CR_CONN_HOST_ERROR)
	  ActiveControl = edServer;
	else
	  if (exception.ErrorCode == ER_ACCESS_DENIED_ERROR)
		if (ActiveControl != edUsername)
		  ActiveControl = edPassword;
	throw;
  }
  catch (Exception &exception) {
	throw;
  }
}
//---------------------------------------------------------------------------
void __fastcall TfmCustomConnect::SetConnectDialog(TMyConnectDialog* Value)
{
  FConnectDialog = Value;
  DoInit();
}
//---------------------------------------------------------------------------
void __fastcall TfmCustomConnect::btConnectClick(TObject *Sender)
{
  DoConnect();
}
//---------------------------------------------------------------------------

pterblan
Posts: 6
Joined: Thu 22 Jul 2010 15:19

Post by pterblan » Tue 27 Jul 2010 09:28

Works like a charm, thanks very much!
Piet

Post Reply