Page 1 of 1

Filter the Connect Dialog Database list

Posted: Tue 26 Oct 2010 09:45
by siik
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.

Posted: Thu 28 Oct 2010 09:13
by AndreyZ
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;