Recent

Author Topic: Find > Jump to Procedure, when procedure is virtual abstract  (Read 1670 times)

dieselnutjob

  • Full Member
  • ***
  • Posts: 217
If I am looking at the definition of a function or procedure in Lazarus I can normally right click on it, select Find, then Jump to Procedure [procedurename].

However if it is has virtual; abstract; then this doesn't work.

I guess that this is because the code is overwritten in some other unit?  Sorry but virtual and abstract stuff blows my mind a bit.

Anyway if I am looking at someone elses code and I want to understand it how do I actually find the code of a procedure that is virtual abstract?

thanks DNJ

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: Find > Jump to Procedure, when procedure is virtual abstract
« Reply #1 on: June 27, 2020, 05:32:35 pm »
A virtual; abstract does not have any code(*). That's the point of abstract methods, that they have to be implemented by someone inheriting from the class. Otherwise you'll get an EAbstractError exception if you call the method.

* To be precise: for each abstract method the compiler simply generates an implicit method body that does esentially a raise EAbstractError.Create.

HeavyUser

  • Sr. Member
  • ****
  • Posts: 397
Re: Find > Jump to Procedure, when procedure is virtual abstract
« Reply #2 on: June 27, 2020, 05:34:12 pm »
If I am looking at the definition of a function or procedure in Lazarus I can normally right click on it, select Find, then Jump to Procedure [procedurename].

However if it is has virtual; abstract; then this doesn't work.

I guess that this is because the code is overwritten in some other unit?  Sorry but virtual and abstract stuff blows my mind a bit.

Anyway if I am looking at someone elses code and I want to understand it how do I actually find the code of a procedure that is virtual abstract?

thanks DNJ
Virtual, means that the method can be overridden in a child class. Abstract, means that the method has no implementation in the current class and child classes must override it.

Try use ctrl+Left mouse click to jump to method declaration and ctrl+shift+up/down arrows keys to move between interface and implementation. That's faster for me.

dieselnutjob

  • Full Member
  • ***
  • Posts: 217
Re: Find > Jump to Procedure, when procedure is virtual abstract
« Reply #3 on: June 27, 2020, 05:48:35 pm »
A virtual; abstract does not have any code(*). That's the point of abstract methods, that they have to be implemented by someone inheriting from the class. Otherwise you'll get an EAbstractError exception if you call the method.

* To be precise: for each abstract method the compiler simply generates an implicit method body that does esentially a raise EAbstractError.Create.

How do I find the thing that inherits it and the implementation there of?

dieselnutjob

  • Full Member
  • ***
  • Posts: 217
Re: Find > Jump to Procedure, when procedure is virtual abstract
« Reply #4 on: June 27, 2020, 05:58:20 pm »
currently I can find the implementation code by using command line, going into the folder that seems to contain the inheriting/inherited (sorry don't understand which) and then I can use grep(unix/linux) or findstr(windows) to search the source code to find the files that contain the function.

Then open the file in Lazarus and use find to find it.

It seems to work, but surely that there must be a slicker way inside the IDE to do this?

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: Find > Jump to Procedure, when procedure is virtual abstract
« Reply #5 on: June 27, 2020, 06:01:09 pm »
A virtual; abstract does not have any code(*). That's the point of abstract methods, that they have to be implemented by someone inheriting from the class. Otherwise you'll get an EAbstractError exception if you call the method.

* To be precise: for each abstract method the compiler simply generates an implicit method body that does esentially a raise EAbstractError.Create.

How do I find the thing that inherits it and the implementation there of?

Well, that is essentially endless, because anyone who inherits a class can provide an implementation. It could be a class in some third party package that you don't have. The best I can offer you is that you search for references of the class with the abstract method, but this search might not be exhaustive.

dieselnutjob

  • Full Member
  • ***
  • Posts: 217
Re: Find > Jump to Procedure, when procedure is virtual abstract
« Reply #6 on: June 27, 2020, 06:15:11 pm »
ok that's fair enough.

However when the thing is actually compiled then clearly the compiler can figure out where the code is.
If the compiler can figure it out then it would be nice if the IDE could figure it out too.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: Find > Jump to Procedure, when procedure is virtual abstract
« Reply #7 on: June 27, 2020, 07:49:39 pm »
The compiler can figure it out, because it walks from child to parent which is linear. What you are trying is to go from the parent to all children which is not so trivial.

BrunoK

  • Sr. Member
  • ****
  • Posts: 452
  • Retired programmer
Re: Find > Jump to Procedure, when procedure is virtual abstract
« Reply #8 on: June 28, 2020, 12:57:33 pm »
From lazarus, suggest you use Ctrl-Shift-F -> Find in files and give [procedurename] and specify the correct Directories where to search. On win10 it is quite slow the first time, but subsequent searches are much faster.

In the search results, locate what unit seems to be concerned, click on one of the retrieved [procedurename]  (not the filename). That should help you to navigate the sources without using grep.


Lazarus quite recent trunk (+/- changes regarding TScrollBar, IntitalSetupDialog, Options.Environment options).  FPC 3.0.4 (the mac os one) in 32 bit mode from svn + some mods.
Windows 10 Pro x64 (v. 1903 / 18362.418) and for occasional Linux tests, Manjaro (QT5 and GTK2)


 

TinyPortal © 2005-2018