Recent

Author Topic: Loading text data from a resource file [SOLVED]  (Read 549 times)

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Loading text data from a resource file [SOLVED]
« on: September 18, 2024, 01:10:53 am »
* Mac Mini M1 (silicon)
* macOS 14.6.1
* Lazarus 3.4
* FPC 3.2.2

I've been asking over n the Mac channels, but I figure I should ask here to reach a bigger audience...

I have a large text file named "OsmosePresets.txt" like this but much bigger (~520 lines)...
Code: Text  [Select][+][-]
  1. bass
  2. 30, 1, "acid bass", "aggressive + analog + distorted + stereo"
  3. 30, 2, "acouskop", "acoustic + distorted + fm + shaking"
  4. 30, 31, "bass distosine", "acoustic + synthetic"
  5. 30, 32, "bass monster", "analog + distorted + portamento + synthetic"
  6. 30, 74, "chordead", "analog + chords"
  7. 30, 108, "deep corners", "analog + chords"
  8. 30, 112, "dirt acid", "analog + distorted"
  9. 30, 119, "doubleslap", "acoustic + shaking + warm + woody"
  10. 30, 127, "edgy fm", "fm"
  11. 31, 3, "eighty neon", "analog"
  12. 31, 5, "electric bass 1", "acoustic + electric"
  13. 31, 6, "electric bass 2", "acoustic + electric"
  14. 31, 29, "fat model d", "analog + big + noise + portamento + warm"
  15. 31, 36, "flunkly", "analog"
  16. 31, 43, "fm darkness", "aggressive + big + dark + digital + dry + ensemble + fm + noise"
  17. 31, 44, "fm doublebass", "clean + fm + portamento"
  18. 31, 50, "fm slapman", "bright + digital + fm + metallic + stereo"
  19. 31, 54, "forgotten animal", "analog + fm + portamento"
  20. 31, 55, "forty eight db", "analog + distorted"
  21. 31, 56, "fourad", "analog + distorted"
  22. 31, 57, "fretless bass", "acoustic + portamento"
  23. 31, 76, "grittysaw", "analog + distorted"
  24. 31, 86, "hollowrez", "analog"
  25. 31, 107, "juknow that bass", "analog + big + clean + simple + soft + stereo"
  26. 31, 121, "kinespeech", "analog + vocal"
  27. 32, 5, "lacous bass", "acoustic + portamento"
  28. 32, 7, "ladder bass", "analog + lfo + synthetic"
  29. 32, 58, "night bass", "analog + portamento"
  30. 32, 92, "outspoken", "analog"
  31. 32, 109, "piercing bass", "aggressive + big + dark + digital"
  32. 32, 114, "pl-bass", "analog + dry + warm"
  33. 32, 126, "pulzz", "analog"
  34. 33, 5, "reesotto", "aggressive + digital"
  35. 33, 6, "reesy rider", "aggressive + analog + distorted + stereo"
  36. 33, 19, "rusty bass", "dark + digital + fm + soft"
  37. 33, 20, "rusty square", "analog + distorted"
  38. 33, 39, "simpledecay", "analog + distorted"
  39. 33, 41, "simplerez", "analog"
  40. 33, 48, "smooth operator", "acoustic + fm"
  41. 33, 49, "solid square", "analog"
  42. 33, 68, "steroids", "analog + noise"
  43. 33, 74, "sub bass 1", "analog"
  44. 33, 75, "subway", "analog + clean + dark + fm + simple"
  45. 33, 77, "syncat", "analog"
  46. 33, 95, "thrilla bass", "analog + dry"
  47. 33, 114, "velsquare", "analog"
  48. 33, 119, "vintage wide bass", "analog + big + dark + portamento + soft + stereo + warm"
  49. 33, 125, "walking blues", "acoustic"
  50. 33, 127, "wallface", "digital + fm + portamento"
  51.  

I have made a file called "OsmosePresets.rc" which consists of...
Code: Text  [Select][+][-]
  1. OsmosePresets RCDATA OsmosePresets.txt
  2.  

I then produced a ".res" file by running...
Code: Bash  [Select][+][-]
  1. fpcres OsmosePresets.rc -o OsmosePresets.res -of res
  2.  

This produced "OsmosePresets.res" which consists of a file with a few control characters as well as the recognisable data...
Code: Text  [Select][+][-]
  1. ���� ���ˇˇ��ˇˇ������������������»_��8���ˇˇ
  2. �O�S�M�O�S�E�P�R�E�S�E�T�S�������     ��������bass
  3. 30, 1, "acid bass", "aggressive + analog + distorted + stereo"
  4. 30, 2, "acouskop", "acoustic + distorted + fm + shaking"
  5. 30, 31, "bass distosine", "acoustic + synthetic"
  6. 30, 32, "bass monster", "analog + distorted + portamento + synthetic"
  7. 30, 74, "chordead", "analog + chords"
  8. 30, 108, "deep corners", "analog + chords"
  9. 30, 112, "dirt acid", "analog + distorted"
  10. 30, 119, "doubleslap", "acoustic + shaking + warm + woody"
  11. 30, 127, "edgy fm", "fm"
  12. 31, 3, "eighty neon", "analog"
  13. 31, 5, "electric bass 1", "acoustic + electric"
  14. 31, 6, "electric bass 2", "acoustic + electric"
  15. 31, 29, "fat model d", "analog + big + noise + portamento + warm"
  16. 31, 36, "flunkly", "analog"
  17. 31, 43, "fm darkness", "aggressive + big + dark + digital + dry + ensemble + fm + noise"
  18.  

My problem is then how to add this resource to my project so I can the extract the data via a TResourceStream.

If I reference "OsmosePresets.res" in my form unit code, like this...
Code: Pascal  [Select][+][-]
  1. implementation
  2.  
  3. {$R 'OsmosePresets.res'}
  4. {$R *.lfm}
  5.  

I find that I have to remove the "{$ *.res}" in the project source, otherwise I get a build error of duplicate resources.
So I can build the project, but there are two problems. One, the program fails to find the "OsmosePresets" resource, and two, the act of building the project seems to cause a new version of the "OsmosePresets.res" file to be generated, with radically different content...
Code: Text  [Select][+][-]
  1. ���� ���ˇˇ��ˇˇ������������������‡�� ���ˇˇ�ˇˇ���������������<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  3.  <assemblyIdentity version="1.0.0.0" processorArchitecture="*" name="CompanyName.ProductName.AppName" type="win32"/>
  4.  <description>Your application description.</description>
  5.  <dependency>
  6.   <dependentAssembly>
  7.    <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="*" publicKeyToken="6595b64144ccf1df" language="*"/>
  8.   </dependentAssembly>
  9.  </dependency>
  10.  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
  11.   <security>
  12.    <requestedPrivileges>
  13.     <requestedExecutionLevel level="asInvoker" uiAccess="false"/>
  14.    </requestedPrivileges>
  15.   </security>
  16.  </trustInfo>
  17.  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
  18.   <application>
  19.    <!-- Windows Vista -->
  20.    <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
  21.    <!-- Windows 7 -->
  22.    <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
  23.    <!-- Windows 8 -->
  24.    <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
  25.    <!-- Windows 8.1 -->
  26.    <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
  27.    <!-- Windows 10 -->
  28.    <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
  29.    </application>
  30.   </compatibility>
  31.  <asmv3:application xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
  32.   <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">
  33.    <dpiAware>True</dpiAware>
  34.   </asmv3:windowsSettings>
  35.   <asmv3:windowsSettings xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">
  36.    
  37.    <longPathAware>false</longPathAware>
  38.    
  39.   </asmv3:windowsSettings>
  40.  </asmv3:application>
  41. </assembly>v���0���ˇˇ�M�A�I�N�I�C�O�N���������������������������� �”ö���ÄÄ��� �(��00��� �®%���((��� �h���  ��� �®������ �à    ������ �∏������ �h�����”ö�� ���ˇˇ�ˇˇ���������������âPNG
  42. 
  43. ���
  44. IHDR���������\r®f�� �IDATxúÏΩwò«u'˙;’·∆…¿`gêH$$AÄ3EôT¥-Y‡$˚=≤l}ˆÁ]{˝V˚ŸJfi晴⁄œ~íÉ,”≤(*ë"-1I        fÄ$í�AÄÄ»Lû∫νQ°´”Ωw0ë‰|sowU˜È™˙ùTß™ÅYö•Yö•Yö•Yö•Yö•Yö•Yö•Yö•Yö•Yö•Yö•Yö•Yö•YzãM7≥4~Ífi¯â˘∞X˘‘¯Û8°É@úc.�:�^�µ�8\�yâ! ‚8Ôáh¿iù¯)~ö8NÏ8g¸�<ˇ¿¡∑ù¬«ú•I†Y&°yÎo.2÷Ó˚|¬z_        PÄ�Y¢z]…°∫;≠(ÁÒ≤©WÖGº‡�àøB>Ì"∆vé˙Óãoϯ˙p›áö•ißY0©Á⁄€≤‘_›ƒâ]Œ     ó«ñ ó‰üì7�¢H◊v¥å¿9◊G8@<r>rŒ}pÏÁÑùƒ±ùè˙Ml˚Å≠fl≠sÛYöbö�3Äz.º≠VıZ"v∂�ÿHDÆYF[Aö#�;§ êÅ√ ¢˙⁄_\3Ù8'„;H¸Â‚ãø8≈UI},tmŒÀ�∂—„‹˜∂¡≥∑xÓõgm£Yöö�”DK6›∫ñ˘¸}úNÆ6oÇùCÄY`&ê>F‚?—ëÚØ8'Îò¬¿D?ùo`^àÇ^_ÇûK∞ìyåã£úKQ è  ‚BÅsÓ·9<»|‹ÛÍéo=·bñ¶Äf¿—∆çütN≥Úı‡˛M�fiCD]Í\Hªì“‘‡ 0&¡L åÄ3  ~Àv`eÛ∞sXôò„Ä9YÒ◊v¡ú òe0ÀůB`Ã�¯æ¯�áÔU�¯^~πøZÜ_)√Øñ‡W*®é¡But~µpüspÓ√˜ï0ëflµPPBBY
  45. aÅ Íc∫ó˚˛ùö=Ñ≠[´S–-o{ö�ìJüeÀ6æzπœ¯M‡Ï#Dò'é S]h¯@ì3Ü@ª3 vF` ≥‡‰Ûp
  46. ≠p
  47. -p
  48. Õ∞2Xπl«”Ç¡ ¶°Äxƒåxhç¯�‡s¯P2BûP©î‡ç √Be®ï°≥®ı°22 Ó{9áÔK!‡ A‡ka‡áÇé"®®‹fiÀ9ÓaƒÔl˜s?›±„Îï…Ï•∑3Õ
  49.  

I asked the original question on the Mac channel, but I thought it would be useful to find out how everyone else loads text data from resource files...

I've also seen posts suggesting that the Resources dialog within Project Options is the best way to add resource data, but I've found that the load dialog only permits the additions of graphics files, which is of no use to me!

What glaringly obvious thing am I missing here>
« Last Edit: September 18, 2024, 04:01:48 pm by carl_caulkett »
"It builds... ship it!"

alpine

  • Hero Member
  • *****
  • Posts: 1271
Re: Loading text data from a resource file
« Reply #1 on: September 18, 2024, 11:30:41 am »
I asked the original question on the Mac channel, but I thought it would be useful to find out how everyone else loads text data from resource files...
I often load *.po files from a resources.

I've also seen posts suggesting that the Resources dialog within Project Options is the best way to add resource data, but I've found that the load dialog only permits the additions of graphics files, which is of no use to me!
That is not true. You can select any file and then change the type of the resource into Options/Resources dialog. I'm not using Mac but I doubt the things are different there.

Quote
What glaringly obvious thing am I missing here>
It seems that you're using the same name OsmosePresets for the project as the OsmosePresets.res file looks overwritten by the subsequent build.  The build always produces a <ProjectName>.res file containing the main icon and some other crap (at least on the platforms that I'm using).

Quote
One, the program fails to find the "OsmosePresets" resource
Try naming it in uppercase and look for it also with the same uppercase string.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Loading text data from a resource file
« Reply #2 on: September 18, 2024, 02:42:43 pm »
I've also seen posts suggesting that the Resources dialog within Project Options is the best way to add resource data, but I've found that the load dialog only permits the additions of graphics files, which is of no use to me!
That is not true. You can select any file and then change the type of the resource into Options/Resources dialog. I'm not using Mac but I doubt the things are different there.

Thanks for the reply! See the attachment... the greyed out filenames indicate that the files cannot be added to the resource list. Note the one thing in common that all of the bright white filenames have...
On my Mac, I'm afraid it is very much true  ;)
"It builds... ship it!"

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Loading text data from a resource file
« Reply #3 on: September 18, 2024, 02:58:56 pm »
Thanks for the reply! See the attachment... the greyed out filenames indicate that the files cannot be added to the resource list. Note the one thing in common that all of the bright white filenames have...
On my Mac, I'm afraid it is very much true  ;)

But never mind all that! The uppercase name change made it work 😃
Thanks for the suggestion 🙏🏽
« Last Edit: September 18, 2024, 04:02:52 pm by carl_caulkett »
"It builds... ship it!"

alpine

  • Hero Member
  • *****
  • Posts: 1271
Re: Loading text data from a resource file [SOLVED]
« Reply #4 on: September 18, 2024, 05:28:01 pm »
Quote
Thanks for the reply! See the attachment... the greyed out filenames indicate that the files cannot be added to the resource list. Note the one thing in common that all of the bright white filenames have...
On my Mac, I'm afraid it is very much true  ;)
The file open dialog should have a filter drop-down. Initially it is for graphic (*.png;*.xpm;...). When you change it to All files (*) then you can select  anything you want.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Loading text data from a resource file [SOLVED]
« Reply #5 on: September 18, 2024, 05:33:34 pm »
Quote
Thanks for the reply! See the attachment... the greyed out filenames indicate that the files cannot be added to the resource list. Note the one thing in common that all of the bright white filenames have...
On my Mac, I'm afraid it is very much true  ;)
The file open dialog should have a filter drop-down. Initially it is for graphic (*.png;*.xpm;...). When you change it to All files (*) then you can select  anything you want.

I apologise! On my machine the filter drop-down is fiendishly hidden behind a button called "Show Options"! I thought I had already checked it and disregarded what I found there. Apparently not  ;)
"It builds... ship it!"

alpine

  • Hero Member
  • *****
  • Posts: 1271
Re: Loading text data from a resource file [SOLVED]
« Reply #6 on: September 18, 2024, 06:21:23 pm »
No need to apologize. When I first came across this I was confused too, since other IDEs usually have a drop-down in the place of the single "+ Add" button here, i.e. you first select the resource type and then the file dialog opens with the corresponding file mask.
It took me a while to realize that the filter could be changed, and only because I was convinced that there must be a way to do it.

Your trouble is indicative that there is room for IDE improvement here. Simply replacing the "Add" with "Add ICON", "Add CURSOR", ... , "Add RCDATA" and setting the dialog filter could save you hours of puzzlement, I guess.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

carl_caulkett

  • Hero Member
  • *****
  • Posts: 635
Re: Loading text data from a resource file [SOLVED]
« Reply #7 on: September 18, 2024, 06:23:19 pm »
👍
"It builds... ship it!"

TRon

  • Hero Member
  • *****
  • Posts: 3520
Re: Loading text data from a resource file [SOLVED]
« Reply #8 on: September 18, 2024, 06:24:49 pm »
Your trouble is indicative that there is room for IDE improvement here. Simply replacing the "Add" with "Add ICON", "Add CURSOR", ... , "Add RCDATA" and setting the dialog filter could save you hours of puzzlement, I guess.
I fell into the same trap in carl's other thread (on the same subject) so yes I guess it does leave room for improvement.
This tagline is powered by AI

alpine

  • Hero Member
  • *****
  • Posts: 1271
Re: Loading text data from a resource file [SOLVED]
« Reply #9 on: September 18, 2024, 06:47:01 pm »
Another thing I find confusing in the same page is that Resource (name?) and Type are both clear unless you add a line to the list, i.e. they're attributes of the resource and initially you don't have a clue they can be changed.

And the {$I *.res} directive shouldn't be deleted from the main source but the additional resources must reside in separate project folder, e.g. ./res, but that is just IMHO.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

 

TinyPortal © 2005-2018