Recent

Author Topic: How do I find the unit with DrawText in?  (Read 2890 times)

imekon

  • New Member
  • *
  • Posts: 12
How do I find the unit with DrawText in?
« on: November 18, 2019, 08:18:10 am »
I've come across this a few times...

How do I find which unit has the definition of a function or class?

I wanted to use DrawText, I ended up searching all the files in the lazarus folder to find it. Is there a website that has this information? Quite often, I find the function described but the unit it's in isn't mentioned.

Delphi had a function that could find which unit a class/function lived in - though often it stopped working after a while. Does Lazarus have anything like that?

Zvoni

  • Hero Member
  • *****
  • Posts: 2319
Re: How do I find the unit with DrawText in?
« Reply #1 on: November 18, 2019, 09:49:23 am »
If you look closely, you'll see a "/lclintf/" in the path.....
https://lazarus-ccr.sourceforge.io/docs/lcl/lclintf/drawtext.html
or just click on "Index"

One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

Handoko

  • Hero Member
  • *****
  • Posts: 5131
  • My goal: build my own game engine using Lazarus
Re: How do I find the unit with DrawText in?
« Reply #2 on: November 18, 2019, 09:56:04 am »
@imekon

If you're looking DrawText for printer, maybe you're interested to read this:
https://forum.lazarus.freepascal.org/index.php/topic,26790.msg164929.html#msg164929

Or if you want to draw text on the screen, you can use TCanvas.TextOut. See my example:
https://forum.lazarus.freepascal.org/index.php/topic,46775.msg333936.html#msg333936
« Last Edit: November 18, 2019, 09:58:09 am by Handoko »

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: How do I find the unit with DrawText in?
« Reply #3 on: November 18, 2019, 10:06:44 am »
Any TObject has a unitname property: https://www.freepascal.org/docs-html/rtl/system/tobject.html and https://www.freepascal.org/docs-html/rtl/system/tobject.unitname.html
Code: Pascal  [Select][+][-]
  1. unit testme;
  2. {$mode objfpc}
  3. interface
  4. type
  5.   TUnitClass= class
  6.   end;
  7. implementation
  8. end.
Code: Pascal  [Select][+][-]
  1. program testtestme;
  2. {$mode objfpc}
  3. uses testme;
  4. var T: TUnitclass;
  5. begin
  6.   T:=TUnitClass.Create;
  7.   try
  8.     writeln(T.Unitname);
  9.   finally
  10.     T.free;
  11.   end
  12. end.
« Last Edit: November 18, 2019, 10:22:27 am by Thaddy »
Specialize a type, not a var.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How do I find the unit with DrawText in?
« Reply #4 on: November 18, 2019, 10:09:25 am »
Provided you have the Cody package installed, you will find on the Source main menu an item 

Show Unit/Identifier Dictionary...
which provides a dialog where you can type the name of the identifier you want. It shows you all occurrences, with unit names and paths, in the FreePascal and Lazarus sources.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: How do I find the unit with DrawText in?
« Reply #5 on: November 18, 2019, 10:20:51 am »
Provided you have the Cody package installed,
Really stable (  :o )and really not needed. <sigh>
(That's another subject but Cody needs a - huge - rewrite)
« Last Edit: November 18, 2019, 10:23:29 am by Thaddy »
Specialize a type, not a var.

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: How do I find the unit with DrawText in?
« Reply #6 on: November 18, 2019, 11:23:53 am »
Some people highly recommend Cody, Thaddy obviously does not. I don't know, I rarely use it because I always forget how to find the menu item which allows me to search for the unknown word...

My standard way of searching for units is this:

Suppose I have this TAChart code:
Code: Pascal  [Select][+][-]
  1.   LineSeries.Pointer.Style := psCircle;
When I compile this the IDE moves the cursor to "psCirclee" and says "Identifier not found: psCircle". This means: it DID find the Style!. Therefore I CTRL-click on the word "Style", and this opens the unit in which Pointer.Style is declared and jumps to this line:
Code: Pascal  [Select][+][-]
  1.     property Style: TSeriesPointerStyle read FStyle write SetStyle default psRectangle;
Here I see: Style is of type TSeriesPointerStyle. So, I CTRL-click on TSeriesPointerStyle and this brings me to
Code: Pascal  [Select][+][-]
  1.   TSeriesPointerStyle = (
  2.     psNone, psRectangle, psCircle, psCross, psDiagCross, psStar,
  3.     psLowBracket, psHighBracket, psLeftBracket, psRightBracket, psDiamond,
  4.     psTriangle, psLeftTriangle, psRightTriangle, psVertBar, psHorBar, psPoint,
  5.     psDownTriangle, psHexagon, psFullStar);
Here, psCircle is the third value of the enumeration. Looking at the editor tab in the IDE I can see that this is in unit TATypes. Therefore, I must add TATypes to "uses".

Of course, this does not help when the unidentified word is out of context, such as the "DrawText" mentioned by the TS. In this case, I usually do an internet search which usually has a hint to the unit within the first few hits.

A good idea is also to move the cursor onto the unidentified word and press F1. The integrated help of Lazarus is getting better and better (thanks to the many contributions by Don Siders - thank you), and there is a good chance that the missing unit is found this way.

P.S.
With "CTRL-click" I mean: hold the CTRL key down while clicking the left mouse button.

lucamar

  • Hero Member
  • *****
  • Posts: 4219
Re: How do I find the unit with DrawText in?
« Reply #7 on: November 18, 2019, 12:22:22 pm »
What I usually do is a simple search in the help files. If that returns nothing (i.e. what I'm looking for is not documented at all) then wp's way is good (though sometimes it leads you to some obscurely-named INC file), or just grep the sources and/or search in the website.
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.

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: How do I find the unit with DrawText in?
« Reply #8 on: November 18, 2019, 03:22:52 pm »
Provided you have the Cody package installed,
Really stable (  :o )and really not needed. <sigh>
(That's another subject but Cody needs a - huge - rewrite)
Cody really is needed if you want to take advantage of its extensive functionality.
If not, no need to sigh. Just get on with your coding without it.
If you encounter bugs or instability using Cody, please submit a bug report. I use it all the time with no problems, but I accept that YMMV.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
Re: How do I find the unit with DrawText in?
« Reply #9 on: November 18, 2019, 03:43:50 pm »
If you encounter bugs or instability using Cody, please submit a bug report. I use it all the time with no problems, but I accept that YMMV.
Will do.
But about the original question:

You can simply examine the unit name from elsewhere, as per my example.
Specialize a type, not a var.

440bx

  • Hero Member
  • *****
  • Posts: 3946
Re: How do I find the unit with DrawText in?
« Reply #10 on: November 18, 2019, 05:35:40 pm »
How do I find which unit has the definition of a function or class?
You got a few answers already but, I simply place the cursor on the function name and either right-click and select "Find declaration of <functioname>" in the popup menu or press <alt-up arrow> which does the same thing.  Most of the time, that will take you to the unit that contains the function, occasionally it will take you to an include file which is part of the unit you're interested in. 

HTH.
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018