Page 1 of 1
Custom ConnectDlg with C++Builder
Posted: Thu 22 Jul 2010 15:46
by pterblan
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
Posted: Mon 26 Jul 2010 11:56
by Dimon
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();
}
//---------------------------------------------------------------------------
Posted: Tue 27 Jul 2010 09:28
by pterblan
Works like a charm, thanks very much!
Piet