これは奇妙なもののように見えます。
MySQL データベースに接続する Pascal ユニットがあります
unit u_MySQLConnection;
interface
uses
ADODB,
AnsiStrings,
Generics.Collections,
SysUtils,
DB
;
type
TMySQLConnection = class
strict private
mysqlCon : TADOConnection;
public
function Connect:boolean;
destructor Destroy;
end;
var
MySQLConnection : TMySQLConnection;
implementation
function TMySQLConnection.Connect:boolean;
var
success : boolean;
begin
success := true;
try
if NOT (mysqlCon = nil)
then mysqlCon.Destroy;
mysqlCon := TADOConnection.Create(nil);
mysqlCon.ConnectionString := 'DRIVER={MySQL ODBC 3.51 Driver}; SERVER=localhost; DATABASE=database; UID=root; PASSWORD=password;OPTION=3;';
except
success := false;
end;
Result := success;
end;
destructor TMySQLConnection.Destroy;
begin
FreeAndNil(mysqlCon);
inherited;
end;
end.
そして接続しようとすると
MySQLConnection := TMySQLConnection.Create;
try
MySQLConnection.Connect;
finally
MySQLConnection.Destroy;
end;
パスワードが既に接続文字列に含まれているにもかかわらず、パスワード プロンプト ダイアログ ボックスが表示されます。このプロンプトにユーザー名とパスワードを入力すると、他のすべてが正常に機能します。
ここで少し奇妙になります:
示されているように、データベース接続コマンドをメインの .dpr ファイルに移動すると
program DieselBatch;
uses
Vcl.Forms,
u_MySQLConnection in '..\src\u_MySQLConnection.pas'
(*,
frm_About in '..\src\frm_About.pas' {frmAbout},
frm_AnalystDetails in '..\src\frm_AnalystDetails.pas' {frmAnalystDetails},
frm_Batch in '..\src\frm_Batch.pas' {frmBatch},
frm_ConfirmResultsChanged in '..\src\frm_ConfirmResultsChanged.pas' {frmConfirmResultsChanged},
frm_DebugSample in '..\src\frm_DebugSample.pas' {frmDebugSample},
frm_FlashManualEntry in '..\src\frm_FlashManualEntry.pas' {frmFlashEntry},
frm_Main in '..\src\frm_Main.pas' {frmMain},
frm_SampleComment in '..\src\frm_SampleComment.pas' {frmSampleComment},
frm_SelectAnalystForResult in '..\src\frm_SelectAnalystForResult.pas' {frmSelectAnalystForResult},
u_Data in '..\src\u_Data.pas',
u_MicroCheck in '..\src\u_MicroCheck.pas',
u_Undo in '..\src\u_Undo.pas'
*)
;
{$R *.res}
var
MySQLConnection : TMySQLConnection;
begin
MySQLConnection := TMySQLConnection.Create;
try
MySQLConnection.Connect;
finally
MySQLConnection.Destroy;
end;
これらのユニットがコメントアウトされている限り、パスワードプロンプトは表示されません。
上記のユニットのコメントを再度外すと、問題が再発します。
これらのユニットの一部は ADODB と DB を使用しますが、ユニットが存在するだけで MySQLConnection ユニットの動作にどのような影響があるかわかりません ....