diff --git a/packages/fcl-db/src/base/database.inc b/packages/fcl-db/src/base/database.inc index 716f5eb7e3..04221c7331 100644 --- a/packages/fcl-db/src/base/database.inc +++ b/packages/fcl-db/src/base/database.inc @@ -505,7 +505,25 @@ begin FBeforeConnect:=AValue; end; +procedure TCustomConnection.DoLoginPrompt; + +var + ADatabaseName, AUserName, APassword: string; + +begin + if FLoginPrompt then + begin + GetLoginParams(ADatabaseName, AUserName, APassword); + if Assigned(FOnLogin) then + FOnLogin(Self, AUserName, APassword) + else if Assigned(LoginDialogExProc) then + LoginDialogExProc(ADatabaseName, AUserName, APassword, False); + SetLoginParams(ADatabaseName, AUserName, APassword); + end; +end; + procedure TCustomConnection.SetConnected(Value: boolean); + begin If Value<>Connected then begin @@ -520,8 +538,7 @@ begin begin if Assigned(BeforeConnect) then BeforeConnect(self); - if FLoginPrompt then if assigned(FOnLogin) then - FOnLogin(self,'',''); + DoLoginPrompt; DoConnect; if Assigned(AfterConnect) then AfterConnect(self); @@ -543,6 +560,26 @@ begin FBeforeDisconnect:=AValue; end; +procedure TCustomConnection.GetLoginParams(out ADatabaseName, AUserName, APassword: string); +begin + if IsPublishedProp(Self,'DatabaseName') then + ADatabaseName := GetStrProp(Self,'DatabaseName'); + if IsPublishedProp(Self,'UserName') then + AUserName := GetStrProp(Self,'UserName'); + if IsPublishedProp(Self,'Password') then + APassword := 'Password'; +end; + +procedure TCustomConnection.SetLoginParams(const ADatabaseName, AUserName, APassword: string); +begin + if IsPublishedProp(Self,'DatabaseName') then + SetStrProp(Self,'DatabaseName',ADatabaseName); + if IsPublishedProp(Self,'UserName') then + SetStrProp(Self,'UserName',AUserName); + if IsPublishedProp(Self,'Password') then + SetStrProp(Self,'Password',APassword); +end; + procedure TCustomConnection.DoConnect; begin diff --git a/packages/fcl-db/src/base/db.pas b/packages/fcl-db/src/base/db.pas index bbb343c862..cd0cd505fc 100644 --- a/packages/fcl-db/src/base/db.pas +++ b/packages/fcl-db/src/base/db.pas @@ -1953,14 +1953,17 @@ type procedure SetBeforeConnect(const AValue: TNotifyEvent); procedure SetBeforeDisconnect(const AValue: TNotifyEvent); protected + procedure DoLoginPrompt; virtual; procedure DoConnect; virtual; procedure DoDisconnect; virtual; function GetConnected : boolean; virtual; Function GetDataset(Index : longint) : TDataset; virtual; Function GetDataSetCount : Longint; virtual; + procedure GetLoginParams(out ADatabaseName, AUserName, APassword: string); virtual; procedure InternalHandleException; virtual; procedure Loaded; override; procedure SetConnected (Value : boolean); virtual; + procedure SetLoginParams(const ADatabaseName, AUserName, APassword: string); virtual; property ForcedClose : Boolean read FForcedClose write FForcedClose; property StreamedConnected: Boolean read FStreamedConnected write FStreamedConnected; public