From: <jfu...@us...> - 2007-07-29 18:00:29
|
Revision: 11424 http://jvcl.svn.sourceforge.net/jvcl/?rev=11424&view=rev Author: jfudickar Date: 2007-07-29 11:00:26 -0700 (Sun, 29 Jul 2007) Log Message: ----------- Improved Thread Handling for Dataset Components Modified Paths: -------------- trunk/jvcl/run/JvBaseDBThreadedDataset.pas trunk/jvcl/run/JvThread.pas Modified: trunk/jvcl/run/JvBaseDBThreadedDataset.pas =================================================================== --- trunk/jvcl/run/JvBaseDBThreadedDataset.pas 2007-07-19 06:59:25 UTC (rev 11423) +++ trunk/jvcl/run/JvBaseDBThreadedDataset.pas 2007-07-29 18:00:26 UTC (rev 11424) @@ -1400,6 +1400,7 @@ procedure TJvBaseDatasetThreadHandler.ThreadExecute(Sender: TObject; Params: Pointer); begin OperationWasHandledInThread := True; + ExecuteThread.ThreadDialogAllowed := True; try SetError('', nil); ExecuteThreadSynchronize(SynchBeforeThreadExecution); @@ -1416,6 +1417,7 @@ on E: Exception do begin SetError(E.Message, E); + ExecuteThread.ThreadDialogAllowed := False; if ThreadOptions.ShowExceptionMessage then begin FSynchMessageDlgMsg := E.Message; @@ -1426,6 +1428,7 @@ ExecuteThreadSynchronize(SynchAfterThreadExecution); finally IntCurrentOperation := tdoNothing; + ExecuteThread.ThreadDialogAllowed := False; end; end; Modified: trunk/jvcl/run/JvThread.pas =================================================================== --- trunk/jvcl/run/JvThread.pas 2007-07-19 06:59:25 UTC (rev 11423) +++ trunk/jvcl/run/JvThread.pas 2007-07-29 18:00:26 UTC (rev 11424) @@ -79,6 +79,7 @@ FConnectedDataObject: TObject; FConnectedThread: TJvThread; FDialogOptions: TJvCustomThreadDialogOptions; + FFormIsShown: Boolean; FInternalShowDelay: Integer; FInternalTimer: TTimer; FInternalTimerInterval: Integer; @@ -98,6 +99,7 @@ procedure Notification(AComponent: TComponent; Operation: TOperation); override; procedure TransferDialogOptions; virtual; procedure UpdateFormContents; virtual; + property FormIsShown: Boolean read FFormIsShown default False; property OnPressCancel: TNotifyEvent read FOnPressCancel write FOnPressCancel; public constructor CreateNew(AOwner: TComponent; Dummy: Integer = 0); override; @@ -194,6 +196,7 @@ FOnShowMessageDlgEvent: TJvThreadShowMessageDlgEvent; FPriority: TThreadPriority; FThreadDialog: TJvCustomThreadDialog; + FThreadDialogAllowed: Boolean; FThreadDialogForm: TJvCustomThreadDialogForm; procedure DoBegin; procedure DoTerminate(Sender: TObject); @@ -230,6 +233,9 @@ property Terminated: Boolean read GetTerminated; // in context of thread in list - for itself; in others - for all threads in list property ReturnValue: Integer read GetReturnValue write SetReturnValue; // in context of thread in list - set return value (slower) property OneThreadIsRunning: Boolean read GetOneThreadIsRunning; + //1 Property to allow/disallow the thread dialog form + property ThreadDialogAllowed: Boolean read FThreadDialogAllowed write + FThreadDialogAllowed default True; property ThreadDialogForm: TJvCustomThreadDialogForm read FThreadDialogForm; (* function GetPriority(Thread: THandle): TThreadPriority; @@ -345,7 +351,8 @@ //=== { TJvCustomThreadDialogForm } ========================================== -constructor TJvCustomThreadDialogForm.CreateNew(AOwner: TComponent; Dummy: Integer = 0); +constructor TJvCustomThreadDialogForm.CreateNew(AOwner: TComponent; Dummy: + Integer = 0); begin inherited CreateNew(AOwner, Dummy); FInternalTimerInterval := 250; @@ -360,6 +367,7 @@ FInternalTimer.OnTimer := InternalTimer; FInternalTimer.Interval := FInternalTimerInterval; FInternalShowDelay := 0; + FFormIsShown := False; end; constructor TJvCustomThreadDialogForm.CreateNewFormStyle(AOwner: TJvThread; FormStyle: TFormStyle; @@ -419,30 +427,37 @@ else // connected component present if ConnectedThread.Terminated then begin - Hide; - Close; + if FormIsShown then + begin + Hide; + Close; + end; end else // not terminated begin if FInternalShowDelay > 0 then // Dialog is not shown until yet - begin - FInternalShowDelay := FInternalShowDelay - FInternalTimerInterval; - if FInternalShowDelay <= 0 then + FInternalShowDelay := FInternalShowDelay - FInternalTimerInterval + else + if not FormIsShown then begin - if DialogOptions.ShowModal then - ShowModal - else - Show; - end; - end - else - UpdateFormContents; + if ConnectedThread.ThreadDialogAllowed then + begin + if DialogOptions.ShowModal then + ShowModal + else + Show; + end; + end + else + if ConnectedThread.ThreadDialogAllowed then + UpdateFormContents; end; // not terminated end; // if not (csDestroying in ComponentState) then end; procedure TJvCustomThreadDialogForm.ReplaceFormClose(Sender: TObject; var Action: TCloseAction); begin + FFormIsShown := False; FInternalTimer.OnTimer := nil; FInternalTimer.Enabled := False; Action := caFree; @@ -463,8 +478,9 @@ procedure TJvCustomThreadDialogForm.ReplaceFormShow(Sender: TObject); begin + FFormIsShown := True; InitializeFormContents; - InternalTimer(nil); + UpdateFormContents; FInternalTimer.Enabled := True; end; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |