Filter the Connect Dialog Database list

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
siik
Posts: 10
Joined: Fri 12 Jun 2009 06:10

Filter the Connect Dialog Database list

Post by siik » Tue 26 Oct 2010 09:45

Hi,

I would like to know if i can filter the list of databases in the TMyConnectDialog.

I have tried implementing my own custom dialog, however whenever i use GetDataBaseNames() function, the standard connect dialog pops up to establish the connection.

Im a bit stuck on how to do this.

Any help is appreciated.

AndreyZ

Post by AndreyZ » Thu 28 Oct 2010 09:13

Hello,

You can filter database names in your custom connection dialog. Try using this code:

Code: Select all

// cbDatabases - your ComboBox with database names
procedure TYourCustomConnectDialogForm.cbDatabasesDropDown(Sender: TObject);
var
  OldLoginPrompt: boolean;
  str: TStringList;
begin
  OldLoginPrompt := FConnectDialog.Connection.LoginPrompt;
  FConnectDialog.Connection.LoginPrompt := False;
  str := TStringList.Create;
  try
    FConnectDialog.Connection.Server := edServer.Text;
    FConnectDialog.Connection.UserName := edUsername.Text;
    FConnectDialog.Connection.Password := edPassword.Text;
    TMyConnection(FConnectDialog.Connection).Port := StrToInt(edPort.Text);
    FConnectDialog.Connection.GetDatabaseNames(str);
    //here you can filter database names in str
    cbDatabases.Items.Assign(str);
  finally
    str.Free;
    FConnectDialog.Connection.LoginPrompt := OldLoginPrompt;
  end;
end;

Post Reply