I don't think this is right - for my case. The shortened code is nearly exact for this issue. But the error happens when I start the program and before any Form is shown. So there isn't any access to the variable slFLartikel.which raises the question where is your application raising the exception? What is the debugger saying?
which raises the question where is your application raising the exception? What is the debugger saying?When I change the code so that the problematic line is shown in Unit1 and removed from Unit2, there is no error shown.
So when you comment out the code in tform2.myproc3 everything seems to work as expected? Can you create the smallest compilable complete application possible, zip it and post it here? As for the message Type TSTRINGLIST has no component named COUNT is the inability of GDB to correctly recognize pascal properties, it has nothing to do with your code.which raises the question where is your application raising the exception? What is the debugger saying?When I change the code so that the problematic line is shown in Unit1 and removed from Unit2, there is no error shown.
But when I set a breakpoint at the problematic line, the debugger shows "Error: Type TSTRINGLIST has no component named COUNT".
unit Unit1; {$mode objfpc}{$H+} interface ... var slFLartikel: TStringlist; implementation uses Unit3; {$R *.lfm} { TForm1 } procedure TForm1.myproc1(); begin slFLartikel := TStringlist.Create; myproc2; //Form2.show; For i := 0 to slFLartikel.Count-1 do showmessage(slFLartikel[i]); slFLartikel.free; end; procedure TForm1.myproc2 begin while ... do slFLartikel.Add(someString); end; ### unit Unit2; {$mode objfpc}{$H+} interface ... implementation uses Unit3; {$R *.lfm} { TForm2 } procedure TForm2.myproc3(); begin // For i := 0 to slFLartikel.Count-1 do showmessage(slFLartikel[i]); end; ### unit Unit3; {$mode objfpc}{$H+} interface uses Classes, SysUtils; var slFLartikel: TStringlist; implementation end.
Btw is the reference to each other bad coding only or is forbidden definitely?It is definitely bad coding imo. Some development software allows it and leave the responsibility to the programmer. Other software may be more strict and disallows cyclical referencing.
You shouldn't cross reference units. Use unit 2 in unit 1 or unit 1 in unit 2, but not both. Also, it would be helpful if you provide the source. Otherwise there's no way anyone can help.Nonsense. The compiler catches that at compile time...
So when you comment out the code in tform2.myproc3 everything seems to work as expected? Can you create the smallest compilable complete application possible, zip it and post it here? As for the message Type TSTRINGLIST has no component named COUNT is the inability of GDB to correctly recognize pascal properties, it has nothing to do with your code.
Nonsense, yet somewhat correct. Right! So what's it gonna be? Cross referencing units is bad coding and has no place in structured programming. Period. And nowhere in my comments did I suggest that it would resolve the problem. Just a step in the right direction. I stated multiple times that without compilable code, no help could be given. But thanks for the lecture. you're very good at it. 8-)You shouldn't cross reference units. Use unit 2 in unit 1 or unit 1 in unit 2, but not both. Also, it would be helpful if you provide the source. Otherwise there's no way anyone can help.Nonsense. The compiler catches that at compile time...
Your advice about introducing a third unit, however is somewhat correct, but not related to an external SIGSEV.
You should have explained that unit references can be resolved by adding one to the interface and the other to the implementation section. (Common knowledge, even basic knowledge).
In the case that it is unresolvable your suggestion is correct, but not for the original problem. So he is still stuck...
If he gives us compilable code, it can be resolved much quicker. (doesn't have to work, but a full project that demonstrates the issue.
Your main project file needs to create Form2 as well as Form1:Ah, this was a mistake which I removed for testing purpose only. In the original code still it's in the project file.
and you should delete the TForm2.OnCreate handler, and replace it with a TForm2.OnShow handler:This did the trick.
Can you explain why the OnCreate event doesn't work for this?OnCreate is invoked when the form is created. If it's in the project file then this will be at program startup. If you try to access an object in that handler that has not (yet) been created you will receive the SIGSEGV. If you access the object in the OnShow handler and create the object before showing the form no error occurs because the object exists.