Recent

Author Topic: [SOLVED] Access Violation error on toggle Unit View / Form View  (Read 6001 times)

perAspera

  • New Member
  • *
  • Posts: 11
[SOLVED] Access Violation error on toggle Unit View / Form View
« on: December 17, 2019, 04:30:57 pm »
Hello! I converted a large and old Delphi 5 project (30+ years of history including the TurboPascal era...) to Lazarus 2.0.6 on Win10. It worked surprisingly well, it compiles and (partially) runs already - that's great, many thanks  :D

However, there is a strange error I cannot explain or isolate: when I toogle between unit view and form view (the 5th button on the IDE) I get the error message:
Read error
In file
(filename...)
Access violation
Access violation

When I press Cancel, it appears again.
When I press Cancel again, I get:
Lazarus IDE v2.0.6 r62128 - opa
Access violation
Press OK to ignore and risk data corruption.
Press Abort to Kill the program.

(opa is the name of my program)
If I press Abort, then IDE kills itself.
If I press OK, I can continue, but I never see the Form. But I can compile and run my code and the Form looks as expected.
  • This happens only for the main menu form of my code, all other Forms can toggle well between Unit and Form View.
  • It also happens when I start Lazarus by clicking the .lpr or .lpi (I guess because the IDE tries to show the Form).
Probably it is something very obvious and stupid, but I'm a newbie, so any suggestion is appreciated  :)
« Last Edit: December 18, 2019, 10:32:33 am by perAspera »

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4675
  • I like bugs.
Re: Access Violation error on toggle Unit View / Form View
« Reply #1 on: December 17, 2019, 05:13:30 pm »
Do you have Sparta DockedFormEditor installed?
In that case see:
 https://bugs.freepascal.org/view.php?id=33772
and its related issues.
If you don't have it installed then we have a new bug and need more information (debugger backtrace or steps to reproduce).
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Access Violation error on toggle Unit View / Form View
« Reply #2 on: December 17, 2019, 07:19:16 pm »
Hi!

Have some files  belonging to the project set the readonly bit?

Winni

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: Access Violation error on toggle Unit View / Form View
« Reply #3 on: December 17, 2019, 07:25:06 pm »
Do the components on this form have properties which were not converted correctly to Lazarus?

Try to compile and run the project. Maybe an error is reported at runtime which is more descriptive, or you can use the debugger to isolate the issue.

perAspera

  • New Member
  • *
  • Posts: 11
Re: Access Violation error on toggle Unit View / Form View
« Reply #4 on: December 17, 2019, 07:34:34 pm »
Thanks for the replies!

  • I guess I don't have the Sparta DockedFormEditor because I cannot reproduce the error according to the instructions in the link.
  • I will check for the readonly bit (have to figure out, I'm a newbie...)
  • Indeed there are more errors at runtime but now I reduced the program to the absolute minimum (there is nothing to run anymore) and the bug is still there.
    [/i]
I removed everything not needed. I edited the *.lfm manually (because I cannot edit the form in the IDE) and I still see the bug.

Please find below the opa.lpr the main program, opamenu.pas and opamenu.lfm the form and opa.lpi. I guess this 4 files are sufficient to reproduce the problem? I also attached a pic how the form looks like. Perhaps somebody can see what went wrong?

As I said, despite the error the full program compiles and runs partially. Of course there are more bugs, and I would like to figure out if these are caused  by this one .

Please tell me or point me to a link how to generate the information which may be better suited for the developers to track the bug.

Many thanks!

opa.lpr

Code: Pascal  [Select][+][-]
  1. program opa;
  2.  
  3. //{$MODE Delphi}
  4.  
  5. uses
  6.   Forms, Interfaces,
  7.   opamenu in 'opamenu.pas' {Menu};
  8. //{$R *.res}
  9.  
  10. begin
  11.   Application.Initialize;
  12.   Application.Title := 'OPA';
  13.   Application.CreateForm(TMenu, Menu);
  14.  
  15.   Application.Run;
  16. end.                          
  17.  

opamenu.pas

Code: Pascal  [Select][+][-]
  1. unit opamenu;
  2.  
  3. interface
  4.  
  5. uses
  6.   LCLIntf, LCLType, SysUtils, Forms, Dialogs, Menus, StdCtrls, ComCtrls,  ExtCtrls,  Imglist,  ActnList;
  7.  
  8. type
  9.  
  10.  
  11.   { TMenu }
  12.  
  13.   TMenu = class(TForm)
  14.     MainMenu1: TMainMenu;
  15.     mi_file: TMenuItem;
  16.     fi_open: TMenuItem;
  17.     fi_save: TMenuItem;
  18.     fi_svas: TMenuItem;
  19.     fi_exit: TMenuItem;
  20.     N1: TMenuItem;
  21.     OpenDialog1: TOpenDialog;
  22.     SaveDialog1: TSaveDialog;
  23.     ed_text: TMenuItem;
  24.     errlog: TMemo;
  25.     LabFi0: TLabel;
  26.     LabFileName: TLabel;
  27.     LabSg0: TLabel;
  28.     comboSeg: TComboBox;
  29.     butlatsh: TButton;
  30.     fi_new: TMenuItem;
  31.     fi_last: TMenuItem;
  32.     fi_expo: TMenuItem;
  33.     mi_edit: TMenuItem;
  34.     mi_desi: TMenuItem;
  35.     mi_trac: TMenuItem;
  36.     mi_extr: TMenuItem;
  37.     tm_geo: TMenuItem;
  38.     tm_cur: TMenuItem;
  39.     tr_phsp: TMenuItem;
  40.     tr_dyna: TMenuItem;
  41.     tr_ttau: TMenuItem;
  42.     ds_opti: TMenuItem;
  43.     ds_sext: TMenuItem;
  44.     ed_oped: TMenuItem;
  45.     tm_test: TMenuItem;
  46.     panstatus: TPanel;
  47.     labstflag: TLabel;
  48.     labstelem: TLabel;
  49.     labstdata: TLabel;
  50.     ds_lgbo: TMenuItem;
  51.     ds_orbc: TMenuItem;
  52.     ds_injc: TMenuItem;
  53.     ds_dppo: TMenuItem;
  54.     ds_rfbu: TMenuItem;
  55.     ex_tracy2: TMenuItem;
  56.     ex_tracy3: TMenuItem;
  57.     ex_elegant: TMenuItem;
  58.     ex_madx: TMenuItem;
  59.     ex_bmad: TMenuItem;
  60.  
  61.   public
  62.     { Public-Deklarationen }
  63.   end;
  64.  
  65. var
  66.   Menu: TMenu;
  67.  
  68. implementation
  69.  
  70. {$R *.lfm}
  71.  
  72. end.
  73.  


opamenu.lfm

Code: XML  [Select][+][-]
  1. object Menu: TMenu
  2.   Left = 312
  3.   Top = 547
  4.   Width = 642
  5.   Height = 395
  6.   Caption = '  OPA 4.0 development version 51'
  7.   Color = clMenu
  8.   Font.Charset = DEFAULT_CHARSET
  9.   Font.Color = clWindowText
  10.   Font.Height = -16
  11.   Font.Name = 'MS Sans Serif'
  12.   Font.Style = [fsBold]
  13.   Menu = MainMenu1
  14.   PixelsPerInch = 96
  15.   object LabFi0: TLabel
  16.     Left = 64
  17.     Top = 8
  18.     Width = 73
  19.     Height = 16
  20.     Caption = 'active File'
  21.     Font.Charset = DEFAULT_CHARSET
  22.     Font.Color = clWindowText
  23.     Font.Height = -13
  24.     Font.Name = 'MS Sans Serif'
  25.     Font.Style = [fsBold]
  26.     ParentFont = False
  27.   end
  28.   object LabFileName: TLabel
  29.     Left = 152
  30.     Top = 8
  31.     Width = 27
  32.     Height = 16
  33.     Caption = 'New'
  34.     Font.Charset = ANSI_CHARSET
  35.     Font.Color = clNavy
  36.     Font.Height = -16
  37.     Font.Name = 'Courier'
  38.     Font.Style = []
  39.     ParentFont = False
  40.   end
  41.   object LabSg0: TLabel
  42.     Left = 32
  43.     Top = 32
  44.     Width = 108
  45.     Height = 16
  46.     Caption = 'active Segment'
  47.     Font.Charset = DEFAULT_CHARSET
  48.     Font.Color = clWindowText
  49.     Font.Height = -13
  50.     Font.Name = 'MS Sans Serif'
  51.     Font.Style = [fsBold]
  52.     ParentFont = False
  53.   end
  54.   object errlog: TMemo
  55.     Left = 152
  56.     Top = 64
  57.     Width = 473
  58.     Height = 273
  59.     Font.Charset = ANSI_CHARSET
  60.     Font.Color = clMaroon
  61.     Font.Height = -12
  62.     Font.Name = 'Courier New'
  63.     Font.Style = []
  64.     ParentFont = False
  65.     ScrollBars = ssVertical
  66.     TabOrder = 0
  67.   end
  68.   object comboSeg: TComboBox
  69.     Left = 152
  70.     Top = 32
  71.     Width = 153
  72.     Height = 24
  73.     Font.Charset = ANSI_CHARSET
  74.     Font.Color = clNavy
  75.     Font.Height = -16
  76.     Font.Name = 'Courier'
  77.     Font.Style = []
  78.     ItemHeight = 16
  79.     ParentFont = False
  80.     TabOrder = 1
  81.     Text = 'none'
  82.   end
  83.   object butlatsh: TButton
  84.     Left = 312
  85.     Top = 32
  86.     Width = 225
  87.     Height = 25
  88.     Caption = 'Show Lattice Expansion'
  89.     Font.Charset = DEFAULT_CHARSET
  90.     Font.Color = clWindowText
  91.     Font.Height = -13
  92.     Font.Name = 'MS Sans Serif'
  93.     Font.Style = []
  94.     ParentFont = False
  95.     TabOrder = 2
  96.   end
  97.   object panstatus: TPanel
  98.     Left = 8
  99.     Top = 64
  100.     Width = 137
  101.     Height = 273
  102.     BevelOuter = bvLowered
  103.     Color = clHighlightText
  104.     TabOrder = 3
  105.     object labstflag: TLabel
  106.       Left = 38
  107.       Top = 22
  108.       Width = 71
  109.       Height = 13
  110.       Caption = 'Status Flags'
  111.       Font.Charset = DEFAULT_CHARSET
  112.       Font.Color = clNavy
  113.       Font.Height = -11
  114.       Font.Name = 'MS Sans Serif'
  115.       Font.Style = [fsBold]
  116.       ParentFont = False
  117.     end
  118.     object labstelem: TLabel
  119.       Left = 38
  120.       Top = 46
  121.       Width = 98
  122.       Height = 13
  123.       Caption = 'Special Elements'
  124.       Font.Charset = DEFAULT_CHARSET
  125.       Font.Color = clNavy
  126.       Font.Height = -11
  127.       Font.Name = 'MS Sans Serif'
  128.       Font.Style = [fsBold]
  129.       ParentFont = False
  130.     end
  131.     object labstdata: TLabel
  132.       Left = 38
  133.       Top = 78
  134.       Width = 92
  135.       Height = 13
  136.       Caption = 'Calculated Data'
  137.       Font.Charset = DEFAULT_CHARSET
  138.       Font.Color = clNavy
  139.       Font.Height = -11
  140.       Font.Name = 'MS Sans Serif'
  141.       Font.Style = [fsBold]
  142.       ParentFont = False
  143.     end
  144.   end
  145.   object MainMenu1: TMainMenu
  146.     Left = 8
  147.     Top = 40
  148.     object mi_file: TMenuItem
  149.       Caption = 'File'
  150.       object fi_new: TMenuItem
  151.         Caption = 'New'
  152.       end
  153.       object fi_open: TMenuItem
  154.         Caption = 'Open...'
  155.       end
  156.       object fi_last: TMenuItem
  157.         Caption = 'Last Used'
  158.       end
  159.       object fi_save: TMenuItem
  160.         Caption = 'Save'
  161.       end
  162.       object fi_svas: TMenuItem
  163.         Caption = 'Save as...'
  164.       end
  165.       object fi_expo: TMenuItem
  166.         Caption = 'Export to .'
  167.         object ex_tracy2: TMenuItem
  168.           Caption = 'Tracy-2'
  169.         end
  170.         object ex_tracy3: TMenuItem
  171.           Caption = 'Tracy-3'
  172.         end
  173.         object ex_elegant: TMenuItem
  174.           Caption = 'Elegant'
  175.         end
  176.         object ex_madx: TMenuItem
  177.           Caption = 'MAD-X'
  178.         end
  179.         object ex_bmad: TMenuItem
  180.           Caption = 'BMAD'
  181.         end
  182.       end
  183.       object N1: TMenuItem
  184.         Caption = '-'
  185.       end
  186.       object fi_exit: TMenuItem
  187.         Caption = 'Exit'
  188.       end
  189.     end
  190.     object mi_edit: TMenuItem
  191.       Caption = 'Edit'
  192.       object ed_text: TMenuItem
  193.         Caption = 'Text Editor'
  194.       end
  195.       object ed_oped: TMenuItem
  196.         Caption = 'OPA Editor'
  197.       end
  198.     end
  199.     object mi_desi: TMenuItem
  200.       Caption = 'Design'
  201.       object ds_opti: TMenuItem
  202.         Caption = 'Linear Optics'
  203.         Enabled = False
  204.       end
  205.       object ds_dppo: TMenuItem
  206.         Caption = 'Off-momentum Optics'
  207.         Enabled = False
  208.       end
  209.       object ds_sext: TMenuItem
  210.         Caption = 'Non-linear Dynamics'
  211.         Enabled = False
  212.       end
  213.       object ds_lgbo: TMenuItem
  214.         Caption = 'LGB Optimizer'
  215.       end
  216.       object ds_orbc: TMenuItem
  217.         Caption = 'Orbit Correction'
  218.         Enabled = False
  219.       end
  220.       object ds_injc: TMenuItem
  221.         Caption = 'Injection Bumps'
  222.         Enabled = False
  223.       end
  224.       object ds_rfbu: TMenuItem
  225.         Caption = 'RF Bucket Viewer'
  226.       end
  227.     end
  228.     object mi_trac: TMenuItem
  229.       Caption = 'Tracking'
  230.       object tr_phsp: TMenuItem
  231.         Caption = 'Phase Space'
  232.         Enabled = False
  233.       end
  234.       object tr_dyna: TMenuItem
  235.         Caption = 'Dynamic Aperture'
  236.         Enabled = False
  237.       end
  238.       object tr_ttau: TMenuItem
  239.         Caption = 'Touschek Lifetime'
  240.         Enabled = False
  241.       end
  242.     end
  243.     object mi_extr: TMenuItem
  244.       Caption = 'Extra'
  245.       object tm_geo: TMenuItem
  246.         Caption = 'Geometry Layout'
  247.         Enabled = False
  248.       end
  249.       object tm_cur: TMenuItem
  250.         Caption = 'Magnet Currents '
  251.         Enabled = False
  252.       end
  253.       object tm_test: TMenuItem
  254.         Caption = '(Test)'
  255.       end
  256.     end
  257.   end
  258.   object OpenDialog1: TOpenDialog
  259.     Filter =
  260.       'OPA File (*.opa)|*.opa|TRACY Lattice File (*.lat)|*.lat|MAD Inpu' +
  261.       't File (*.mad)|*.mad'
  262.     Title = 'select lattice file'
  263.     Left = 8
  264.     Top = 24
  265.   end
  266.   object SaveDialog1: TSaveDialog
  267.     DefaultExt = 'opa'
  268.     Left = 8
  269.     Top = 8
  270.   end
  271. end
  272.  

opa.lpi

Code: XML  [Select][+][-]
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <CONFIG>
  3.   <ProjectOptions>
  4.     <Version Value="11"/>
  5.     <PathDelim Value="\"/>
  6.     <General>
  7.       <Flags>
  8.         <MainUnitHasUsesSectionForAllUnits Value="False"/>
  9.         <MainUnitHasCreateFormStatements Value="False"/>
  10.         <MainUnitHasTitleStatement Value="False"/>
  11.         <MainUnitHasScaledStatement Value="False"/>
  12.       </Flags>
  13.       <SessionStorage Value="InProjectDir"/>
  14.       <MainUnit Value="0"/>
  15.       <Title Value="opa"/>
  16.       <UseAppBundle Value="False"/>
  17.       <ResourceType Value="res"/>
  18.     </General>
  19.     <BuildModes Count="1">
  20.       <Item1 Name="Default" Default="True"/>
  21.     </BuildModes>
  22.     <PublishOptions>
  23.       <Version Value="2"/>
  24.       <UseFileFilters Value="True"/>
  25.     </PublishOptions>
  26.     <RunParams>
  27.       <FormatVersion Value="2"/>
  28.       <Modes Count="0"/>
  29.     </RunParams>
  30.     <RequiredPackages Count="2">
  31.       <Item1>
  32.         <PackageName Value="Printer4Lazarus"/>
  33.       </Item1>
  34.       <Item2>
  35.         <PackageName Value="LCL"/>
  36.       </Item2>
  37.     </RequiredPackages>
  38.     <Units Count="2">
  39.       <Unit0>
  40.         <Filename Value="opa.lpr"/>
  41.         <IsPartOfProject Value="True"/>
  42.       </Unit0>
  43.       <Unit1>
  44.         <Filename Value="opamenu.pas"/>
  45.         <IsPartOfProject Value="True"/>
  46.         <HasResources Value="True"/>
  47.       </Unit1>
  48.     </Units>
  49.   </ProjectOptions>
  50.   <CompilerOptions>
  51.     <Version Value="11"/>
  52.     <PathDelim Value="\"/>
  53.     <SearchPaths>
  54.       <IncludeFiles Value="..\..\com"/>
  55.       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
  56.     </SearchPaths>
  57.     <Parsing>
  58.       <SyntaxOptions>
  59.         <SyntaxMode Value="delphi"/>
  60.       </SyntaxOptions>
  61.     </Parsing>
  62.     <Linking>
  63.       <Options>
  64.         <Win32>
  65.           <GraphicApplication Value="True"/>
  66.         </Win32>
  67.       </Options>
  68.     </Linking>
  69.   </CompilerOptions>
  70.   <Debugging>
  71.     <Exceptions Count="4">
  72.       <Item1>
  73.         <Name Value="EAbort"/>
  74.       </Item1>
  75.       <Item2>
  76.         <Name Value="ECodetoolError"/>
  77.       </Item2>
  78.       <Item3>
  79.         <Name Value="EFOpenError"/>
  80.       </Item3>
  81.       <Item4>
  82.         <Name Value="EStringListError"/>
  83.       </Item4>
  84.     </Exceptions>
  85.   </Debugging>
  86. </CONFIG>
  87.  

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Access Violation error on toggle Unit View / Form View
« Reply #5 on: December 17, 2019, 07:52:37 pm »
Hi!

If there are files which can't be changed by the IDE there is a big chance that readonly is set to one ore more files. Instructions here:

https://smallbusiness.chron.com/change-read-only-files-folders-54559.html

Winni

lucamar

  • Hero Member
  • *****
  • Posts: 4217
Re: Access Violation error on toggle Unit View / Form View
« Reply #6 on: December 17, 2019, 08:09:49 pm »
It may not have anything to do with your problem but note that calling your form Menu (hence its class TMenu) is exceedingly bad. There is already a class TMenu (ancestor of all menus) in the LCL and calling your form that may lead to unexpected and difficult to debug bugs.

If I may be so bold, I think you should call your form something else like, say, MenuFrm (class TMenuFrm).

In general, try to avoid "reusing" class names which already exist unless you know exactly what you're doing (for example, creating an interposed class)
« Last Edit: December 17, 2019, 08:12:19 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus/FPC 2.0.8/3.0.4 & 2.0.12/3.2.0 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4675
  • I like bugs.
Re: Access Violation error on toggle Unit View / Form View
« Reply #7 on: December 17, 2019, 11:14:08 pm »
If there are files which can't be changed by the IDE there is a big chance that readonly is set to one ore more files. Instructions here:
Please read his first post. He switched between form/unit view. It is not related to readonly files. Besides readonly files do not crash the IDE.

@perAspera, after fixing the obvious potential problem pointed by lucamar, please compress your example project sources into one zip file (or similar) and upload it here. It will be easier to extract and test. No binaries, just sources.
Hint, there is also a nice Project -> Publish Project ... feature.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: Access Violation error on toggle Unit View / Form View
« Reply #8 on: December 17, 2019, 11:56:08 pm »
I pasted your code into a new project/form and confirm the crash. lucamar is right, naming the form a TMenu was a bad idea, it probably causes all the trouble. Did Delphi accept this?

I opened the pas file in an external editor and changed the form type to TMenuForm and its instance to MenuForm:
Code: Pascal  [Select][+][-]
  1. type
  2.   TMenuForm = class(TForm)  
  3.   ...
  4.   end;
  5.  
  6. var
  7.   MenuForm: TMenuForm;
(Of course in your real form, you must also change the class names at each method implementation, too).

Next is the lfm file - the first line should be
Code: Pascal  [Select][+][-]
  1. object MenuForm: TMenuForm  

And the lpr file. Change the Application.CreateForm to
Code: Pascal  [Select][+][-]
  1.   Application.CreateForm(TMenuForm, MenuForm);
I am not quite sure if I remember correctly, but I think after these changes I could load the form into Lazarus, but there was still a SIGFPE runtime error. I am not sure what finally solved it, but I think it was the double-click on the TMainMenu component which opened the menu editor and forced the menu structure to be rewritten. Now the code compiles and runs.

A wish for the next post: You would help us if you'd avoid pasting full code into the post directly; it would be much better we had the source files directly (this would have allowed me to download the original project again, do the changes and find out how EXACTLY is solved the issue; but I did not want to repeat the hassle of pasting the code into empty Lazarus files again...). In order to upload a project, pack the *.pas, *.lfm, *.lpi and *.lpr files (plus any data files needed) into a common zip file. Below the forum editor box  you find "Attachments and other options" where you can upload the zip file. Do not include compiler-generated files, mainly the exe, in the zip, otherwise the file might exceed the forum upload limit for 250kB.
« Last Edit: December 18, 2019, 12:03:39 am by wp »

perAspera

  • New Member
  • *
  • Posts: 11
Re: Access Violation error on toggle Unit View / Form View
« Reply #9 on: December 18, 2019, 10:22:56 am »
Thank you so much for your kind help!
I'm impressed how you engaged yourself in my problem and, special thanks to @wp that you solved it for me. I implemented the changes and now everything is fine - I even didn't get a runtime error, perhaps in the shortened version I posted something was missing.

It seems Delphi, at least the old version 5, is more relaxed with regard to special words. I will pay attention to that.

And thanks for the hint on how to post code.

 

TinyPortal © 2005-2018