Recent

Author Topic: Can't load resources from a trivial program  (Read 1142 times)

bobc50

  • New Member
  • *
  • Posts: 30
Can't load resources from a trivial program
« on: July 14, 2022, 10:09:37 pm »
I've seen some similar questions but can't apply the answers to this simple problem. I'm running Version: 2.2.2, FPC Version 3.2.2, Revision: lazarus_2_2_2, i386-win32-win32/win64. I created a new application and add one line, {$R 'CheckBox1.rc'} after {$mode objfpc}{$H+}. Code is below. CheckBox.rc is in the same folder as the project and contains the one line:
CHKBOX BITMAP TICKCHK1.BMP
TICKCHK1.BMP is also in the same folder.

When I compile with -vd I get the following messages:
Compile Project, Target: project1.exe: Exit code 1, Errors: 1, Warnings: 2
Warning: windres [option(s)] [input-file] [output-file]
Warning: windres: supported targets: pe-i386 pei-i386 elf32-i386 elf32-iamcu elf32-little elf32-big pe-x86-64 pei-x86-64 pe-bigobj-x86-64 elf64-x86-64 elf64-l1om elf64-k1om elf64-little elf64-big plugin srec symbolsrec verilog tekhex binary ihex
unit1.pas(28,0) Error: Error while compiling resources -> Compile with -vd for more details. Check for duplicates.

I've had another programmer follow the exact same steps and they had no issue. How can I troubleshoot/fix this problem?



Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4. {$R 'CheckBox1.rc'}// this is how the TickChk.bmp file gets included
  5.  
  6. interface
  7.  
  8. uses
  9.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
  10.  
  11. type
  12.   TForm1 = class(TForm)
  13.   private
  14.  
  15.   public
  16.  
  17.   end;
  18.  
  19. var
  20.   Form1: TForm1;
  21.  
  22. implementation
  23.  
  24. {$R *.lfm}
  25.  
  26. end.    

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Can't load resources from a trivial program
« Reply #1 on: July 14, 2022, 11:47:17 pm »
try putting that down in the Implementation section instead.
The only true wisdom is knowing you know nothing

bobc50

  • New Member
  • *
  • Posts: 30
Re: Can't load resources from a trivial program
« Reply #2 on: July 15, 2022, 12:00:04 am »
Thanks, but unfortunately that made no difference. The messages are identical.

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Can't load resources from a trivial program
« Reply #3 on: July 15, 2022, 12:39:31 am »
Not but I normally recompile the *.RC to a *.res file and include that instead.

However, have you tried going to the project inspector in the Project menu and add it there ?
The only true wisdom is knowing you know nothing

bobc50

  • New Member
  • *
  • Posts: 30
Re: Can't load resources from a trivial program
« Reply #4 on: July 15, 2022, 01:21:42 am »
Thanks again for trying to help!

I tried your suggestion about add the rc file to the project inspector and it compiled with no errors. This small test case was designed to trouble shoot a compile problem in a very large program. I went back to the project inspector and add the three rc files and the large project built but when I went to run it I got error messages indicating that the resource checkbox was not found. That message is identical to what I got when I commented out the rc lines in the appropriate .pas files so that I could compile the whole project and then built it.

You suggested compiling the rc file to a res file and including that. I tried adding them via the project inspector and got the same results as above.

Let me try a be a bit clearer in the larger problem I'm trying to solve.

I've got a very large program. One of the components in that program is a package file. One of the .pas files in that package file had one {$R...} lines and another had two. Following your suggestions, I hope, I've removed those lines and then rebuilt the package file using the project inspector to add the three .rc files I had commented out. I then tried to build the major project and if failed, not finding one of the rc file, specifically checkbox.rc. I tried the same set of steps removing the rc files from the project build and adding the corresponding .res files and the same error occurred.

I hope that makes sense and hope I've followed your advice and would appreciate some other trouble shooting steps.

I am a long-time programmer but new to both Pascal and Lazarus. Are there a few lines of code that I can add to a new application that would allow me to know if the resource was actually present? There is little I can do with the large project to provide an example.

dsiders

  • Hero Member
  • *****
  • Posts: 1084
Re: Can't load resources from a trivial program
« Reply #5 on: July 15, 2022, 01:29:09 am »
I do not use .rc for resources, but all off the $R directives for .lfm resources in my code does not have quotes around the resource name:

{$R checkbox.rc}

The quotes are not mentioned in the language reference either....
Preview Lazarus 3.99 documentation at: https://dsiders.gitlab.io/lazdocsnext

jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: Can't load resources from a trivial program
« Reply #6 on: July 15, 2022, 01:44:07 am »
Good catch, I didn't see that.
The only true wisdom is knowing you know nothing

bobc50

  • New Member
  • *
  • Posts: 30
Re: Can't load resources from a trivial program
« Reply #7 on: July 15, 2022, 08:25:11 am »
Thanks again for the suggestion.

I was surprised at the results and initially thought (hoped) that the problem was solved.

Eliminating the single quotes allowed my trivial program to build with no issue.

However, when I did the same to the rc lines in the two pascal files that were in the package I got the same fatal error about checkbox.rc suggesting that it was a duplicate.

bobc50

  • New Member
  • *
  • Posts: 30
Re: Can't load resources from a trivial program (Solved)
« Reply #8 on: July 15, 2022, 11:48:27 am »
Thanks to all that helped.

What finally worked was to change the three {$R entries in the package to use the .res files, not the .rc files and remove the single quotes, e.g.,
{$R checkbox.res}

I’ve got no clue why that worked nor why the {$R 'checbox.rc'} approach the developer used was working on their pc, but not mine. If anyone can explain that we'd appreciate hearing the answer.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11455
  • FPC developer.
Re: Can't load resources from a trivial program
« Reply #9 on: July 15, 2022, 02:25:04 pm »
Having quotes is valid syntax and works for me ({$mode delphi}) but with two arguments; I have lines like

{$R 'shadersrc.res' '..\libraries\common\shadersrc.rc'}

in my .dpr

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Can't load resources from a trivial program
« Reply #10 on: July 15, 2022, 03:09:41 pm »
That syntax is indeed the one to use. It also works for .lpr. It may be that for the .res part it is not necessary, but it is for the .rc part.
Personally I use the quotes for both.

In effect it tells the - resource - compiler to first compile the .rc file, which is a text file, to binary format and then use the generated res file to compile the final result.
Note that when you change the .rc file you need a rebuild, not just a recompile.
People may be confused about that: if a res file is already present, that will be used on a simple recompile, hence you need to fully rebuild your program after an rc file is editted.

This feature is Delphi compatible and I wrote an article about this feature for the legendary UNDU in 1999/2000 so nay 24 years old and still relevant.
I also lobbyed for including this in Lazarus/FPC.
You can still find more info on nldelphi.com (in Dutch).
« Last Edit: July 15, 2022, 03:29:00 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

bobc50

  • New Member
  • *
  • Posts: 30
Re: Can't load resources from a trivial program
« Reply #11 on: July 15, 2022, 03:55:52 pm »
Thanks for the explanations. That was helpful.

RE: Quotes-It may be that for the .res part it is not necessary, but it is for the .rc part. Personally I use the quotes for both.

That gets me back to my original post. For some reason I cannot write the most trivial pascal program which will compile a .rc file. I can remove the quotes and get it to compile without a duplicate error, but it doesn't generate a .res file.

RE: Using {$R 'shadersrc.res' '..\libraries\common\shadersrc.rc' in my .dpr

A .dpr file is new to me. Is it (roughly) a pascal file that is compiled in Delphi compatibility mode? Using a second argument in my pascal file doesn't have any affect.

Thaddy

  • Hero Member
  • *****
  • Posts: 14377
  • Sensorship about opinions does not belong here.
Re: Can't load resources from a trivial program
« Reply #12 on: July 15, 2022, 04:31:24 pm »
dpr is delphi or delphi mode. lpr is for Lazarus, but also suitable for delphi mode. Both contain the main program.
Note you need to put a space between the quotes res and quoted rc! Otherwise it might be (is) interpreted as a concatenation.
« Last Edit: July 15, 2022, 04:34:27 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

bobc50

  • New Member
  • *
  • Posts: 30
Re: Can't load resources from a trivial program
« Reply #13 on: July 15, 2022, 05:07:39 pm »
Thanks, I've learned a lot.

I tried all of the suggestions and have gotten the large program to compile and run which is a major victory. I still haven't gotten a simple pascal program which will compile and run under Lazarus on my PC which will convert a resource file (.rc) to a .res file. I can provide my programs to other Lazarus user's, and they are able to do that with no issue. Oh well! I've got other challenges to deals with.

 

TinyPortal © 2005-2018