Recent

Author Topic: how to: Linux resource file in Lazarus - free pascal ?  (Read 5361 times)

userx-bw

  • Full Member
  • ***
  • Posts: 178
how to: Linux resource file in Lazarus - free pascal ?
« on: April 25, 2017, 11:51:07 pm »
I am thinking about starting a project that is a "simple" 21 card game. Of course it will need 52 cards. to elevate having to worry about where are all of the cards. I thought why not (try to) put them into a resource file?

I already looked just a very a little into the resource file thing. as Lazarus has a short wiki on it, and it looks like that is a windows thing only?

Can a resource file be used on Linux too?

if yes.

Can 52 plus images be put into a resource file as a whole then called up on to be shuffled then be dealt  out in that order that it would now be in just like a real deck of cards? 

if yes.

then the next question would be.

how do I do that?


My Finished Projects
https://sourceforge.net/projects/mhsetroot/
https://sourceforge.net/projects/gmhsetrootfreepascalfrontend/

HP Elitetbook 6930p Dual Core Intel vPro 2.66 gHz
VOID (Linux) 64bit

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: how to: Linux resource file in Lazarus - free pascal ?
« Reply #1 on: April 26, 2017, 04:11:18 am »
Yes, it can be used on Linux.

In Lazarus you can use the project options feature to manage the resources. To do it:
Lazarus main menu > Project > Project Options > Resources > Add | Delete | Delete All

To use it in your code, just use LoadFromResourceName. For example you have Image1 in your form and you want to load the picture named IMG1 then you use this code:

Code: Pascal  [Select][+][-]
  1. Image1.Picture.Bitmap.LoadFromResourceName(HINSTANCE, 'IMG1');

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: how to: Linux resource file in Lazarus - free pascal ?
« Reply #2 on: April 26, 2017, 10:38:07 am »
Free Pascal doesn't supply a resource compiler for any Unix-like OS though. The fpcres binary is NOT a resource compiler - contrary to what the filename suggests. :-/ So the suggestion by Handoko forces a dependencies on Lazarus IDE usage only, which is a shame. I often need to compile binaries on a headless server in a daily build/test environment.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: how to: Linux resource file in Lazarus - free pascal ?
« Reply #3 on: April 26, 2017, 12:00:48 pm »
I thought some basic resource support was compiler internal since 2.6.0 and you can just $R the .rc ?

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: how to: Linux resource file in Lazarus - free pascal ?
« Reply #4 on: April 26, 2017, 03:17:15 pm »
@Marco: No, that only works under Windows. Under Linux, FreeBSD etc if you use a {$R somefile.rc} the compilation fails with an error about missing resources or unable to compile the resource - sorry, I can't remember the exact error from memory.

The windres tool is not a standard tool installed with Linux or FreeBSD either.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: how to: Linux resource file in Lazarus - free pascal ?
« Reply #5 on: April 26, 2017, 03:24:19 pm »
Here is the exact output using FPC 2.6.4 and FPC 3.0.2 under 64-bit FreeBSD.

Code: [Select]
[tmp]$ fpc TestResources.pas
Hint: End of reading config file /home/graemeg/.fpc.cfg
Free Pascal Compiler version 2.6.4 [2014/02/28] for x86_64
Copyright (c) 1993-2014 by Florian Klaempfl and others
Target OS: FreeBSD for x86-64
Compiling TestResources.pas
TestResources.pas(10,1) Error: resource compiler "windres" not found, switching to external mode
TestResources.pas(10,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /data/devel/fpc-2.6.4/x86_64-freebsd/bin/ppcx64 returned an error exitcode (normal if you did not specify a source file to be compiled)
[tmp]$


[tmp]$ /data/devel/fpc-3.0.2/x86_64-freebsd/bin/fpc TestResources.pas
Hint: End of reading config file /home/graemeg/.fpc.cfg
Free Pascal Compiler version 3.0.2 [2017/02/10] for x86_64
Copyright (c) 1993-2017 by Florian Klaempfl and others
Target OS: FreeBSD for x86-64
Compiling TestResources.pas
TestResources.pas(10,1) Error: resource compiler "windres" not found, switching to external mode
TestResources.pas(10,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /data/devel/fpc-3.0.2/x86_64-freebsd/bin/ppcx64 returned an error exitcode
[tmp]$


I used {$R mydata.rc} in my test program and that files simply includes a binary data file:

==========================================
   MYDATA         RCDATA "mydata.dat"
==========================================
« Last Edit: April 26, 2017, 03:26:37 pm by Graeme »
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: how to: Linux resource file in Lazarus - free pascal ?
« Reply #6 on: April 26, 2017, 03:53:45 pm »
I looked into this further under FreeBSD, and also spotted my same concern back in 2012 in the mailing lists.

windres is part of the GNU binutils project. But even under FreeBSD (not sure about Linux - untested), if you use ports to install binutils, it doesn't include the windres binary (I guess it's too Windows centric). I have to download the binutils source code and manually compile the windres binary, then copy that into /usr/local/bin before FPC finds and uses it.

This is why fpGUI uses a different method to include resources and not via $R.

Why doesn't Free Pascal just included a home grown resource compiler? Like all other compiler projects do (Visual Studio, Delphi, OpenWatcom etc). There is enough open source example source code to implement such a utility.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: how to: Linux resource file in Lazarus - free pascal ?
« Reply #7 on: April 26, 2017, 04:43:12 pm »
But even under FreeBSD (not sure about Linux - untested), if you use ports to install binutils, it doesn't include the windres binary (I guess it's too Windows centric). I have to download the binutils source code and manually compile the windres binary, then copy that into /usr/local/bin before FPC finds and uses it.
Well, reading this this gives an answer as to the why:
Quote
Warning: windres is not always built as part of the binary utilities, since it is only useful for Windows targets.

I understand your frustration though...

It is usually a pita to maintain/develop the platforms that are not part fo the big 3 (and by seeing the post on the forums/bugreports, i guess even the big two or sometimes even the big one).

I often find myself setting up obscure toolchains (not referring to gnu here) that requires a load of maintenance to even get them to work (or usually, don't even work at all) or find/try alternative approaches that might be able to speed things up.

Even when you find targets that have nothing to do with windows, linux or mac, there are those developers that still find a way to restrict themselves to compile their toolchain/utils with MSVC or other platform specific tools.

In this day and age you need to have a fair understanding and/or have several different installations of .net, java, python, ruby, lua, VC, mingw, cygwin, etc. to even get you started. And that is only to be able to have a (cross-)toolchain working for you. Thank heavens for VM's.

The hardship that belongs to choosing 'obscure' targets, i guess :-)

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: how to: Linux resource file in Lazarus - free pascal ?
« Reply #8 on: April 26, 2017, 05:11:26 pm »
I understand your frustration though...
...snip...
The hardship that belongs to choosing 'obscure' targets, i guess :-)
I wouldn't consider Linux an "obscure target". Neither FreeBSD to be honest. They are THE most used platforms on the Internet.

What boggles my mind (and frustrates me) is that the Free Pascal team did so well with the Compiler, but yet left out other vital components that are normally associated with a compiler. Like a Debugger, and in this case a Resource Compiler. They (the FPC team) chose to implement resources in a Windows centric way (yet still cross-platform), yet don't supply a resource compiler for the multiple other platforms that the FPC project supports (and as for as I know, all support resource as implement in FPC {ELF and COFF binaries}). I'm not even talking about cross-compiling here. And then they supply a windres binary in the official Windows installer, but don't supply it for other official target installers like Linux, FreeBSD, OSX etc. Biased and inconsistent if you ask me.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

 

TinyPortal © 2005-2018