* * *

Author Topic: Macros in directives possible?  (Read 552 times)

CCRDude

  • Sr. Member
  • ****
  • Posts: 324
Macros in directives possible?
« on: June 16, 2017, 06:36:58 pm »
I want to use a Lazarus file for a Lazarus extension, laz_images.res.

If the file is in the same folder, I can do:

Code: Pascal  [Select]
  1. {$R laz_images.res}
  2.  

What I would love to do instead is:
Code: Pascal  [Select]
  1. {$R $(LazarusDir)/images/laz_images.res}
  2.  

Is this possible, maybe with another syntax?

taazz

  • Hero Member
  • *****
  • Posts: 3818
Re: Macros in directives possible?
« Reply #1 on: June 16, 2017, 07:41:24 pm »
try
Code: Pascal  [Select]
  1.  
  2. {$MACRO ON}
  3.   {$define ResFolder:='..\..\..\This\is\aNew\Folder'}
  4.  
  5. {$R ResFolder\laz_images.res}
  6.  
or something along those lines I do not know any way to use laz/fpc macros directly.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5427
Re: Macros in directives possible?
« Reply #2 on: June 16, 2017, 07:56:09 pm »
Don't add a res, just add a .rc to the project and lazarus handle it

CCRDude

  • Sr. Member
  • ****
  • Posts: 324
Re: Macros in directives possible?
« Reply #3 on: June 16, 2017, 10:05:06 pm »
@taazz: I can use relative paths with $R, point is that I need a path that's available only through macro (path macro, not source macro... am I using the right term?) afaik.

@marcov: laz_images.res is created through lazres with a text list file, no .rc involved.

Background is my FPCUnit extension displays a list of classes, functions, and methods. I want to use the same icons as Lazarus.

Checking for the debugging process would give me lazarus.exe and I could load resources from there, but FPCUnit tests can be executed from outside the IDE as well.

If there's no way, I'll simply stick with a copy of the laz_images.res in my project folder. Just would've loved to learn something new :)

Thaddy

  • Hero Member
  • *****
  • Posts: 3639
Re: Macros in directives possible?
« Reply #4 on: June 16, 2017, 10:21:34 pm »
@marcov: laz_images.res is created through lazres with a text list file, no .rc involved.
What Marco means: call the text file *.rc. if it is in resource script format it will automatically be compiled into a res and automatically handled by Lazarus,
Why do the Danish always try to fuck up any programming language?

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5427
Re: Macros in directives possible?
« Reply #5 on: June 16, 2017, 10:56:21 pm »
Thanks Thaddy,

yes, it is better to work as high level as possible. Like what do you think the "Resfolder" directory is relative  to exactly (answer: whatever directory the compiler is executed in)

It is possible to pass Lazarus macros as FPC macros by passing them as -dmacroname:=xxx

(note the :=).  I'm not sure though FPC interprets macro within preprocessor code. (and even if so, how deep does it recurse?) It is a bad habit, and one of the reasons the macroprocessor is deliberately not expanded; it is a slippery slope.

CCRDude

  • Sr. Member
  • ****
  • Posts: 324
Re: Macros in directives possible?
« Reply #6 on: June 17, 2017, 07:18:06 am »
@Thaddy: that's contradicting. If I rename a file that belongs to Lazarus itself, I probably cannot compile Lazarus any more. If I cannot compile Lazarus any more, I can't compile my own extension into Lazarus :D

I know about resource compiling, and the laz_images_list.txt file is merely a list of filenames. Plus, that would be exactly the same problem - I would need to point to the Lazarus folder, without knowing where the user had installed Lazarus ;)

I could pick, from any generated .gdb, the path to one of the LCL units, construct the Lazarus path from there, and then load the image resources there. But that's looks way too complicated compared to simply copying the file (or using different icons).

@marcov: thanks for clarifying the relativity of the path! Sorry for misunderstanding this earlier :)
I'll see if this helps. I noticed that in the subversion trunk, the FPC directory lies parallel to the Lazarus directory, while in releases, it's a subfolder of it.

{$R ResFolder\laz_images.res} does not work (regards ResFolder as part of the path), but I'll play around with that as well :)

taazz

  • Hero Member
  • *****
  • Posts: 3818
Re: Macros in directives possible?
« Reply #7 on: June 17, 2017, 10:07:58 am »
@Thaddy: that's contradicting. If I rename a file that belongs to Lazarus itself, I probably cannot compile Lazarus any more. If I cannot compile Lazarus any more, I can't compile my own extension into Lazarus :D

I know about resource compiling, and the laz_images_list.txt file is merely a list of filenames. Plus, that would be exactly the same problem - I would need to point to the Lazarus folder, without knowing where the user had installed Lazarus ;)

I could pick, from any generated .gdb, the path to one of the LCL units, construct the Lazarus path from there, and then load the image resources there. But that's looks way too complicated compared to simply copying the file (or using different icons).

@marcov: thanks for clarifying the relativity of the path! Sorry for misunderstanding this earlier :)
I'll see if this helps. I noticed that in the subversion trunk, the FPC directory lies parallel to the Lazarus directory, while in releases, it's a subfolder of it.

{$R ResFolder\laz_images.res} does not work (regards ResFolder as part of the path), but I'll play around with that as well :)
Do not copy or include the laz resurces verbatim, it will create problems with duplicate resources when installing your packages. Do not assume that fpcunit application will be executed using the GUI application as well, after all the strength of those tests, comes from the fact that they can be automated executed silently and save the result to a file, which they might be accessed from a console instead of a GUI application. Icons, cursor and sounds are good to have but they are not going to be of any help on remote shells.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

CCRDude

  • Sr. Member
  • ****
  • Posts: 324
Re: Macros in directives possible?
« Reply #8 on: June 18, 2017, 12:15:19 pm »
My bad by calling it package!

Rest assured that my test output is going into phpunit "compatible" xml files in the first place, everything discussed here is just a nice thing on the side :)
The actual "package" exists only to extend the Lazarus IDE with a custom gutter to help making code coverage results visible, no reference to these icons there.
And the resources are only intended to be used in a form that inherits from the TGUITestRunner form, so it will be used only in GUI tests.

My primary upstream is not the gitlab.com repo linked here on the forum, but an internal GitLab installation, where, thanks to GitLab CI, console versions of my code test are built and executed automatically on each push, using lazbuild and console test runners. I know that strength and am using it regularly :)

For code coverage to be used in both console and GUI runners, I would need to think about an interface for custom event handlers for FPCUnit that would be well-thought of sufficiently to be suggested on Mantis.

taazz

  • Hero Member
  • *****
  • Posts: 3818
Re: Macros in directives possible?
« Reply #9 on: June 18, 2017, 12:31:01 pm »
And the resources are only intended to be used in a form that inherits from the TGUITestRunner form, so it will be used only in GUI tests.
use an imagelist that is what they were created for.
My primary upstream is not the gitlab.com repo linked here on the forum, but an internal GitLab installation, where, thanks to GitLab CI, console versions of my code test are built and executed automatically on each push, using lazbuild and console test runners. I know that strength and am using it regularly :)

For code coverage to be used in both console and GUI runners, I would need to think about an interface for custom event handlers for FPCUnit that would be well-thought of sufficiently to be suggested on Mantis.
I prefer the fptest suit my self so I can't comment on the internals of fpcunit, so I'll just wait and see your suggestion be warned my only interest in this is to port it to fptest suit ;)
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

CCRDude

  • Sr. Member
  • ****
  • Posts: 324
Re: Macros in directives possible?
« Reply #10 on: June 19, 2017, 08:42:23 pm »
Now that's something great I could learn from this thread... I didn't know about FPTest; simply switched from DUnit to FPCUnit because it came with the IDE! FPTest looks way better.

I've started supporting FPTest as well, it works, but I'm still looking to automate registration of test case units with the codecoverage part (iterating through RegisteredTests, getting the actual TTestCase instances somehow to use their UnitName property, like I do in TCodeCoverageFPCUnit.FindTestUnitFilenames).

Not sure where to place a display on the FPTest IDE, and how that would be possible without modifying FPTest (I guess the GUIObject property might give a start), but even in the worst case, the created XML files can be interpreted within the Lazarus IDE.

taazz

  • Hero Member
  • *****
  • Posts: 3818
Re: Macros in directives possible?
« Reply #11 on: June 19, 2017, 09:19:55 pm »
Now that's something great I could learn from this thread... I didn't know about FPTest; simply switched from DUnit to FPCUnit because it came with the IDE! FPTest looks way better.

I've started supporting FPTest as well, it works, but I'm still looking to automate registration of test case units with the codecoverage part (iterating through RegisteredTests, getting the actual TTestCase instances somehow to use their UnitName property, like I do in TCodeCoverageFPCUnit.FindTestUnitFilenames).

I have no idea how this works but I'm under the impression that it should be the same if you jump over the interface part of the suit to the concrete objects bellow. In any case I'll take a closer look as soon as possible now that your attention is on it as well.
Not sure where to place a display on the FPTest IDE, and how that would be possible without modifying FPTest (I guess the GUIObject property might give a start), but even in the worst case, the created XML files can be interpreted within the Lazarus IDE.
There are a number of ideas running through my head from an extra column with a progress bar paint to a pale progress bar as background in the cell with the test name or even a group using the extra name of the registration procedures as a type of "sum" brunch. The possibilities are endless let me see what I can do. I'll need to fork the fptest repo in github so I can create pull requests. I'll inform you on my progress.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus