Recent

Author Topic: Adding custom .rc-file  (Read 1052 times)

Jungle

  • New Member
  • *
  • Posts: 25
Adding custom .rc-file
« on: February 04, 2023, 04:59:20 pm »
I try adding custom rc file to my project by specifying
Code: Pascal  [Select][+][-]
  1. {$R 'd:\data.rc' 'd:\data.res'}

When I compile, I get a message ''Compiling resource d:\data.rc" which stays forever and nothing happens. What could be the reason? Is there more verbose log?

Lazarus 2.2.2, Win 11

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Adding custom .rc-file
« Reply #1 on: February 04, 2023, 05:08:10 pm »
I try adding custom rc file to my project by specifying
Code: Pascal  [Select][+][-]
  1. {$R 'd:\data.rc' 'd:\data.res'}

When I compile, I get a message ''Compiling resource d:\data.rc" which stays forever and nothing happens. What could be the reason? Is there more verbose log?

Lazarus 2.2.2, Win 11
Syntax should .rc or .res, but not both.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Adding custom .rc-file
« Reply #2 on: February 04, 2023, 05:11:04 pm »
Like described on a wiki page (sorry, i did not found on official docu)
Quote
{$R filename.rc} to compile a resource script and include the resulting resource file or
{$R filename.res} directive to include a compiled resource file
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

TRon

  • Hero Member
  • *****
  • Posts: 2435
Re: Adding custom .rc-file
« Reply #3 on: February 04, 2023, 05:20:53 pm »
Since this is posted in a Lazarus related sub-forum: unless you have special needs to compile the resource manually you can simply add the resource to your project. There is functionality in place that let's you access the resource.

Jungle

  • New Member
  • *
  • Posts: 25
Re: Adding custom .rc-file
« Reply #4 on: February 04, 2023, 05:43:08 pm »
Syntax should .rc or .res, but not both.

{$R 'd:\data.rc'} Doesn't work too. The same behaviour

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Adding custom .rc-file
« Reply #5 on: February 04, 2023, 05:54:33 pm »
When I remember correct .rc must be inside project folder, so in source add it without 'path'.
But do like TRon told, use the IDE.
Menu Project -> Project Options -> Resources -> +ADD
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Jungle

  • New Member
  • *
  • Posts: 25
Re: Adding custom .rc-file
« Reply #6 on: February 04, 2023, 06:44:57 pm »
But do like TRon told, use the IDE.
Menu Project -> Project Options -> Resources -> +ADD
And what if I want to share some resource file between different projects? So a file could be in a fixed location, and there wouldn't be a need to synchronize changes or make links.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Adding custom .rc-file
« Reply #7 on: February 04, 2023, 06:59:28 pm »
Compile it to .res outside of Lazarus and add inside of Lazarus
Code: Pascal  [Select][+][-]
  1. {$R 'c:\Your\Shared\Resources.res'}

//edit:
Take care that you NOT include in that shared resource something like "MainIcon" (!)
It really must be unique (!)
« Last Edit: February 04, 2023, 07:07:47 pm by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Jungle

  • New Member
  • *
  • Posts: 25
Re: Adding custom .rc-file
« Reply #8 on: February 04, 2023, 08:26:18 pm »
Compile it to .res outside of Lazarus and add inside of Lazarus
It means that I (or someone else) will have to remember to add pre-compile actions to a project or build *.res after each resource change.

Btw,
1. Why is path respected for *.res, but not for *.rc ?
2. Why is there no error, no timeout, just endless "Compiling" process ?

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2007
  • Fifty shades of code.
    • Delphi & FreePascal
Re: Adding custom .rc-file
« Reply #9 on: February 04, 2023, 08:47:20 pm »
Idk what kind of resources you/your team need to share, in belonging of linking something into an executable file, what you said is true.
After a change of the .rc file, you need to compile it, after that you need to compile all affected projects.
The better strategy for such is to use .dll, that you can compile within Lazarus and just need to tell your executable project from where to load it, so every app is automagical up-to-date.
Does it make sense to you?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Jungle

  • New Member
  • *
  • Posts: 25
Re: Adding custom .rc-file
« Reply #10 on: February 05, 2023, 02:44:35 pm »
The better strategy for such is to use .dll, that you can compile within Lazarus and just need to tell your executable project from where to load it, so every app is automagical up-to-date.
Does it make sense to you?
Thanks, it indeed looks good.

 

TinyPortal © 2005-2018