0
votes

I have usual code to show modal form. But sometimes happens strange bug captured on picture below. (about once per 10 attempt to show that form) It happens only with custom FireMonkey style "Diamond.style".

enter image description here

My code for setting style (in DPR file):

var
  lib: THandle;
  RS: TResourceStream;
begin
  Application.Initialize;
  lib := LoadLibrary('res.dll');
  RS := TResourceStream.Create(lib, 'DIAMOND', RT_RCDATA);
  try
    TStyleManager.SetStyle(TStyleManager.LoadFromStream(RS));
  finally
    RS.Free;
  end;
  ...

My code for showing form:

  formProjectName := TformProjectName.Create(Self);
  try
    formProjectName.ShowModal;
    ...
  finally
    formProjectName.Free;
  end;
1
Much easier to use a resource stream. And you would do better to load the module as a res only module.David Heffernan
The PChar cast is also redundant here. A literal passes as a PChar. And your try finally is a little loose. Always have the the try immediately following the acquisition.David Heffernan
Yeah, you're right, I forgot that in Delphi exists TResourceStream. I'll update the code in post. But this isn't solution to my problem.core4096
I know. Sorry. Was just offering a little help on a side issue.David Heffernan
No, thank you for answer. I learned something new!core4096

1 Answers

1
votes

I'm not sure if this is helpful.... but this is the code from my "OnChange" event of the TComboBox I use with the style names loaded:

var
  resname :string;
  style:TFMXObject;

begin
  // set style to default...
  if TOSVersion.Platform = pfAndroid then
      resname := 'And';
  if TOSVersion.Platform = pfWindows then
      resname := 'Win';

  if cbStyles.ItemIndex > 0 then
  Begin
    //(Add prefix to style name from TComboBox)
    resname := resname + cbStyles.Selected.Text;
    Style := TStyleStreaming.LoadFromResource(HInstance,resname, RT_RCDATA) ;
    if style <> nil then
      TStyleManager.SetStyle(style);

  End;
   // The below line causes hangs in some future version (just guessing:-) ) -- XE8 was OK.
  //else TStyleManager.SetStyle(nil);

I load the TComboBox STyles like this typically...

 CBStyles.Items.Clear;

    CBStyles.Items.Add('Default');

    if TOSVersion.Platform = pfAndroid  then
    begin
       CBStyles.Items.Add('CoralCrystal');
       CBStyles.Items.Add('CoralDark');
       CBStyles.Items.Add('Diamond');
       CBStyles.Items.Add('EmeraldCrystal');

       CBStyles.Items.Add('EmeraldDark');
       CBStyles.Items.Add('Jet');
       CBStyles.Items.Add('Radiant');

       CBStyles.Items.Add('Sterling');
       CBStyles.Items.Add('Vapor');

    end;

Maybe that will help...