Forum > Unix

SOLVED Free pascal resource file question. list resources of <type> in .res file

(1/2) > >>

muller59:
using fpc 3.0.4 i create a program that uses data from a FPC resource file (.res).
i can read the individual resources like this fine

ResNam : string;
ResNam := 'RESOURCENAME';
S := TResourceStream.Create(HInstance, ResNam, RT_RCDATA);
F := TFileStream.Create(sPoPath_nl + '/' + sPoFile_nl, fmCreate);
F.CopyFrom(S, S.Size);

what i need is a function to read all resource names of type RT_RCDATA from the file. the documentation is not really clear about this (imho).

any hint will be appreciated

lucamar:
Use a TResources object (unit resource of package fcl-res): load it with LoadFromFile() or LoadFromStream() and traverse its Items[].

That's the basic way to do it.

dsiders:

--- Quote from: lucamar on August 15, 2020, 07:05:33 pm ---Use a TResources object (unit resource of package fcl-res): load it with LoadFromFile() or LoadFromStream() and traverse its Items[].

That's the basic way to do it.

--- End quote ---

There are some relevant code samples in fclres.chm too.

muller59:
Thanks Friends, i will look into that.
Much appreciated.

muller59:
@ lucamar
i tried and failed.

i did


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program reslist; {$mode objfpc}{$H+} uses  Classes, SysUtils, resource,// You need to specify which resources you want to be able to read.// The units initialize themselves and register themselves as readers....  resreader; var  resources : TResources;  reader : TAbstractResourceReader;  inFile : TFileStream;  i : integer; {$R *.res} begin  resources:=TResources.Create;  inFile:=TFileStream.Create(paramstr(1), fmOpenRead );  // Use FindReader to let TResources find the appropriate reader for the file  reader:=TResources.FindReader(inFile);  writeln('Selected reader: ',reader.Description);  resources.LoadFromStream(inFile,reader);   for i:=0 to resources.Count-1 do  begin    //resread := Tabtractresourcereader.create    writeln(inttostr(i));    writeln(resources.getname(resources.Items[i]));  <<< source of error  end;   resources.Free;  reader.Free;  inFile.Free;end.  

compilation error: reslist.lpr(31,20) Error: identifier idents no member "getname" 

given this program, i can see there are 9 resources in the resource file if i comment out the error line, but i cannot get to the names.
i trawled thought the resources source of fpc, but i get lost in the class attribute types...
can anyone help me get the correct code to print the resource names.
i have attached the test resource list as well.

as always, thanks in advance for your help

Navigation

[0] Message Index

[#] Next page

Go to full version