1

I've a simple app that uses this:

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes,
  Winapi.Windows, System.Variants, FMX.DialogService, TLHelp32,
  PlayForm, FMX.Platform, FMX.Media, FMX.Types, FMX.Controls, FMX.Forms,
  FMX.Graphics, FMX.Dialogs, FMX.Layouts, FMX.StdCtrls, System.IOUtils,
  FMX.Controls.Presentation, FMX.Colors, FMX.Edit, FMX.Objects, FMX.ListBox;

Then it is compiled and copied to another computer it produces this error:

Exception EAccessViolation in module Kvigraonica.exe at 0054B0F7.

Access violation at address 0094B0F7 in module 'Kvigraonica.exe'. Read of address 0000000C.

OnCreate event is like this:

procedure TfrmMain.FormCreate(Sender: TObject);
var
  i: Integer;
begin
  try
    TDialogService.PreferredMode := TDialogService.TPreferredMode.Platform;
    if tfile.Exists(System.SysUtils.GetCurrentDir + '\team-a.jpg') then
    begin
      imgTeamA.LoadFromFile(System.SysUtils.GetCurrentDir + '\team-a.jpg');
      imgTeamA.TagString := System.SysUtils.GetCurrentDir + '\team-a.jpg';
    end;
    if tfile.Exists(System.SysUtils.GetCurrentDir + '\team-a.png') then
    begin
      imgTeamA.LoadFromFile(System.SysUtils.GetCurrentDir + '\team-a.png');
      imgTeamA.TagString := System.SysUtils.GetCurrentDir + '\team-a.png';
    end;
    if tfile.Exists(System.SysUtils.GetCurrentDir + '\team-a.gif') then
    begin
      imgTeamA.LoadFromFile(System.SysUtils.GetCurrentDir + '\team-a.gif');
      imgTeamA.TagString := System.SysUtils.GetCurrentDir + '\team-a.gif';
    end;
    if tfile.Exists(System.SysUtils.GetCurrentDir + '\team-b.jpg') then
    begin
      imgTeamB.LoadFromFile(System.SysUtils.GetCurrentDir + '\team-b.jpg');
      imgTeamB.TagString := System.SysUtils.GetCurrentDir + '\team-b.jpg';
    end;
    if tfile.Exists(System.SysUtils.GetCurrentDir + '\team-b.png') then
    begin
      imgTeamB.LoadFromFile(System.SysUtils.GetCurrentDir + '\team-b.png');
      imgTeamB.TagString := System.SysUtils.GetCurrentDir + '\team-b.png';
    end;
    if tfile.Exists(System.SysUtils.GetCurrentDir + '\team-b.gif') then
    begin
      imgTeamB.LoadFromFile(System.SysUtils.GetCurrentDir + '\team-b.gif');
      imgTeamB.TagString := System.SysUtils.GetCurrentDir + '\team-b.gif';
    end;

  except on E: Exception do
    ShowMessage(e.Message);
  end;

end;

And I have a timer:

procedure TfrmMain.tmr1Timer(Sender: TObject);
begin
  try

    if (cbbTeamA.Items.Count = 1) then
    begin
      EnumWindows(@EnumWindowsProc, LPARAM(cbbTeamA));
    end
    else
    if (cbbTeamA.Items.Count = 0) or ((cbbTeamA.Selected <> nil) and (cbbTeamA.Selected.Index = 0)) then
    begin
      cbbTeamA.Clear;
      cbbTeamA.Items.AddObject('Izaberite VLC player Ekipu A', TObject(0));
      cbbTeamA.ItemIndex := 0;
      EnumWindows(@EnumWindowsProc, LPARAM(cbbTeamA));
    end;

    if (cbbTeamB.Items.Count = 1) then
    begin
      EnumWindows(@EnumWindowsProc, LPARAM(cbbTeamB));
    end
    else
    if (cbbTeamB.Items.Count = 0) or ((cbbTeamB.Selected <> nil) and (cbbTeamB.Selected.Index = 0))  then
    begin
      cbbTeamB.Clear;
      cbbTeamB.Items.AddObject('Izaberite VLC player za Ekipu B', TObject(0));
      cbbTeamB.ItemIndex := 0;
      EnumWindows(@EnumWindowsProc, LPARAM(cbbTeamB));
    end;
  except on E: Exception do
    ShowMessage(e.Message);
  end;
end;

I have more events and procedures, but here I put the ones that I think are the most important. Now, even if I comment out all events and procedures I still have the same error:

Exception EAccessViolation in module Kvigraonica.exe at 0054B0F7.

Access violation at address 0094B0F7 in module 'Kvigraonica.exe'. Read of address 0000000C.

Is there anything that FMX relies on so I have to install it on the target systems?

UPDATE

I've found that the problem is in a stylebook that I am using.

I've followed @StijnSanders advice (with @TomBrunberg help too) and I got this:

enter image description here

And this is when I lookup caller:

enter image description here

Dejan Dozet
  • 948
  • 10
  • 26
  • You simply have a bug in your code. You need to debug. – Andreas Rejbrand Sep 13 '20 at 17:44
  • "Is there anything that FMX relies on so I have to install it on the target systems?" No. And you could easily have found that out yourself by making a trivial "Hello, World!" FMX app and running it on the second machine! :) – Andreas Rejbrand Sep 13 '20 at 17:46
  • The bug really could be anywhere. But just a very, very, wild guess: do you use the right calling convention for `EnumWindowsProc`? – Andreas Rejbrand Sep 13 '20 at 17:52
  • @AndreasRejbrand the problem is in components that I am using, now I've started a new project and copy/paste only components and I have the same error again. Now I will delete one by one to see where the issue is, thanks Andreas :) – Dejan Dozet Sep 13 '20 at 18:03
  • That sounds like an excellent idea. – Andreas Rejbrand Sep 13 '20 at 18:05
  • @AndreasRejbrand in my project I have a stylebook is it possible that I need to copy that style with the app too? – Dejan Dozet Sep 13 '20 at 18:14
  • Sorry, no idea. I have never use FMX. – Andreas Rejbrand Sep 13 '20 at 18:16
  • No, Dejan you don't need to copy that stylebook. It is included in your exe as a resource. The *read of address 0000000C* is with 99% certainty due to attempting to access an object that is not created. If you follow the information in @StijnSanders answer you will know what object you try to access at that point. – Tom Brunberg Sep 13 '20 at 18:36
  • @TomBrunberg, this app is so simple that I don't have anything to debug, really. Now, I've removed the stylebook and it worked perfectly. I can't follow StijnSanders advice because it is too complicated for me. I've searched for 0094B0F7 and only that I am getting is 5E pop esi so what I can do with that? – Dejan Dozet Sep 13 '20 at 18:46
  • I'm confused that you did not ask Stijn for clarification! – Tom Brunberg Sep 13 '20 at 19:00
  • I didn't because at that moment I've deleted the stylebook and it worked, and I still have to wait for the client to decide which style he wants in the app (if any), but I will read more about debugging as he suggested later (note that the app works on my computer in any folder, but doesn't work on other computers) – Dejan Dozet Sep 13 '20 at 19:05
  • 1
    You need to preceed the address with a '$' since the address is in hex format. – Tom Brunberg Sep 13 '20 at 19:06
  • @TomBrunberg, thanks that did give me something, I've added screen to the question, can you check it, Tom, please? – Dejan Dozet Sep 13 '20 at 19:11
  • 1
    The code `TFormBorder.GetSupported` is in `FMX.Forms.pas`. You can now put a normal breakpoint on the first line of that function. When execution stops there, look in the `CallStack` window (top-left in IDE) how you arrived at this point. The call stack is btw upside down, execution order is from lower lines to upper ones. Good luck! – Tom Brunberg Sep 13 '20 at 19:22
  • Thanks @TomBrunberg for your support, it means a lot! – Dejan Dozet Sep 13 '20 at 19:39

1 Answers1

2

Press F7 which starts your project with the debugger, this will enable an option 'Go to Address' under the Search menu. Use it to look up address $0094B0F7. Optionally read more about debugging in the manual to find out how you can run the program up to the point where it fails.

Tom Brunberg
  • 20,312
  • 8
  • 37
  • 54
Stijn Sanders
  • 35,982
  • 11
  • 45
  • 67