Browse Source

Parent form might be temporarily null if the control is part of frame

Source commit: 804159c3f50706394f2e5fe6dd7d5218febb72d3
Martin Prikryl 4 months ago
parent
commit
4d351c5583
1 changed files with 10 additions and 3 deletions
  1. 10 3
      source/windows/VCLCommon.cpp

+ 10 - 3
source/windows/VCLCommon.cpp

@@ -241,9 +241,16 @@ bool IsWindowColorControl(TControl * Control)
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 bool UseDarkModeForControl(TControl * Control)
 bool UseDarkModeForControl(TControl * Control)
 {
 {
-  return
-    WinConfiguration->UseDarkTheme() && // optimization
-    GetFormCustomizationComponent(GetParentForm(Control))->DarkMode;
+  bool Result = WinConfiguration->UseDarkTheme();
+  if (Result)
+  {
+    TCustomForm * ParentForm = GetParentForm(Control);
+    Result =
+      // Might be null temporarily if the control is part of frame
+      (ParentForm != NULL) &&
+      GetFormCustomizationComponent(ParentForm)->DarkMode;
+  }
+  return Result;
 }
 }
 //---------------------------------------------------------------------------
 //---------------------------------------------------------------------------
 void __fastcall EnableControl(TControl * Control, bool Enable)
 void __fastcall EnableControl(TControl * Control, bool Enable)