Jump to content
FabDev

AV with SetStyleFromFile at runtime

Recommended Posts

Hello,

 

I try to da a Style tester on Android, IOS, Window and MacOs. It's a form with most of visual components and a style selector.

For that I use :

FMX.Styles.TStyleManager.SetStyleFromFile(SytleFileName);

It's work but I have random access violation

Exception 'first chance' at $00F0CD3A. Exception class $C0000005 with a message 'access violation at 0x00f0cd3a: read of address 0x0907728b'. Processus StyleTest.exe (10884)

in FMX.Objects in all platform :

 

function TText.GetColor: TAlphaColor;
begin
  Result := FTextSettings.FontColor;
end;

 

I have tried something like :

try
 BeginUpdate;
 FMX.Styles.TStyleManager.SetStyleFromFile(SytleFileName);
finally
 EndUpdate;
end;

Or using Thread :

  TThread.Synchronize(
       nil,
        procedure
        begin
                    try
                      try

                      BeginUpdate;
                      
                      ok:=FMX.Styles.TStyleManager.SetStyleFromFile(StyleFilename);
                      finally
                        endupdate;
                      end;
                    except
                     ok:=false;
                    end;
                    
        end
        );

 

But it's doesn't fix the problem.

 

Or does it a bad idea to change style at runtime ?

 

 

Share this post


Link to post
6 minutes ago, FabDev said:

Or does it a bad idea to change style at runtime ?

 

It's not. There were Embarcadero webinars on this topic.

Share this post


Link to post

 

I confirm that SetStyleFromFile can (must ?) be used in Application.Initialize) or in the initialization section of one of the form unit :

https://docwiki.embarcadero.com/Libraries/Alexandria/en/FMX.Styles.TStyleManager.SetStyleFromFile

 

But I have found another solution which doesn't seems to give AV on IOS/Win32/Android :

             StyleBook:=nil;
             StyleBook1.Clear;
             StyleBook1.LoadFromFile(StyleFileName);
             StyleBook:= StyleBook1;

 

 

Or the unique way, I have tested, it's to only use it in Application.Initialize (or Initalization section) ?

Edited by FabDev

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×