LCL: debugging

git-svn-id: trunk@26501 -
This commit is contained in:
mattias 2010-07-07 12:18:37 +00:00
parent 81f8e13285
commit b37ad612d8

View File

@ -451,13 +451,7 @@ end;
procedure TCustomForm.WMShowWindow(var message: TLMShowWindow); procedure TCustomForm.WMShowWindow(var message: TLMShowWindow);
begin begin
{$IFDEF VerboseFocus} {$IFDEF VerboseFocus}
DbgOut('TCustomForm.WMShowWindow A ',Name,':'+ClassName+' fsShowing='+dbgs(fsShowing in FFormState)+' Msg.Show='+dbgs(Message.Show)); Debugln(['TCustomForm.WMShowWindow A ',DbgSName(Self),' fsShowing=',fsShowing in FFormState,' Msg.Show=',Message.Show,' FActiveControl=',DbgSName(FActiveControl)]);
if FActiveControl<>nil then begin
DbgOut(' FActiveControl=',FActiveControl.Name,':',FActiveControl.ClassName,' HandleAllocated=',dbgs(FActiveControl.HandleAllocated));
end else begin
DbgOut(' FActiveControl=nil');
end;
DebugLn('');
{$ENDIF} {$ENDIF}
if (fsShowing in FFormState) then exit; if (fsShowing in FFormState) then exit;
Include(FFormState, fsShowing); Include(FFormState, fsShowing);
@ -483,7 +477,7 @@ end;
procedure TCustomForm.WMActivate(var Message : TLMActivate); procedure TCustomForm.WMActivate(var Message : TLMActivate);
begin begin
{$IFDEF VerboseFocus} {$IFDEF VerboseFocus}
DebugLn('TCustomForm.WMActivate A ',Name,':',ClassName,' Msg.Active=',dbgs(Message.Active)); DebugLn('TCustomForm.WMActivate A ',DbgSName(Self),' Msg.Active=',dbgs(Message.Active));
{$ENDIF} {$ENDIF}
if (FormStyle <> fsMDIForm) or (csDesigning in ComponentState) then if (FormStyle <> fsMDIForm) or (csDesigning in ComponentState) then
SetActive(Message.Active); SetActive(Message.Active);
@ -1708,48 +1702,38 @@ end;
------------------------------------------------------------------------------} ------------------------------------------------------------------------------}
procedure TCustomForm.SetActiveControl(AWinControl: TWinControl); procedure TCustomForm.SetActiveControl(AWinControl: TWinControl);
begin begin
if FActiveControl <> AWinControl then if FActiveControl = AWinControl then exit;
if (AWinControl<>nil) and IsVisible then
begin begin
if (AWinControl<>nil) and IsVisible then // this form can focus => do some sanity checks and raise an exception to
// to help programmers to understand why a control is not focused
if (AWinControl = Self) or
(GetParentForm(AWinControl) <> Self) or
not ((csLoading in ComponentState) or AWinControl.CanFocus) then
begin begin
// this form can focus => do some sanity checks and raise an exception to DebugLn('TCustomForm.SetActiveControl ',DbgSName(Self),' AWinControl=',DbgSName(AWinControl),' GetParentForm(AWinControl)=',
// to help programmers to understand why a control is not focused DbgSName(GetParentForm(AWinControl)),' csLoading=',dbgs(csLoading in ComponentState),' AWinControl.CanFocus=',
if (AWinControl = Self) or dbgs((AWinControl<>nil) and AWinControl.CanFocus),' IsControlVisible=',dbgs((AWinControl<>nil) and AWinControl.IsControlVisible),
(GetParentForm(AWinControl) <> Self) or ' Enabled=',dbgs((AWinControl<>nil) and AWinControl.Enabled));
not ((csLoading in ComponentState) or AWinControl.CanFocus) then {$IFDEF VerboseFocus}
begin RaiseGDBException(SCannotFocus);
DebugLn('TCustomForm.SetActiveControl ',DbgSName(Self),' AWinControl=',DbgSName(AWinControl),' GetParentForm(AWinControl)=', {$ELSE}
DbgSName(GetParentForm(AWinControl)),' csLoading=',dbgs(csLoading in ComponentState),' AWinControl.CanFocus=', raise EInvalidOperation.Create(SCannotFocus);
dbgs((AWinControl<>nil) and AWinControl.CanFocus),' IsControlVisible=',dbgs((AWinControl<>nil) and AWinControl.IsControlVisible), {$ENDIF}
' Enabled=',dbgs((AWinControl<>nil) and AWinControl.Enabled));
{$IFDEF VerboseFocus}
RaiseGDBException(SCannotFocus);
{$ELSE}
raise EInvalidOperation.Create(SCannotFocus);
{$ENDIF}
end;
end; end;
end;
{$IFDEF VerboseFocus} {$IFDEF VerboseFocus}
DbgOut('TCustomForm.SetActiveControl ',Name,':',ClassName,' FActive=',DbgS(FActive)); Debugln(['TCustomForm.SetActiveControl ',DbgSName(Self),' FActive=',DbgS(FActive),' OldActiveControl=',DbgSName(FActiveControl),' NewActiveControl=',DbgSName(AWinControl)]);
if FActiveControl<>nil then {$ENDIF}
DebugLn(' OldActiveControl=',DbgSName(FActiveControl))
else
DebugLn(' OldActiveControl=nil');
if AWinControl<>nil then
DebugLn(' NewActiveControl=',DbgSName(AWinControl))
else
DebugLn(' NewActiveControl=nil');
{$ENDIF}
FActiveControl := AWinControl; FActiveControl := AWinControl;
if FActiveControl<>nil then FreeNotification(FActiveControl); if FActiveControl<>nil then FreeNotification(FActiveControl);
if ([csLoading, csDestroying] * ComponentState = []) then if ([csLoading, csDestroying] * ComponentState = []) then
begin begin
if FActive then if FActive then
SetWindowFocus; SetWindowFocus;
ActiveChanged; ActiveChanged;
end;
end; end;
end; end;
@ -2261,11 +2245,20 @@ begin
if (FDesigner = nil) and (not (csLoading in ComponentState)) then if (FDesigner = nil) and (not (csLoading in ComponentState)) then
begin begin
if Control <> Self then begin if Control <> Self then begin
{$IFDEF VerboseFocus}
if FActiveControl<>Control then
debugln(['TCustomForm.SetFocusedControl ',DbgSName(Self),' OldActiveControl=',DbgSName(FActiveControl),' New=',DbgSName(Control)]);
{$ENDIF}
FActiveControl := Control; FActiveControl := Control;
if FActiveControl<>nil then if FActiveControl<>nil then
FreeNotification(FActiveControl); FreeNotification(FActiveControl);
end else end else begin
{$IFDEF VerboseFocus}
if FActiveControl<>nil then
debugln(['TCustomForm.SetFocusedControl ',DbgSName(Self),' OldActiveControl=',DbgSName(FActiveControl),' New=',DbgSName(Control)]);
{$ENDIF}
FActiveControl := nil; FActiveControl := nil;
end;
end; end;
// update Screen object // update Screen object
@ -2299,6 +2292,10 @@ begin
while CurControl <> nil do while CurControl <> nil do
begin begin
if CurControl is TCustomForm then begin if CurControl is TCustomForm then begin
{$IFDEF VerboseFocus}
if TCustomForm(CurControl).FActiveControl<>Control then
debugln(['TCustomForm.SetFocusedControl Self=',DbgSName(Self),' SomeParent=',DbgSName(CurControl),' OldActiveControl=',DbgSName(TCustomForm(CurControl).FActiveControl),' New=',DbgSName(Control)]);
{$ENDIF}
TCustomForm(CurControl).FActiveControl := Control; TCustomForm(CurControl).FActiveControl := Control;
TCustomForm(CurControl).FreeNotification(Control); TCustomForm(CurControl).FreeNotification(Control);
end; end;
@ -2478,9 +2475,12 @@ begin
end; end;
if (ActiveControl <> nil) and (Parent=nil) then if (ActiveControl <> nil) and (Parent=nil) then
begin begin
// check if loaded ActiveControl can be focused
// and if yes, call SetActiveControl to invoke handlers
Control := ActiveControl; Control := ActiveControl;
{$IFDEF VerboseFocus} {$IFDEF VerboseFocus}
Debugln('TCustomForm.Loaded Self=',DbgSName(Self),' FActiveControl=',DbgSName(FActiveControl)); if FActiveControl<>nil then
Debugln('TCustomForm.Loaded Self=',DbgSName(Self),' FActiveControl=',DbgSName(FActiveControl));
{$ENDIF} {$ENDIF}
FActiveControl := nil; FActiveControl := nil;
if Control.CanFocus then SetActiveControl(Control); if Control.CanFocus then SetActiveControl(Control);