Recent

Author Topic: [SOLVED] Code clean up at TWinControl.Loaded  (Read 2042 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
[SOLVED] Code clean up at TWinControl.Loaded
« on: April 15, 2023, 10:45:33 am »
lcl/include/wincontrol.inc has procedure TWinControl.Loaded;
Code: Pascal  [Select][+][-]
  1. procedure TWinControl.Loaded;
  2. var
  3.   CachedText: string;
  4.   i: Integer;
  5.   AChild: TControl;
  6.   LoadedClientSize: TSize;
  7.   CurControl: TWinControl;
  8. begin
  9.   //DebugLn(['TWinControl.Loaded START ',DbgSName(Self),' cfWidthLoaded=',cfWidthLoaded in FControlFlags,' cfHeightLoaded=',cfHeightLoaded in FControlFlags,' ']);
  10.   DisableAutoSizing{$IFDEF DebugDisableAutoSizing}('TWinControl.Loaded'){$ENDIF};
  11.   try
  12.     //DebugLn(['TWinControl.Loaded ',DbgSName(Self),' cfWidthLoaded=',cfWidthLoaded in FControlFlags,' cfHeightLoaded=',cfHeightLoaded in FControlFlags,' ']);
  13.     if cfClientWidthLoaded in FControlFlags then
  14.       LoadedClientSize.cx:=FLoadedClientSize.cx
  15.     else begin
  16.       CurControl:=Self;
  17.       while CurControl<>nil do begin
  18.         LoadedClientSize.cx:=CurControl.ClientWidth;
  19.         if LoadedClientSize.cx>0 then break;
  20.         LoadedClientSize.cx:=CurControl.Width;
  21.         if LoadedClientSize.cx>0 then break;
  22.         CurControl:=CurControl.Parent;
  23.       end;
  24.     end;
  25.     if cfClientHeightLoaded in FControlFlags then
  26.       LoadedClientSize.cy:=FLoadedClientSize.cy
  27.     else begin
  28.       CurControl:=Self;
  29.       while CurControl<>nil do begin
  30.         LoadedClientSize.cy:=CurControl.ClientHeight;
  31.         if LoadedClientSize.cy>0 then break;
  32.         LoadedClientSize.cy:=CurControl.Height;
  33.         if LoadedClientSize.cy>0 then break;
  34.         CurControl:=CurControl.Parent;
  35.       end;
  36.     end;
  37.     for i:=0 to ControlCount-1 do begin
  38.       AChild:=Controls[i];
  39.       if AChild=nil then ;
  40.       AChild.FBaseParentClientSize:=LoadedClientSize;
  41.       //DebugLn(['TWinControl.Loaded Self=',DbgSName(Self),' AChild=',AChild,' AChild.FBaseParentClientSize=',dbgs(AChild.FBaseParentClientSize)]);
  42.     end;
  43.     if HandleAllocated then
  44.     begin
  45.       // Set cached caption
  46.       if GetCachedText(CachedText) then
  47.         WSSetText(CachedText);
  48.       InvalidatePreferredSize;
  49.  
  50.       if wcfColorChanged in FWinControlFlags then
  51.       begin
  52.         TWSWinControlClass(WidgetSetClass).SetColor(Self);
  53.         NotifyControls(CM_PARENTCOLORCHANGED);
  54.         Exclude(FWinControlFlags, wcfColorChanged);
  55.       end;
  56.       if wcfFontChanged in FWinControlFlags then
  57.       begin
  58.         TWSWinControlClass(WidgetSetClass).SetFont(Self,Font);
  59.         NotifyControls(CM_PARENTFONTCHANGED);
  60.         FWinControlFlags:=FWinControlFlags-[wcfFontChanged];
  61.       end;
  62.     end;
  63.  
  64.     inherited Loaded;
  65.  
  66.     FixupTabList;
  67.  
  68.   finally
  69.     //DebugLn(['TWinControl.Loaded enableautosizing ',DbgSName(Self),' ',dbgs(BoundsRect)]);
  70.     EnableAutoSizing{$IFDEF DebugDisableAutoSizing}('TWinControl.Loaded'){$ENDIF};
  71.     //DebugLn(['TWinControl.Loaded END ',DbgSName(Self),' ',dbgs(BoundsRect)]);
  72.   end;
  73. end;

The following patch removes the useless "if AChild=nil then ;" line. The line can be found inside the "for" loop.
Code: Pascal  [Select][+][-]
  1. diff --git a/lcl/include/wincontrol.inc b/lcl/include/wincontrol.inc
  2. index 37346973b5..7034017b77 100644
  3. --- a/lcl/include/wincontrol.inc
  4. +++ b/lcl/include/wincontrol.inc
  5. @@ -7784,7 +7784,6 @@ begin
  6.      end;
  7.      for i:=0 to ControlCount-1 do begin
  8.        AChild:=Controls[i];
  9. -      if AChild=nil then ;
  10.        AChild.FBaseParentClientSize:=LoadedClientSize;
  11.        //DebugLn(['TWinControl.Loaded Self=',DbgSName(Self),' AChild=',AChild,' AChild.FBaseParentClientSize=',dbgs(AChild.FBaseParentClientSize)]);
  12.      end;
« Last Edit: April 16, 2023, 12:56:14 pm by lagprogramming »

AlexTP

  • Hero Member
  • *****
  • Posts: 2480
    • UVviewsoft
Re: Code clean up at TWinControl.Loaded
« Reply #1 on: April 15, 2023, 10:50:53 am »

 

TinyPortal © 2005-2018