Delphi 10.2.3 Access Violations


I have been experiencing Access Violation issues.
I'm using the latest Delphi version and the latest TMS FMX sources.

The problem seems to be in the "global variable" TTMSFMXStyles.FScene.
This variable will be set by TTMSFMXStyles.SetActiveScene.
Most of the time it's no problem.

But if a form closes the FScene variable may point to the just-closed form.
The function TTMSFMXStyles.GetStyleSceneObject gets called, but the FScene value still is still referencing the close form.

class function TTMSFMXStyles.GetStyleSceneObject: TFmxObject;
  frm: TCommonCustomForm;
  if Assigned(TTMSFMXStyles.FScene) then // <-- NOT NIL
    if Assigned(TTMSFMXStyles.FScene.StyleBook) then // <-- EXCEPTION because FScene is invalid
      Result := TTMSFMXStyles.FScene.StyleBook.Style
      Result := TStyleManager.ActiveStyleForScene(TTMSFMXStyles.FScene);
    frm := Screen.ActiveForm;
    if not Assigned(frm) then
      frm := Application.MainForm;

    if Assigned(frm) and Assigned(frm.StyleBook) then
      Result := frm.StyleBook.Style
      Result := TStyleManager.ActiveStyle(nil);

My workaround for now is:
class procedure TTMSFMXStyles.SetActiveScene(AScene: IScene);
  FScene := nil; //JJ FScene := AScene;

This may have a performance penalty, but it's not crashing our application anymore.
In our case the application crashes were always related to the TTMSFMXPageControl controls.

Maybe in the new version of Delphi the order of some "style" calls has changed.

Hope this helps.

can you point out exactly in which circumstances this exception occurs? Do you have a sample that demonstrates this?

Hi Pieter,

No unfortunately not.
I tried to make a small demo program to mimic this, but that didn't create AV's.
So it's not just the PageControls, it's PageControls in combination with "something".
Don't know yet what.

I am using Delphi Berlin. I am using TMS FMX UI Pack of 27 March 2018 which is the current version.

I get a similar Access Violation. It is to do with Styles

I only use the TTMSFMXPageControl in two (2) places.

In the code where the PageControl is used often I get the problem.

If I can I will post the diagnostic trace.

  Peter Evans

This is the second Access Violation I get

main thread

Unit               Line  Rel.  Function

System             36349 +10   @IntfClear
FMX.TMSStyles                  TTMSFMXStyles.Destroy@
System             22152 +17   FinalizeUnits
madExcept                      InterceptFinalizeUnits
madExcept                      InterceptHaltFinalizeUnits
System             23544 +87   @Halt0
MyClient             182 +8    initialization 

This is where the first error occurs

main thread

Unit                   Line     Rel.   Function

FMX.TMSStyles           150    +3     TTMSFMXStyles.GetStyleSceneObject
FMX.TMSStyles          1269    +5     TTMSFMXStyles.StyleServicesEnabled
FMX.TMSStyles           780    +2     TTMSFMXStyles.GetStyleBackgroundFillColor
FMX.TMSCustomControl    700    +2     TTMSFMXCustomControlBaseCommon.SetDefaultGraphicColors
FMX.TMSCustomControl    830    +7     TTMSFMXCustomControlBaseCommon.Create
FMX.TMSCustomControl   1185    +1     TTMSFMXCustomControlBase.Create
FMX.TMSCustomControl   1748    +1     TTMSFMXCustomControl.Create
FMX.TMSTabSet          1494    +1     TTMSFMXCustomTabSet.Create
FMX/TMSPageControl      343    +1     TTMSFMXCustomPageControl.Create
FMX/TMSPageControl     1098    +1     TTMSFMXPageControl.Create


I have just sent to support a demo application that reproduces this problem.
  Peter Evans

I have been told that there will be a fix to this issue.
Presumably after the just released version

Hi This issue should be fixed. It didn?t make it to the version history as this was a last minute change

Tank you for that response. I have just downloaded and will be testing it soon.

I am pleased that one of my suggestions to fix the problem was used.

I have done some preliminary testing on Windows and three different Android devices. So far the fix appears to be working.

Thank you.

Thank you for the confirmation!