The Advantage client Engine 10.1 introduced new API calls. One of them, AdsConnect101, can connect to a database using a connection string rather than setting the connection options one by one.

UNSIGNED32 AdsConnect101(
  UNSIGNED8 *pucConnectString, 
  ADSHANDLE *phConnectOptions,
  ADSHANDLE *phConnect);

TAdsConnection is able to hook into such a connection, either by setting the ConnectionHandle (TAdsConnection.SetHandle) or by creating a new component based on that ConnectionHandle (TAdsConnection.CreateWithHandle, TAdsConnection.CreateFromHandle).

However, this useful functionality of using a connection string directly is not exposed in TAdsConnection component – you can only retrieve it by calling TAdsConnection.ConnectString function.
So I’ve decided to write my own TAdsConnection descendant:

unit adsconnectionex;  
interface  
uses adscnnct, adsdata, ace;   
    
type  
 TAdsConnectionEX = class(TAdsConnection)  
 private  
   function GetConnectionString: string;  
   procedure SetConnectionString(const Value: string);  
 published  
   property ConnectionString: string read GetConnectionString write SetConnectionString;  
  end;  

procedure Register;  

implementation  

procedure Register;  
begin  
  RegisterComponents('Advantage', [TAdsConnectionEX]);  
end;  

function TAdsConnectionEX.GetConnectionString: string;  
begin  
  //use the inherited ConnectString function  
  Result:=ConnectString;  
end;  

procedure TAdsConnectionEX.SetConnectionString(const Value: string);  
var  
  hconn: ADSHANDLE;  
  sconn: ansistring;  
begin  
  if IsConnected   
    then raise AdsConnectionError.Create( 'The TAdsConnection.ConnectionString '+ 
      'may not be changed when IsConnected is TRUE');  
  //implicit conversion of string to AnsiString  
  sconn:=Value;  
  //connect using the ACE API call  
  ACECheck(nil, ace.AdsConnect101(PAnsiChar(sconn),nil,@hconn));  
  //hook self to the connection handle returned by the ACE API call  
  self.SetHandle(hconn,true);  
  //tell the ancestor component not to keep the connection after Disconnect  
  self.FGivenConnection:=0;  
end;  

end.