Recent

Author Topic: What unit contains this object?  (Read 1056 times)

dgrhoads

  • New Member
  • *
  • Posts: 30
What unit contains this object?
« on: January 19, 2021, 02:07:09 pm »
One thing I love about Lazarus is the documentation, especially the lists of objects for the rtf, FCL and LCL.  It took me a while to figure out how it all goes together.  Having done that, it makes things a whole lot easier.

One thing that I don't see in the descriptions of those objects (i.e. TStringGrid or TINIFiles), is which unit they are located.  If the object were in a package, it would be loaded automatically into the uses statement.  In many cases, there is no package as the object is not visual.

Is there an easy way to figure out the unit in which a given object is located?

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: What unit contains this object?
« Reply #1 on: January 19, 2021, 02:23:15 pm »
If you use Lazarus IDE, you can move your mouse above the identifier and use Alt + Click. It does not show/tell you which unit the identifier belong to but it shows you which file (not always *.pas, it can be *.inc) the declaration of it can be found.

Alt + Click does not always available, for example you haven't put the correct unit in the uses clause.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: What unit contains this object?
« Reply #2 on: January 19, 2021, 02:35:19 pm »
One thing that I don't see in the descriptions of those objects (i.e. TStringGrid or TINIFiles), is which unit they are located.

https://lazarus-ccr.sourceforge.io/docs/lcl/grids/tstringgrid.html
Quote
Declaration
Source position: grids.pas line 1761

https://www.freepascal.org/docs-html/fcl/inifiles/tinifile.html
Quote
Declaration
Source position: inifiles.pp line 215

Look at the URL to see the package it is in: LCL and FCL.

You can add the package to your project, type the unit into your uses clause, and then use the IDE to jump to the unit.



There is also a nice tool "Identifier dictionary"

Under Packages > Install Packages: Install the packages "Cody" into your IDE.

You get a new menu entry "Show Unit/Identifier dictionary" in the "Source" menu. It can find almost any identifier, and tell you where it is declared.
If it does not find something, it will learn as you manually discover it... (afaik)



cdbc

  • Hero Member
  • *****
  • Posts: 1026
    • http://www.cdbc.dk
Re: What unit contains this object?
« Reply #3 on: January 19, 2021, 03:20:43 pm »
Hi
On my Lazarus, i just have to 'hover' the mouse over the identifier and up pops a bobble with the information you need. Clever, right  ;)
HTH
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE5 -> FPC 3.2.2 -> Lazarus 2.2.6 up until Jan 2024 from then on it's: KDE5/QT5 -> FPC 3.3.1 -> Lazarus 3.0

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: What unit contains this object?
« Reply #4 on: January 19, 2021, 03:41:42 pm »
The "alt click" and "hover" work fine, if the correct unit is already in the uses.

If you start a new empty project, and you insert "var a: TWriteInstruction" then you still need to add the unit where this is declared. And "alt click" and "hover"  will not tell you anything.

The identifier dictionary might find it. It may not always. Afaik it learns over time....

wp

  • Hero Member
  • *****
  • Posts: 11856
Re: What unit contains this object?
« Reply #5 on: January 19, 2021, 03:54:28 pm »
Alt + Click
Really? I use Ctrl+Click.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: What unit contains this object?
« Reply #6 on: January 19, 2021, 04:02:34 pm »
Alt + Click
Really? I use Ctrl+Click.
Ok, yes... In my case thoughtless  copy and paste.... Alt - cursor-up....

Though you can configure the mouse to work with alt-click.

Never mind: Ctrl click will not find you TWriteInstruction, unless the unit is in the uses (and the package in the project)

dgrhoads

  • New Member
  • *
  • Posts: 30
Re: What unit contains this object?
« Reply #7 on: January 19, 2021, 08:59:52 pm »
So the bottom line is that if the correct unit is not listed on the uses section, I have to figure out what unit to include using whatever resources I can muster.

I had a feeling that was the case.  I was hoping that there was a better solution.

I know that it would be a tremendous amount of work at this stage, but it would be nice to update the documentation so that the name of the unit is included in the description. 

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9792
  • Debugger - SynEdit - and more
    • wiki
Re: What unit contains this object?
« Reply #8 on: January 19, 2021, 09:05:45 pm »
So the bottom line is that if the correct unit is not listed on the uses section, I have to figure out what unit to include using whatever resources I can muster.

No, the identifier directory will do that. Eventually.

I do not know its exact inner working, and when exactly it builds the dictionary. I heard (hearsay) some people had to wait until it would build the dictionary. For me it always worked on the spot.


Of course the IDE has to have access to the source.

It will not tell you, if the identifier is in a package you have not yet downloaded.

 

TinyPortal © 2005-2018