const
  ODBC_ADD_DSN        = 1;
  ODBC_CONFIG_DSN     = 2;
  ODBC_REMOVE_DSN     = 3;
  ODBC_ADD_SYS_DSN    = 4;
  ODBC_CONFIG_SYS_DSN = 5;
  ODBC_REMOVE_SYS_DSN = 6;function SQLConfigDataSource(hwndParent: Integer;
  fRequest: LongInt; lpszDriverString: string;
  lpszAttributes: string): LongBool; stdcall; external 'ODBCCP32.DLL';procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
const
  BoolStr: array[Boolean] of string = ('f', 't');
begin
  if Key <> VK_RETURN then Exit;
  Caption := BoolStr[
    SQLConfigDataSource(0, ODBC_ADD_SYS_DSN,
//                    ~换成Handle就是手工配置
'SQL Server',                       //数据库类型
'DSN=MyDatabase'#0 +                //数据源名称
'Server=(local)'#0 +                //SQL Server服务器名
'Database=DatabaseName'#0 +         //数据库名称
'Description=动态配置ODBC'#0        //描述
    )];
end;