Recent

Author Topic: Ctrl click won't work in inherited form  (Read 908 times)

packard

  • New member
  • *
  • Posts: 5
Ctrl click won't work in inherited form
« on: October 12, 2022, 02:43:01 pm »
I have been using Lazarus/Free Pascal for some time to run parts of a big old Delphi 6 project that I worked on back in early the 2000s. Having successfully compiled and run lots of the low level stuff, I am generally very impressed with Lazarus, so thanks in advance for all the hard work that has gone into the project.

But now comes the tricky bit. The original projects used Forms inheritance, packages and other Delphi 6 delights that imo were never completely foolproof in the D6 environment. In Lazarus, I am now trying to inherit a "base" form TBaseForm that was extensively used by the D6 projects. Having carved out all the windows dependencies, the base form compiles runs OK on its own in Lazarus IDEv2.2.4 under Win 10 (32bit compiler version).

I successfully managed to create a simple new project with an inherited TBaseform, by creating a new form and changing its class from TForm to TBaseForm (itself a descendent of TForm) and copying/renaming the base form's .lfm file to the new project, finally changing the .lfr file appropriately. This works and compiles and runs OK, but something is obviously awry, in the IDE because Ctrl click no longer functions consistently, making navigation around the code return to 1980s dark ages! Ctrl click works in the .lpr file, but not in the unit containing the inherited form. The underline does not illuminate when Ctrl is pressed with the curser hovering over an element in the code and right click|Find declaration goes somewhere completely random. It doesn't work in any of the other units in the project either.

Yes, I know that there is a Lazarus package that is supposed to enable Form inheritance, but I am curious to know what might be going wrong with the manual method that I used, before grappling with packages.


PascalDragon

  • Hero Member
  • *****
  • Posts: 4872
  • Compiler Developer
Re: Ctrl click won't work in inherited form
« Reply #1 on: October 13, 2022, 07:34:19 am »
If you have a small reproducible test case it might be best to simply report that as a bug. You could also upload it here so that others can try whether they're able to identify the problem right away.

packard

  • New member
  • *
  • Posts: 5
Re: Ctrl click won't work in inherited form
« Reply #2 on: October 13, 2022, 01:40:13 pm »
Yes, I need to isolate the problem in a new project, or preferably create a new project that doesn't have the problem.

There is something in the present project's  configuration that is causing severe brain damage. The program compiles and runs, up to a point and gives correct results. However as well as Ctrl click not working in the IDE, right clicking on a token and selecting "find declaration" always jumps to the same spurious place in an unrelated unit. The debugger is also haywire. It halts correctly at breakpoints, but fatal exceptions, e.g. array range checks or memory exceptions cause havoc and the source/assembler box does not display the  address at which the program is halted, but some completely spurious location instead. When I try to step through the the code, it crashes horribly of course.

I found an old project that I was playing with back in 2014, when I first tried Lazarus. I recompiled it and that project does work OK, using a main form inherited from my desired base form unit. But I cannot remember how I created it!

I compared the setups of the new and the old projects, i.e. examined the main units ,.pas .lfm and the .lpr .lpi .lps .res files along with project options in the IDE etc. but I cannot see anything untoward.

I think that I need to step back and recreate the new project. Rather than trying to inherit the base form for every new project, it may be simpler to create a "base project" that works and copy/rename that each time I want to create a new application. 

 

 

wp

  • Hero Member
  • *****
  • Posts: 10469
Re: Ctrl click won't work in inherited form
« Reply #3 on: October 13, 2022, 01:45:47 pm »
- Did you set any paths in the project options? Make sure that they are correct.
- Do a "Run" > "Cleanup and Build".
- Try "Tools" > "Rescan FPC directory".

packard

  • New member
  • *
  • Posts: 5
Re: Ctrl click won't work in inherited form
« Reply #4 on: October 13, 2022, 05:51:50 pm »
thanks wp, I tried those things. The problem is related to  the inheritance of visual components.
I created a new "template" project which has an empty form, inherited from the base form. This compiles and runs OK, but obviously does nothing interesting.

I then copied the entire template directory to a new folder and edited in the various procedures and functions that I need and renamed both the main form unit and the project. However, when I try to add a visual component to the inherited form from the component palette, it appears in the object inspector, but is not added to source code in the form unit. If I try to rename it in the object inspector i get "unable to rename variable in source". Well obviously, because the new component was not declared in the source code, even though it appears on the form. However, it does appear in the .lfm file when I save the unit

So I tried adding a new component by dropping it on to the form and then adding the missing declaration to the main form class statement. I can then rename it in the object inspector and the name changes correctly in the source code declaration too.

but Ctrl click still doesn't work, so there is still a fundamental problem

af0815

  • Hero Member
  • *****
  • Posts: 1085
Re: Ctrl click won't work in inherited form
« Reply #5 on: October 13, 2022, 06:12:47 pm »
Try to handle all from the IDE. you can always make inhertited Forms if say in the new form dialog inherited from. The only goal is, the project must know your baseforms. Try it only with the IDE an compare this with your changes by hand. You must miss something in the lfm like a misplaced or missing inherited.

BTW. Lazarus can handle template projects by itself. See https://wiki.freepascal.org/Project_Templates
 
« Last Edit: October 13, 2022, 06:17:11 pm by af0815 »
regards
Andreas

packard

  • New member
  • *
  • Posts: 5
Re: Ctrl click won't work in inherited form
« Reply #6 on: October 13, 2022, 11:48:55 pm »
thanks AF0815.
re handling from the IDE
The File|New|inherited project component menu looks promising, but how do I get the component to appear in the list? It only shows the form for the current project. some light is thrown on this by

https://forum.lazarus.freepascal.org/index.php?topic=53589.0

Food for though anyway. maybe I should create a new project with just the baseform unit in it and then inherit from that.

The project template package idea is nice and I tried it, but it doesn't cure the problem. If the original project didn't work properly, then the new one won't either.

regards,
P.




GetMem

  • Hero Member
  • *****
  • Posts: 3934
Re: Ctrl click won't work in inherited form
« Reply #7 on: October 14, 2022, 06:24:53 am »
@packard
Quote
The File|New|inherited project component menu looks promising, but how do I get the component to appear in the list? It only shows the form for the current project. some light is thrown on this by
Add baseform to the project first, then go to File->New->Inherited.

af0815

  • Hero Member
  • *****
  • Posts: 1085
Re: Ctrl click won't work in inherited form
« Reply #8 on: October 14, 2022, 08:27:12 am »
Not calling a event from parentform, can happens with the ide and static bound frames too. I know there is a problem. if you create a event in the child the binding to the parent event is lost. there is a missing inherited in the chain.

your problem looks similar. this is the reason, i think there is a missig inheritd in the lfm.

if you have a working project an a not wirking you can compare the difference.
« Last Edit: October 14, 2022, 08:29:06 am by af0815 »
regards
Andreas

packard

  • New member
  • *
  • Posts: 5
Re: Ctrl click won't work in inherited form
« Reply #9 on: October 14, 2022, 02:59:42 pm »
thanks to all for informative and helpful replies. I found that the cause of the problem was nothing to do with the inheritance of the form. Deep in the application code  in one of the units, in the uses clause of the main form, was an include file with type statement
type
foo : single;
bar : boolean;
static : integer;

It seems that "static" in that context was recognised as a keyword by the IDE (although not by the compiler). Afaik, The concept of a "Static Variable" does not exist in Standard Pascal. Static is also not listed in the Freepascal list of reserved words and Delphi 6 did not have a problem with this either. When the range of an array is included in the array definition, it is called a static array, however, elsewhere I found under FPC documentation
class Function GetA : Integer;  static; 

In my project, the term static is one used in seismology to indicate a static time delay, btw.

Changing the integer variable name static to istatic cured the problem ( I should have followed the historic convention from FORTRAN that integer variable names should begin with I,J,K,L,M or N). Ctrl click returned and along with it I and the debugger regained our sanity - but nevertheless ignorance is no friend of reliable programming!

regards,
P

PascalDragon

  • Hero Member
  • *****
  • Posts: 4872
  • Compiler Developer
Re: Ctrl click won't work in inherited form
« Reply #10 on: October 14, 2022, 03:25:49 pm »
thanks to all for informative and helpful replies. I found that the cause of the problem was nothing to do with the inheritance of the form. Deep in the application code  in one of the units, in the uses clause of the main form, was an include file with type statement
type
foo : single;
bar : boolean;
static : integer;

It seems that "static" in that context was recognised as a keyword by the IDE (although not by the compiler). Afaik, The concept of a "Static Variable" does not exist in Standard Pascal. Static is also not listed in the Freepascal list of reserved words and Delphi 6 did not have a problem with this either. When the range of an array is included in the array definition, it is called a static array, however, elsewhere I found under FPC documentation
class Function GetA : Integer;  static;

Yes, static is a valid modifier in some cases, however not for variable (or field) declarations. So please file a bug against Lazarus with an example that shows the IDE misinterpreting it.

Changing the integer variable name static to istatic cured the problem ( I should have followed the historic convention from FORTRAN that integer variable names should begin with I,J,K,L,M or N). Ctrl click returned and along with it I and the debugger regained our sanity - but nevertheless ignorance is no friend of reliable programming!

You could also have used the identifier escape &, so &static.

 

TinyPortal © 2005-2018