SOLVED Free pascal resource file question. list resources of in .res file lazarus / 66-Unix ---------------------------------------------------------------------- muller59 · 2020-08-15 11:26 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 · 2020-08-15 17:05 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 · 2020-08-15 18:58 Quote from: lucamar on August 15, 2020, 07:05:33 pmUse 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. There are some relevant code samples in fclres.chm too. ---------------------------------------------------------------------- muller59 · 2020-08-16 16:25 Thanks Friends, i will look into that. Much appreciated. ---------------------------------------------------------------------- muller59 · 2020-08-17 11:49 @ lucamar i tried and failed. i did Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 ---------------------------------------------------------------------- lucamar · 2020-08-17 12:51 AFAICT TResources has no method called GetName. Try with this (untested, might or might not work): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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.Items[i].Name);  end;   resources.Free;  reader.Free;  inFile.Free;end. ---------------------------------------------------------------------- muller59 · 2020-08-17 12:54 Never mind, found an answer resources.Name.Name does the trick, a bit counter-intuitive IMHO ---------------------------------------------------------------------- TRon · 2020-08-17 13:23 Quote from: muller59 on August 17, 2020, 02:54:22 pmresources.Name.Name does the trick, a bit counter-intuitive IMHO Yes and no  afaik there are two type of resources as in those that are identified by their name and those that are identified by ID. That is probably why it was implemented the way it is. The counter-intuitive part as far as I am concerned stems from both properties name and _type pointing to class TResourceDesc. That is unless there exists resources that actually can be identified (as in: stored) in both ways. BTW: You both seem to load the loader manually while I was lazy and included all the individual reader units so I wouldn't have to. No idea what should be the way to actually use it though, or if that even matters. Edit: my bad. the type property is the resource listing while name property for the actual resource. It is always using either ID or name as indicated by the DescType (sub)property. Code: [Select]Found 96 resources in file /home/tron/projects/bunch_of_resources res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 1 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 2 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 3 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 4 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 5 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 6 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 7 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 8 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 9 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 10 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 11 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 12 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 13 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 14 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 15 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 16 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 17 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 18 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 19 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 20 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 21 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 22 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 23 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 24 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 25 res.Type.ID   =   1 (RT_CURSOR), res.Name.ID   = 26 res.Type.ID   =   3 (RT_ICON), res.Name.ID   = 1 res.Type.ID   =   3 (RT_ICON), res.Name.ID   = 2 res.Type.ID   =   3 (RT_ICON), res.Name.ID   = 3 res.Type.ID   =   3 (RT_ICON), res.Name.ID   = 4 res.Type.ID   =   3 (RT_ICON), res.Name.ID   = 5 res.Type.ID   =   3 (RT_ICON), res.Name.ID   = 6 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_ABORT res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_ABORT_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_ABORT_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_ALL res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_ALL_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_ALL_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_ARROWRIGHT res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_ARROWRIGHT_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_ARROWRIGHT_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_CANCEL res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_CANCEL_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_CANCEL_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_CLOSE res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_CLOSE_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_CLOSE_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_HELP res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_HELP_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_HELP_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_IGNORE res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_IGNORE_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_IGNORE_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_NO res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_NO_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_NO_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_OK res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_OK_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_OK_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_RETRY res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_RETRY_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_RETRY_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_YES res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_YES_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = BTN_YES_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = DIALOG_CONFIRMATION res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = DIALOG_ERROR res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = DIALOG_INFORMATION res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = DIALOG_SHIELD res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = DIALOG_WARNING res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = SORTASC res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = SORTASC_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = SORTASC_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = SORTASC_50 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = SORTASC_75 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = SORTDESC res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = SORTDESC_150 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = SORTDESC_200 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = SORTDESC_50 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = SORTDESC_75 res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = TFRMCLOCKS res.Type.ID   =  10 (RT_RCDATA), res.Name.Name = TFRMMAIN res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_1 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_10 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_12 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_13 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_14 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_15 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_16 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_17 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_18 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_20 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_21 res.Type.ID   =  12 (RT_GROUP_CURSOR), res.Name.Name = CUR_22 res.Type.ID   =  14 (RT_GROUP_ICON), res.Name.Name = MAINICON res.Type.ID   =  24 (RT_MANIFEST), res.Name.ID   = 1