resource.xml 133 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <fpdoc-descriptions>
  3. <package name="fcl-res">
  4. <topic name="Format of resources in object files">
  5. <short>Format of resources in object files</short>
  6. <descr>
  7. <p><b>Introduction</b></p>
  8. <p>This appendix describes the format in which resources are stored in object files. This doesn't apply to PECOFF file format, where a format already exists and is well described in documentation from Microsoft.</p>
  9. <p>On Microsoft Windows, resources are natively supported by the operating system. On other systems, Free Pascal RTL provides access to resources, which are embedded in the executable file in the format that is here described.</p>
  10. <p>This appendix doesn't describe a particular object file format implementation (e.g. ELF or Mach-O), but the layout of the sections involved in supporting resources: the way these sections are actually laid out on a file are subject to the rules of the hosting object file format.</p>
  11. <p>For external resource file details, see <link id ="externaltypes.Description of external resource file format">Description of external resource file format</link></p>
  12. <p><b>Conventions</b></p>
  13. <p>In this document, data sizes are specified with pascal-style data types. They are the following:</p>
  14. <table>
  15. <th><td>Name</td><td>Meaning</td></th>
  16. <tr><td><var>longword</var></td><td>Unsigned 32 bit integer.</td></tr>
  17. <tr><td><var>ptruint</var></td><td>Unsigned integer of the size of a pointer</td></tr>
  18. </table>
  19. <p>Byte order is the one of the target machine.</p>
  20. <p>All data structures in the sections must be aligned on machine boundaries (4 bytes for 32 bit machines, 8 bytes for 64 bit machines).</p>
  21. <p>Note that all pointers must be valid at runtime. This means that relocations must be written to the object file so that the linker can relocate pointers to the addresses they will have at runtime. Note also that pointers to strings are really pointers, and not offsets to the beginning of the string table.</p>
  22. <p><b>Resource sections</b></p>
  23. <p>Free Pascal uses two sections to store resource information:</p>
  24. <ul>
  25. <li><var>fpc.resources</var>. This is a data section that contains all required structures. It must be writable.</li>
  26. <li><var>fpc.rehandles</var>. This is a bss section whose size must be equal to <var>(total number of resources)*(size of pointer)</var>. It must be writable.</li>
  27. </ul>
  28. <p>The rest of this chapter will describe the contents of <var>fpc.resources</var> section.</p>
  29. <p><b>Resource section layout</b></p>
  30. <p>The <var>fpc.resources</var> section consists of these parts:</p>
  31. <ul>
  32. <li>The initial header</li>
  33. <li>The resource tree, in the form of nodes</li>
  34. <li>The string table, which can be optional</li>
  35. <li>The resource data</li>
  36. </ul>
  37. <p><b>The initial header</b></p>
  38. <p>The <var>fpc.resources</var> section starts with this header:</p>
  39. <table>
  40. <th><td>Name</td><td>Offset</td><td>Length</td><td>Description</td></th>
  41. <tr>
  42. <td>rootptr</td>
  43. <td>0</td>
  44. <td>ptruint</td>
  45. <td>Pointer to the root node.</td>
  46. </tr>
  47. <tr>
  48. <td>count</td>
  49. <td>4/8</td>
  50. <td>longword</td>
  51. <td>Total number of resources.</td>
  52. </tr>
  53. <tr>
  54. <td>usedhandles</td>
  55. <td>8/12</td>
  56. <td>longword</td>
  57. <td>Used at runtime. Set to zero in object files.</td>
  58. </tr>
  59. <tr>
  60. <td>handles</td>
  61. <td>12/16</td>
  62. <td>ptruint</td>
  63. <td>Pointer to the first byte of <var>fpc.reshandles</var> section.</td>
  64. </tr>
  65. </table>
  66. <p><b>The resource tree</b></p>
  67. <p>Immediately following the initial header, the resource tree comes. It is made up by nodes that represent resource types, names and language ids.</p>
  68. <p>Data is organized so that resource information (type, name and language id) is represented by a tree: root node contains resource types, that in turn contain resource names, which contain language ids, which describe resource data.</p>
  69. <p>Given a node, its sub-nodes are ordered as follows:</p>
  70. <ul>
  71. <li>First the "named" nodes (nodes that use a string as identifier) come, then the id ones (nodes that use an integer as identifier).</li>
  72. <li>Named nodes are alphabetically sorted, in ascending order.</li>
  73. <li>Id nodes are sorted in ascending order.</li>
  74. </ul>
  75. <p>In the file, all sub-nodes of a node are written in the order described above. Then, all sub-nodes of the first sub-node are written, and so on.</p>
  76. <p><b>Example:</b></p>
  77. <p>There are three resources:</p>
  78. <ol>
  79. <li>a <var>BITMAP</var> resource with name <var>MYBITMAP</var> and language id <var>$0409</var></li>
  80. <li>a <var>BITMAP</var> resource with name <var>1</var> and language id <var>0</var></li>
  81. <li>a resource with type <var>MYTYPE</var> and name <var>1</var> and language id <var>0</var></li>
  82. </ol>
  83. <p>Nodes are laid out this way (note that <var>BITMAP</var> resources have type <var>2</var>):</p>
  84. <pre>
  85. root | MYTYPE 2 | 1 | 0 | MYBITMAP 1 | $0409 | 0
  86. </pre>
  87. <p>That is, types (<var>MYTYPE</var> is a string, so it comes before <var>2</var> which is <var>BITMAP</var>), then names for <var>MYTYPE</var> (<var>1</var>), then language id for resource 3 (<var>0</var>), then names for <var>BITMAP</var> (<var>MYBITMAP</var> and <var>1</var>), then language id for resource 1 (<var>$0409</var>), then language id for resource 2 (<var>0</var>).</p>
  88. <p><b>Node format</b></p>
  89. <table>
  90. <th><td>Name</td><td>Offset</td><td>Length</td><td>Description</td></th>
  91. <tr>
  92. <td>nameid</td>
  93. <td>0</td>
  94. <td>ptruint</td>
  95. <td>name pointer, integer id or language id</td>
  96. </tr>
  97. <tr>
  98. <td>ncount</td>
  99. <td>4/8</td>
  100. <td>longword</td>
  101. <td>named sub-nodes count</td>
  102. </tr>
  103. <tr>
  104. <td>idcountsize</td>
  105. <td>8/12</td>
  106. <td>longword</td>
  107. <td>id sub-nodes count or resource size</td>
  108. </tr>
  109. <tr>
  110. <td>subptr</td>
  111. <td>12/16</td>
  112. <td>ptruint</td>
  113. <td>pointer to first sub-node</td>
  114. </tr>
  115. </table>
  116. <p>If the node is identified by a string, <var>nameid</var> is a pointer to the null-terminated string holding the name. If it is identified by an id, <var>nameid</var> is that id. Language id nodes are always identified by and ID.</p>
  117. <p><var>ncount</var> is the number of named sub-nodes of this node (nodes that are identified by a string).</p>
  118. <p><var>idcountsize</var> is the number of id sub-nodes of this node (nodes that are identified by an integer id). For language id nodes, this field holds the size of the resource data.</p>
  119. <p><var>subptr</var> is an pointer to the first subnode of this node. Note that it allows to access every subnode of this node, since subnodes of a node always come one after the other. For language id nodes, <var>subptr</var> is the pointer to the resource data.</p>
  120. <p><b>The string table</b></p>
  121. <p>The string table is used to store strings used for resource types and names. If all resources use integer ids for name and types, it may not be present in the file.</p>
  122. <p>The string table simply contains null-terminated strings, one after the other.</p>
  123. <p>If present, the string table always contains a <var>0</var> (zero) at the beginning. This way, the empty string is located at the first byte of the string table.</p>
  124. <p><b>The resource data</b></p>
  125. <p>This part of the file contains raw resource data. As written before, all data structures must be aligned on machine boundaries, so if a resource data size is not a multiple of 4 (for 32 bit machines) or 8 (for 64 bit machines), bytes of padding must be inserted after that resource data.</p>
  126. <p><b>Exported symbols</b></p>
  127. <p>Object files containing resources must export a pointer to the first byte of <var>fpc.resources</var> section. The name of this symbol is <var>FPC_RESSYMBOL</var>.</p>
  128. <p><b>Mach-O specific notes</b></p>
  129. <p><var>fpc.resources</var> and <var>fpc.reshandles</var> sections are to be contained in a <var>__DATA</var> segment.</p>
  130. </descr>
  131. </topic>
  132. <topic name="How to implement a new resource writer">
  133. <short>How to implement a new resource writer</short>
  134. <descr>
  135. <remark>This chapter assumes you have some experience in using this library.</remark>
  136. <p>We'll see how to implement a writer for a new resource file format. A resource writer is a descendant of <link id="resource.TAbstractResourceWriter">TAbstractResourceWriter</link>, and it's usually implemented in a unit named <var>namewriter</var>, where <i>name</i> is file format name.</p>
  137. <p>Suppose we must write a writer for file format <i>foo</i>; we could start with a unit like this:</p>
  138. <code>
  139. unit foowriter;
  140. {$MODE OBJFPC} {$H+}
  141. interface
  142. uses
  143. Classes, SysUtils, resource;
  144. type
  145. TFooResourceWriter = class (TAbstractResourceWriter)
  146. protected
  147. function GetExtensions : string; override;
  148. function GetDescription : string; override;
  149. procedure Write(aResources : TResources; aStream : TStream); override;
  150. public
  151. constructor Create; override;
  152. end;
  153. implementation
  154. function TFooResourceWriter.GetExtensions: string;
  155. begin
  156. end;
  157. function TFooResourceWriter.GetDescription: string;
  158. begin
  159. end;
  160. procedure TFooResourceWriter.Write(aResources: TResources; aStream: TStream);
  161. begin
  162. end;
  163. constructor TFooResourceWriter.Create;
  164. begin
  165. end;
  166. initialization
  167. TResources.RegisterWriter('.foo',TFooResourceWriter);
  168. end.
  169. </code>
  170. <p>Note that in the <var>initialization</var> section, <var>TFooResourceWriter</var> is registered for extension <var>.foo</var>.</p>
  171. <p>We must implement abstract methods of <link id="resource.TAbstractResourceWriter">TAbstractResourceWriter</link>. Let's start with the simpler ones, <link id="resource.TAbstractResourceWriter.GetExtensions">GetExtensions</link> and <link id="resource.TAbstractResourceWriter.GetDescription">GetDescription</link>.</p>
  172. <code>
  173. function TFooResourceWriter.GetExtensions: string;
  174. begin
  175. Result:='.foo';
  176. end;
  177. function TFooResourceWriter.GetDescription: string;
  178. begin
  179. Result:='FOO resource writer';
  180. end;
  181. </code>
  182. <p>Now let's see <link id="resource.TAbstractResourceWriter.Write">Write</link>. This method must write all resources in the <link id="resource.TResources">TResources</link> object to the stream.</p>
  183. <p>Suppose that our foo format is very simple:</p>
  184. <ul>
  185. <li>the header is made by a 4-byte signature (<var>FOO*</var>), a <var>longword</var> holding the number of resources in the file, and other 8 bytes of padding.</li>
  186. <li><p>each resource has a 16-byte header containing:</p>
  187. <ul>
  188. <li>a longword for the resource type (only IDs are allowed for types)</li>
  189. <li>a longword for the resource name (only IDs are allowed for names)</li>
  190. <li>a longword for the language ID</li>
  191. <li>a longword for the size of the resource data</li>
  192. </ul>
  193. </li>
  194. <li>
  195. after the resource header immediately comes the resource data, possibly padded so that it ends on a 4 byte boundary.
  196. </li>
  197. <li>
  198. file format is little-endian
  199. </li>
  200. </ul>
  201. <p>Our <link id="resource.TAbstractResourceWriter.Write">Write</link> method could be something like this:</p>
  202. <code>
  203. procedure TFooResourceWriter.Write(aResources: TResources; aStream: TStream);
  204. var i : integer;
  205. begin
  206. WriteFileHeader(aStream,aResources);
  207. for i:=0 to aResources.Count-1 do
  208. WriteResource(aStream,aResources[i]);
  209. end;
  210. </code>
  211. <p>So we must implement <var>WriteFileHeader</var>, which writes the 16-byte file header, and <var>WriteResource</var>, which writes a single resource with its header.</p>
  212. <p>Let's start from the first one:</p>
  213. <code>
  214. procedure TFooResourceWriter.WriteFileHeader(aStream: TStream; aResources: TResources);
  215. var signature : array[0..3] of char;
  216. rescount : longword;
  217. padding : qword;
  218. begin
  219. signature:='FOO*';
  220. rescount:=aResources.Count;
  221. padding:=0;
  222. aStream.WriteBuffer(signature[0],4);
  223. aStream.WriteBuffer(rescount,sizeof(rescount));
  224. aStream.WriteBuffer(padding,sizeof(padding));
  225. end;
  226. </code>
  227. <p>This code simply writes the file header as defined in foo format. Note that if we are running on a big endian system we should swap bytes before writing, e.g. calling <var>SwapEndian</var> function, but for simplicity this is omitted.</p>
  228. <p>Now <var>WriteResource</var> comes. This method could be like this:</p>
  229. <code>
  230. procedure TFooResourceWriter.WriteResource(aStream: TStream; aResource: TAbstractResource);
  231. var aType : longword;
  232. aName : longword;
  233. aLangID : longword;
  234. aDataSize : longword;
  235. begin
  236. aType:=aResource._Type.ID;
  237. aName:=aResource.Name.ID;
  238. aLangID:=aResource.LangID;
  239. aDataSize:=aResource.RawData.Size;
  240. //write resource header
  241. aStream.WriteBuffer(aType,sizeof(aType));
  242. aStream.WriteBuffer(aName,sizeof(aName));
  243. aStream.WriteBuffer(aLangID,sizeof(aLangID));
  244. aStream.WriteBuffer(aDataSize,sizeof(aDataSize));
  245. //write resource data
  246. aResource.RawData.Position:=0;
  247. aStream.CopyFrom(aResource.RawData,aResource.RawData.Size);
  248. //align data so that it ends on a 4-byte boundary
  249. Align4Bytes(aStream);
  250. end;
  251. </code>
  252. <p>We write the 16-byte resource header, and then resource data. Note that if resources have been loaded from a stream and the user didn't modify resource data, we are copying data directly from the original stream.</p>
  253. <p><var>Align4Bytes</var> is a private method (not shown for simplicity) that writes some padding bytes to the stream if needed, since FOO file format specifies that resource data must be padded to end on a 4 byte boundary. Again, we didn't consider endianess for simplicity. And finally, note that foo format only supports IDs for types and names, so if one of them is a name (that is, a string) this code might cause exceptions to be raised.</p>
  254. <p><b>Note:</b> More complex file formats store resources in a tree hierarchy; since <link id="resource.TResources">TResources</link> internally stores resources in this way too, a writer can choose to acquire a reference to the internal tree used by the <link id="resource.TResources">TResources</link> object (see <link id="resource.TAbstractResourceWriter.GetTree">TAbstractResourceWriter.GetTree</link>) and use it directly. For these file formats resources can be written faster, since there is no overhead involved in building a separate resource tree in the writer.</p>
  255. <p>That's all. Now you should be able to create a real resource writer.</p>
  256. </descr>
  257. </topic>
  258. <topic name="How to implement a new resource reader">
  259. <short>How to implement a new resource reader</short>
  260. <descr>
  261. <remark>This chapter assumes you have some experience in using this library.</remark>
  262. <p>We'll see how to implement a reader for a new resource file format. A resource reader is a descendant of <link id="resource.TAbstractResourceReader">TAbstractResourceReader</link>, and it's usually implemented in a unit named <var>namereader</var>, where <i>name</i> is file format name.</p>
  263. <p>Suppose we must write a reader for file format <i>foo</i>; we could start with a unit like this:</p>
  264. <code>
  265. unit fooreader;
  266. {$MODE OBJFPC} {$H+}
  267. interface
  268. uses
  269. Classes, SysUtils, resource;
  270. type
  271. TFooResourceReader = class(TAbstractResourceReader)
  272. protected
  273. function GetExtensions : string; override;
  274. function GetDescription : string; override;
  275. procedure Load(aResources : TResources; aStream : TStream); override;
  276. function CheckMagic(aStream : TStream) : boolean; override;
  277. public
  278. constructor Create; override;
  279. end;
  280. implementation
  281. function TFooResourceReader.GetExtensions: string;
  282. begin
  283. end;
  284. function TFooResourceReader.GetDescription: string;
  285. begin
  286. end;
  287. procedure TFooResourceReader.Load(aResources: TResources; aStream: TStream);
  288. begin
  289. end;
  290. function TFooResourceReader.CheckMagic(aStream: TStream): boolean;
  291. begin
  292. end;
  293. constructor TFooResourceReader.Create;
  294. begin
  295. end;
  296. initialization
  297. TResources.RegisterReader('.foo',TFooResourceReader);
  298. end.
  299. </code>
  300. <p>Note that in the <var>initialization</var> section, <var>TFooResourceReader</var> is registered for extension <var>.foo</var>.</p>
  301. <p>We must implement abstract methods of <link id="resource.TAbstractResourceReader">TAbstractResourceReader</link>. Let's start with the simpler ones, <link id="resource.TAbstractResourceReader.GetExtensions">GetExtensions</link> and <link id="resource.TAbstractResourceReader.GetDescription">GetDescription</link>.</p>
  302. <code>
  303. function TFooResourceReader.GetExtensions: string;
  304. begin
  305. Result:='.foo';
  306. end;
  307. function TFooResourceReader.GetDescription: string;
  308. begin
  309. Result:='FOO resource reader';
  310. end;
  311. </code>
  312. <p>Now let's see <link id="resource.TAbstractResourceReader.CheckMagic">CheckMagic</link> method. This method is called with a stream as a parameter, and the reader must return <var>true</var> if it recognizes the stream as a valid one. Usually this means checking some magic number or header.</p>
  313. <code>
  314. function TFooResourceReader.CheckMagic(aStream: TStream): boolean;
  315. var signature : array[0..3] of char;
  316. begin
  317. Result:=false;
  318. try
  319. aStream.ReadBuffer(signature[0],4);
  320. except
  321. on e : EReadError do exit;
  322. end;
  323. Result:=signature='FOO*';
  324. end;
  325. </code>
  326. <p>Suppose our foo files start with a 4-byte signature <var>'FOO*'</var>. This method checks the signature and returns <var>true</var> if it is verified. Note that it catches <var>EReadError</var> exception raised by <var>TStream</var>: this way, if the stream is too short it returns <var>false</var> (as it should, since magic is not valid) instead of letting the exception to propagate.</p>
  327. <p>Now let's see <link id="resource.TAbstractResourceReader.Load">Load</link>. This method must read the stream and create resources in the <link id="resource.TResources">TResources</link> object, with information about their name, type, position and size of their raw data, and so on.</p>
  328. <code>
  329. procedure TFooResourceReader.Load(aResources: TResources; aStream: TStream);
  330. begin
  331. if not CheckMagic(aStream) then
  332. raise EResourceReaderWrongFormatException.Create('');
  333. try
  334. ReadResources(aResources,aStream);
  335. except
  336. on e : EReadError do
  337. raise EResourceReaderUnexpectedEndOfStreamException.Create('');
  338. end;
  339. end;
  340. </code>
  341. <p>First of all, this method checks file magic number, calling <link id="resource.TAbstractResourceReader.CheckMagic">CheckMagic</link> method we already implemented. This is necessary since <link id="resource.TAbstractResourceReader.CheckMagic">CheckMagic</link> is not called before <link id="resource.TAbstractResourceReader.Load">Load</link>: <link id="resource.TAbstractResourceReader.CheckMagic">CheckMagic</link> is invoked by <link id="resource.TResources">TResources</link> when probing a stream, while <link id="resource.TAbstractResourceReader.Load">Load</link> is invoked when loading resources (so if the user passed a reader object to a <link id="resource.TResources">TResources</link> object, <link id="resource.TAbstractResourceReader.CheckMagic">CheckMagic</link> is never called). Note also that the stream is always at its starting position when these methods are called.</p>
  342. <p>If magic number is ok, our method invokes another method to do the actual loading. If during this process the stream can't be read, an <link id="resource.EResourceReaderUnexpectedEndOfStreamException">EResourceReaderUnexpectedEndOfStreamException</link> exception is raised.</p>
  343. <p>So, let's implement the private method which will load resources.</p>
  344. <p>Suppose that our foo format is very simple:</p>
  345. <ul>
  346. <li>the header is made by the 4-byte signature we already saw, a <var>longword</var> holding the number of resources in the file, and other 8 bytes of padding.</li>
  347. <li><p>each resource has a 16-byte header containing:</p>
  348. <ul>
  349. <li>a longword for the resource type (only IDs are allowed for types)</li>
  350. <li>a longword for the resource name (only IDs are allowed for names)</li>
  351. <li>a longword for the language ID</li>
  352. <li>a longword for the size of the resource data</li>
  353. </ul>
  354. </li>
  355. <li>
  356. after the resource header immediately comes the resource data, possibly padded so that it ends on a 4 byte boundary.
  357. </li>
  358. <li>
  359. file format is little-endian
  360. </li>
  361. </ul>
  362. <p>To start with, our method will be:</p>
  363. <code>
  364. procedure TFooResourceReader.ReadResources(aResources: TResources; aStream: TStream);
  365. var Count, i: longword;
  366. aType, aName, aLangID : longword;
  367. aDataSize : longword;
  368. begin
  369. //read remaining file header
  370. aStream.ReadBuffer(Count,sizeof(Count));
  371. aStream.Seek(8,soFromCurrent);
  372. for i:=1 to Count do
  373. begin
  374. //read resource header
  375. aStream.ReadBuffer(aType,sizeof(aType));
  376. aStream.ReadBuffer(aName,sizeof(aName));
  377. aStream.ReadBuffer(aLangID,sizeof(aLangID));
  378. aStream.ReadBuffer(aDataSize,sizeof(aDataSize));
  379. end;
  380. end;
  381. </code>
  382. <p>Since in <link id="resource.TAbstractResourceReader.Load">Load</link> we called <link id="resource.TAbstractResourceReader.CheckMagic">CheckMagic</link>, which read the first 4 bytes of the header, we must read the remaining 12: we read the number of resources, and we skip the other 8 bytes of padding.</p>
  383. <p>Then, for each resource, we read the resource header. Note that if we are running on a big endian system we should swap the bytes we read, e.g. calling <var>SwapEndian</var> function, but for simplicity this is omitted.</p>
  384. <p>Now, we should create a resource. Of which class? Well, we must use <link id="resfactory"/> unit. In fact it contains <link id="resfactory.TResourceFactory">TResourceFactory</link> class, which is an expert in creating resources of the right class: when the user adds a unit containing a resource class to the <var>uses</var> clause of its program, the resource class registers itself with <link id="resfactory.TResourceFactory">TResourceFactory</link>. This way it knows how to map resource types to resource classes.</p>
  385. <p>We need to have type and name of the resource to create as <link id="resource.TResourceDesc">TResourceDesc</link> objects: instead of creating and destroying these objects for each resource, we'll create a couple in the creator of our reader and we'll destroy them in the destructor, so that they will live for the whole life of our reader. Let's name them <var>workType</var> and <var>workName</var>.</p>
  386. <p>Our code becomes:</p>
  387. <code>
  388. uses
  389. resfactory;
  390. procedure TFooResourceReader.ReadResources(aResources: TResources; aStream: TStream);
  391. var Count, i: longword;
  392. aType, aName, aLangID : longword;
  393. aDataSize : longword;
  394. aRes : TAbstractResource;
  395. begin
  396. //read remaining file header
  397. aStream.ReadBuffer(Count,sizeof(Count));
  398. aStream.Seek(8,soFromCurrent);
  399. for i:=1 to Count do
  400. begin
  401. //read resource header
  402. aStream.ReadBuffer(aType,sizeof(aType));
  403. aStream.ReadBuffer(aName,sizeof(aName));
  404. aStream.ReadBuffer(aLangID,sizeof(aLangID));
  405. aStream.ReadBuffer(aDataSize,sizeof(aDataSize));
  406. //create the resource
  407. workType.ID:=aType;
  408. workName.ID:=aName;
  409. aRes:=TResourceFactory.CreateResource(workType,workName);
  410. SetDataSize(aRes,aDataSize);
  411. SetDataOffset(aRes,aStream.Position);
  412. aRes.LangID:=aLangID;
  413. end;
  414. end;
  415. </code>
  416. <p>Note that after the resource has been created we set its data size and data offset. Data offset is the current position in the stream, since in our FOO file format resource data immediately follows resource header.</p>
  417. <p>What else do we need to do? Of course we must create <link id="resource.TAbstractResource.RawData">RawData</link> stream for our resource, so that raw data can be accessed with the caching mechanism. We will create a <link id="resdatastream.TResourceDataStream">TResourceDataStream</link> object, telling it which resource and stream it is associated to, which its size will be and which class its underlying cached stream must be created from.</p>
  418. <p>So we add <link id="resdatastream"/> to the <var>uses</var> clause, declare another local variable</p>
  419. <code>
  420. aRawData : TResourceDataStream;
  421. </code>
  422. <p>and add these lines in the for loop</p>
  423. <code>
  424. aRawData:=TResourceDataStream.Create(aStream,aRes,aRes.DataSize,TCachedResourceDataStream);
  425. SetRawData(aRes,aRawData);
  426. </code>
  427. <p>That is, aRawData will create its underlying stream as a <link id="resdatastream.TCachedResourceDataStream">TCachedResourceDataStream</link> over the portion of <var>aStream</var> that starts at current position and ends after <var>aRes.DataSize bytes</var>.</p>
  428. <p>We almost finished: now we must add the newly created resource to the <link id="resource.TResources">TResources</link> object and move stream position to the next resource header. Complete code for <var>ReadResources</var> method is:</p>
  429. <code>
  430. procedure TFooResourceReader.ReadResources(aResources: TResources; aStream: TStream);
  431. var Count, i: longword;
  432. aType, aName, aLangID : longword;
  433. aDataSize : longword;
  434. aRes : TAbstractResource;
  435. aRawData : TResourceDataStream;
  436. begin
  437. //read remaining file header
  438. aStream.ReadBuffer(Count,sizeof(Count));
  439. aStream.Seek(8,soFromCurrent);
  440. for i:=1 to Count do
  441. begin
  442. //read resource header
  443. aStream.ReadBuffer(aType,sizeof(aType));
  444. aStream.ReadBuffer(aName,sizeof(aName));
  445. aStream.ReadBuffer(aLangID,sizeof(aLangID));
  446. aStream.ReadBuffer(aDataSize,sizeof(aDataSize));
  447. //create the resource
  448. workType.ID:=aType;
  449. workName.ID:=aName;
  450. aRes:=TResourceFactory.CreateResource(workType,workName);
  451. SetDataSize(aRes,aDataSize);
  452. SetDataOffset(aRes,aStream.Position);
  453. aRes.LangID:=aLangID;
  454. //set raw data
  455. aRawData:=TResourceDataStream.Create(aStream,aRes,aRes.DataSize,TCachedResourceDataStream);
  456. SetRawData(aRes,aRawData);
  457. //add to aResources
  458. try
  459. aResources.Add(aRes);
  460. except
  461. on e : EResourceDuplicateException do
  462. begin
  463. aRes.Free;
  464. raise;
  465. end;
  466. end;
  467. //go to next resource header
  468. aStream.Seek(aDataSize,soFromCurrent);
  469. Align4Bytes(aStream);
  470. end;
  471. end;
  472. </code>
  473. <p><var>Align4Bytes</var> is a private method (not shown for simplicity) that sets stream position to the next multiple of 4 if needed, since FOO file format specifies that resource data must be padded to end on a 4 byte boundary.</p>
  474. <p><b>Note:</b> We have used <link id="resource.TResources.Add">Add</link> method to populate the <link id="resource.TResources">TResources</link> object. More complex file formats store resources in a tree hierarchy; since <link id="resource.TResources">TResources</link> internally stores resources in this way too, a reader can choose to acquire a reference to the internal tree used by the <link id="resource.TResources">TResources</link> object (see <link id="resource.TAbstractResourceReader.GetTree">TAbstractResourceReader.GetTree</link>), populate it and notify the <link id="resource.TResources">TResources</link> object about the added resources (see <link id="resource.TAbstractResourceReader.AddNoTree">TAbstractResourceReader.AddNoTree</link>). For these file formats resources can be loaded faster, since there is no overhead involved in keeping a separate resource tree in the reader.</p>
  475. <p>That's all. Now you should be able to create a real resource reader.</p>
  476. </descr>
  477. </topic>
  478. <topic name="How to implement a new resource class">
  479. <short>How to implement a new resource class</short>
  480. <descr>
  481. <remark>This chapter assumes you have some experience in using this library.</remark>
  482. <p><b>Some considerations</b></p>
  483. <p>Usually, a specific resource class is needed when resource data is encoded in a specific binary format that makes working with <link id="resource.TAbstractResource.RawData">RawData</link> uncomfortable.</p>
  484. <p>However, there aren't many reasons to design a new binary format requiring a specific resource class: the classes provided with this package exist for compatibility with Microsoft Windows, but in the general case one should avoid such approach.</p>
  485. <p>In Microsoft Windows, some resource types have a specific format, and the operating system supports them at runtime making it easy to access that kind of data: e.g. icons and bitmaps are stored in resources in a format that is slightly different from the one found in regular files, but the operating system allows the user to easily load them using <var>LoadImage</var> function, without having to deal with their internal format. Other resource types are used to obtain information about the executable: <link id="resource.RT_VERSION">RT_VERSION</link> resource type and <link id="resource.RT_GROUP_ICON">RT_GROUP_ICON</link> contain version information and program icon that can be displayed in Windows Explorer, respectively.</p>
  486. <p>Using this kind of resources in a cross-platform perspective doesn't make much sense however, since there is no support by other operating systems for these types of resources (and for resources in general), and this means that it's up to you to provide support at runtime for these binary formats. So if you need to store images as resources it's better to use <link id="resource.TGenericResource">TGenericResource</link> and store an image in PNG format (for instance), which can be read by existing libraries at runtime, instead of creating a <link id="resource.RT_BITMAP">RT_BITMAP</link> resource with <link id="bitmapresource.TBitmapResource">TBitmapResource</link>, since libraries that read BMP files can't handle that resource contents.</p>
  487. <p>New resource classes thus make sense when you want to add support for existing Windows-specific resources, e.g. because you are writing a resource compiler or editor, but in the general case they should be avoided.</p>
  488. <p>Now that you've been warned, let's start with the topic of this chapter.</p>
  489. <p><b>How to implement a new resource class</b></p>
  490. <p>A resource class is a descendant of <link id="resource.TAbstractResource">TAbstractResource</link>, and it's usually implemented in a unit named <var>typeresource</var>, where <i>type</i> is resource type.</p>
  491. <p>If you are implementing a new resource class, you are doing it to provide additional methods or properties to utilize resource data. You resource class must thus be able to read its <link id="resource.TAbstractResource.RawData">RawData</link> stream format and write data back to it when it is requested to do so.</p>
  492. <p>Generally, your class shouldn't create private objects, records or memory buffers to provide these specific means of accessing data until it's requested to do so (lazy loading), and it should free these things when it is requested to write back data to the <link id="resource.TAbstractResource.RawData">RawData</link> stream.</p>
  493. <p>We'll see these points in more detail, using <link id="acceleratorsresource.TAcceleratorsResource">TAcceleratorsResource</link> as an example.</p>
  494. <p><link id="acceleratorsresource.TAcceleratorsResource">TAcceleratorsResource</link> holds a collection of accelerators. An accelerator is a record defined as follows:</p>
  495. <code>
  496. type
  497. TAccelerator = packed record
  498. Flags : word;
  499. Ansi : word;
  500. Id : word;
  501. padding : word;
  502. end;
  503. </code>
  504. <p>The resource simply contains accelerators, one immediately following the other. Last accelerator must have $80 in its flags.</p>
  505. <p>To provide easy access to the elements it contains, our accelerator resource class exposes these methods and properties in its public section:</p>
  506. <code>
  507. procedure Add(aItem : TAccelerator);
  508. procedure Clear;
  509. procedure Delete(aIndex : integer);
  510. property Count : integer read GetCount;
  511. property Items[index : integer] : TAccelerator read GetItem write SetItem; default;
  512. </code>
  513. <p>We must also implement abstract methods (and an abstract constructor) of <link id="resource.TAbstractResource">TAbstractResource</link>:</p>
  514. <code>
  515. protected
  516. function GetType : TResourceDesc; override;
  517. function GetName : TResourceDesc; override;
  518. function ChangeDescTypeAllowed(aDesc : TResourceDesc) : boolean; override;
  519. function ChangeDescValueAllowed(aDesc : TResourceDesc) : boolean; override;
  520. procedure NotifyResourcesLoaded; override;
  521. public
  522. constructor Create(aType,aName : TResourceDesc); override;
  523. procedure UpdateRawData; override;
  524. </code>
  525. <p>The protected methods are very easy to implement, so let's start from them. For <link id="resource.TAbstractResource.GetType">GetType</link> and <link id="resource.TAbstractResource.GetName">GetName</link>, we need to add two private fields, <var>fType</var> and <var>fName</var>, of type <link id="resource.TResourceDesc">TResourceDesc</link>. We create them in the constructor and destroy them in the destructor. Type will always be <link id="resource.RT_ACCELERATOR">RT_ACCELERATOR</link>. We make the parameterless constructor of <link id="resource.TAbstractResource">TAbstractResource</link> public, using <var>1</var> as the resource name, while in the other constructor we use the name passed as parameter, ignoring the type (since it must always be <link id="resource.RT_ACCELERATOR">RT_ACCELERATOR</link>).</p>
  526. <p>So, <link id="resource.TAbstractResource.GetType">GetType</link>, <link id="resource.TAbstractResource.GetName">GetName</link>, the constructors and the destructor are implemented as follows:</p>
  527. <code>
  528. function TAcceleratorsResource.GetType: TResourceDesc;
  529. begin
  530. Result:=fType;
  531. end;
  532. function TAcceleratorsResource.GetName: TResourceDesc;
  533. begin
  534. Result:=fName;
  535. end;
  536. constructor TAcceleratorsResource.Create;
  537. begin
  538. inherited Create;
  539. fType:=TResourceDesc.Create(RT_ACCELERATOR);
  540. fName:=TResourceDesc.Create(1);
  541. SetDescOwner(fType);
  542. SetDescOwner(fName);
  543. end;
  544. constructor TAcceleratorsResource.Create(aType, aName: TResourceDesc);
  545. begin
  546. Create;
  547. fName.Assign(aName);
  548. end;
  549. destructor TAcceleratorsResource.Destroy;
  550. begin
  551. fType.Free;
  552. fName.Free;
  553. inherited Destroy;
  554. end;
  555. </code>
  556. <p>Note that we used <link id="resource.TAbstractResource.SetDescOwner">SetDescOwner</link> to let type and name know the resource that owns them.</p>
  557. <p>Now <link id="resource.TAbstractResource.ChangeDescTypeAllowed">ChangeDescTypeAllowed</link> and <link id="resource.TAbstractResource.ChangeDescValueAllowed">ChangeDescValueAllowed</link> come. As we said, resource type must be <link id="resource.RT_ACCELERATOR">RT_ACCELERATOR</link>, always. Thus, we only allow name to change value or type:</p>
  558. <code>
  559. function TAcceleratorsResource.ChangeDescTypeAllowed(aDesc: TResourceDesc): boolean;
  560. begin
  561. Result:=aDesc=fName;
  562. end;
  563. function TAcceleratorsResource.ChangeDescValueAllowed(aDesc: TResourceDesc): boolean;
  564. begin
  565. Result:=aDesc=fName;
  566. end;
  567. </code>
  568. <p><link id="resource.TAbstractResource.NotifyResourcesLoaded">NotifyResourcesLoaded</link> is called by <link id="resource.TResources">TResources</link> when it finishes loading all resources. Since we are not interested in this fact, we simply leave this method empty. This method is useful for resources that "own" other resources, like <link id="groupiconresource.TGroupIconResource">TGroupIconResource</link> and <link id="groupiconresource.TGroupCursorResource">TGroupCursorResource</link> (note: you should <b>not</b> implement resource types that depend on other resources: it complicates things a lot and gives you a lot of headaches).</p>
  569. <p>Now, let's see the more interesting - and more difficult - part: providing an easy way to deal with accelerators.</p>
  570. <p>As we said earlier, we must implement some methods and properties to do so. Surely we'll need a list to hold pointers to accelerator records, but we must think a little bit about how this list is created, populated, written to <link id="resource.TAbstractResource.RawData">RawData</link> and so on.</p>
  571. <p>When the object is created, we don't have to create (yet) single accelerator records, as said before; but if the user tries to access them we must do it. If the object is created and its <link id="resource.TAbstractResource.RawData">RawData</link> contains data (e.g. because a reader has created the resource when loading a resource file) and the user tries to access an accelerator, we must create accelerators from <link id="resource.TAbstractResource.RawData">RawData</link> contents. So, until a user tries to access accelerators our class doesn't do anything, while when the user does so it "lazy-loads" data, or creates empty structures if <link id="resource.TAbstractResource.RawData">RawData</link> is empty.</p>
  572. <p>When data is loaded, <link id="resource.TAbstractResource.RawData">RawData</link> contents aren't considered anymore. When, however, our resource is requested to update <link id="resource.TAbstractResource.RawData">RawData</link> (that is, when <link id="resource.TAbstractResource.UpdateRawData">UpdateRawData</link> method is invoked), our "lazy-loaded" data must be freed. In fact, a user could ask our resource to update raw data, then he/she could modify it directly and then could use our resource's specialized methods and properties to do further processing: for this reason, when <link id="resource.TAbstractResource.RawData">RawData</link> is written, other buffered things must be freed, so that they'll created again from <link id="resource.TAbstractResource.RawData">RawData</link> if needed.</p>
  573. <p>Note that other resource classes could behave differently: e.g. <link id="bitmapresource.TBitmapResource">TBitmapResource</link> uses a copy-on-write mechanism on top of <link id="resource.TAbstractResource.RawData">RawData</link> to insert a BMP file header at the beginning of the stream, but it doesn't copy <link id="resource.TAbstractResource.RawData">RawData</link> contents whenever possible.</p>
  574. <p>Coming back to our <link id="acceleratorsresource.TAcceleratorsResource">TAcceleratorsResource</link> example, let's see how to implement this behaviour.</p>
  575. <p>Let's add a <var>fList</var> field in the <var>private</var> section of our class:</p>
  576. <code>
  577. fList : TFPList;
  578. </code>
  579. <p>In the constructor, we set this field to <var>nil</var>: we use it to check if data has been loaded from <link id="resource.TAbstractResource.RawData">RawData</link> or not. Consequently in the destructor we'll free the list only if it's not <var>nil</var>:</p>
  580. <code>
  581. destructor TAcceleratorsResource.Destroy;
  582. begin
  583. fType.Free;
  584. fName.Free;
  585. if fList&lt;&gt;nil then
  586. begin
  587. Clear;
  588. fList.Free;
  589. end;
  590. inherited Destroy;
  591. end;
  592. </code>
  593. <p>(we did not implement <var>Clear</var> method yet: we'll see it later).</p>
  594. <p>We said that our resource must load data only when needed; to do this we add a private method, <var>CheckDataLoaded</var> that ensures that data is loaded. This method is called by whatever method needs to operate on the list: if data has already been loaded it will quickly return, otherwise it will load data.</p>
  595. <code>
  596. procedure TAcceleratorsResource.CheckDataLoaded;
  597. var acc : TAccelerator;
  598. tot, i : integer;
  599. p : PAccelerator;
  600. begin
  601. if fList&lt;&gt;nil then exit;
  602. fList:=TFPList.Create;
  603. if RawData.Size=0 then exit;
  604. RawData.Position:=0;
  605. tot:=RawData.Size div 8;
  606. for i:=1 to tot do
  607. begin
  608. RawData.ReadBuffer(acc,sizeof(acc));
  609. GetMem(p,sizeof(TAccelerator));
  610. p^:=acc;
  611. fList.Add(p);
  612. end;
  613. end;
  614. </code>
  615. <p>If <var>fList</var> is not <var>nil</var> data is already loaded, so exit. Otherwise, create the list. If <link id="resource.TAbstractResource.RawData">RawData</link> is empty we don't need to load anything, so exit. Otherwise allocate room for accelerators, read them from the stream, and add them to the list.</p>
  616. <p>Note that if we are running on a big endian system we should swap the bytes we read, e.g. calling <var>SwapEndian</var> function, but for simplicity this is omitted.</p>
  617. <p>The counterpart of <var>CheckDataLoaded</var> is <link id="resource.TAbstractResource.UpdateRawData">UpdateRawData</link>. When it is called, data from the list must be written back to <link id="resource.TAbstractResource.RawData">RawData</link>, and the list and its contents must be freed:</p>
  618. <code>
  619. procedure TAcceleratorsResource.UpdateRawData;
  620. var acc : TAccelerator;
  621. i : integer;
  622. begin
  623. if fList=nil then exit;
  624. RawData.Size:=0;
  625. RawData.Position:=0;
  626. for i:=0 to fList.Count-1 do
  627. begin
  628. acc:=PAccelerator(fList[i])^;
  629. // $80 means 'this is the last entry', so be sure only the last one has this bit set.
  630. if i=Count-1 then acc.Flags:=acc.Flags or $80
  631. else acc.Flags:=acc.Flags and $7F;
  632. RawData.WriteBuffer(acc,sizeof(acc));
  633. end;
  634. Clear;
  635. FreeAndNil(fList);
  636. end;
  637. </code>
  638. <p>If <var>fList</var> is <var>nil</var> data hasn't been loaded, so <link id="resource.TAbstractResource.RawData">RawData</link> is up to date, so exit. Otherwise, write each accelerator (ensuring that only last one has <var>$80</var> flag set), clear the list, free it and set it to nil. Again, if we are on a big endian system we should swap each accelerator contents before writing it, but for simplicity this is omitted.</p>
  639. <p>Other methods we named earlier (<var>Add</var>, <var>Delete</var>, <var>Clear</var>) are trivial to implement: remember only to call <var>CheckDataLoaded</var> before doing anything. The same is true for accessor methods of relevant properties (<var>Count</var>, <var>Items</var>).</p>
  640. <p>If you are curious, you can check the full implementation of <link id="acceleratorsresource.TAcceleratorsResource">TAcceleratorsResource</link> looking at source code.</p>
  641. </descr>
  642. </topic>
  643. <topic name="Basic Usage">
  644. <short>Basic Usage</short>
  645. <descr>
  646. <p><b>Resource files and TResources class</b></p>
  647. <p>One of the most important classes is <link id="resource.TResources">TResources</link> class, contained in <link id="resource"/> unit, which represents a format-independent view of a resource file. In fact, while single resources are important, they are of little use alone, since they can't be read or written to file directly: they need to be contained in a <link id="resource.TResources">TResources</link> object.</p>
  648. <p><link id="resource.TResources">TResources</link> provides methods to read itself from a file or stream, using specific objects that are able to read resource data from such a stream: these are the so called <i>resource readers</i>, that descend from <link id="resource.TAbstractResourceReader">TAbstractResourceReader</link>.</p>
  649. <p>There are also <i>resource writers</i> that do the opposite, and that descend from <link id="resource.TAbstractResourceWriter">TAbstractResourceWriter</link>.</p>
  650. <p>Usually readers and writers register themselves with <link id="resource.TResources">TResources</link> in the <var>initialization</var> section of the unit they are implemented in, so you only need to add a certain unit to your program <var>uses</var> clause to let <link id="resource.TResources">TResources</link> "know" about a particular file format.</p>
  651. <p>Let's see a very simple example: a program that converts a .res file to an object file in COFF format (the object file format used by Microsoft Windows).</p>
  652. <code>
  653. program res1;
  654. {$mode objfpc}
  655. uses
  656. Classes, SysUtils, resource, resreader, coffwriter;
  657. var
  658. resources : TResources;
  659. begin
  660. resources:=TResources.Create;
  661. resources.LoadFromFile('myresource.res');
  662. resources.WriteToFile('myobject.o');
  663. resources.Free;
  664. end.
  665. </code>
  666. <p>As you can see, the code is trivial. Note that <var>resreader</var> and <var>coffwriter</var> units were added to the <var>uses</var> clause of the program: this way, the resource reader for .res files and the resource writer for COFF files have been registered, letting the <var>resources</var> object know how to handle these file types.</p>
  667. <p>There are cases where one doesn't want to let the <link id="resource.TResources">TResources</link> object to choose readers and writers by itself. In fact, while generally it is a good idea to let <link id="resource.TResources">TResources</link> probe all readers it knows to find one able to read the input file, this isn't true when it comes to write files: writers are selected based on the file extension, so if you are trying to write a file with .o extension you can't be sure about which writer will be selected: it could be the COFF or the ELF writer (it depends on which writer gets registered first). Moreover, writers generally make an object file for the host architecture, so if you are running the program on a i386 machine it will produce a COFF or ELF file for i386.</p>
  668. <p>The solution is to provide <link id="resource.TResources">TResources</link> with a specific writer. In the following example the reader is automatically chosen among various readers, and we use a specific writer to produce an ELF file for SPARC.</p>
  669. <code>
  670. program res2;
  671. {$mode objfpc}
  672. uses
  673. Classes, SysUtils, resource,
  674. resreader, coffreader, elfreader, winpeimagereader, //readers
  675. elfwriter, elfconsts;
  676. var
  677. resources : TResources;
  678. writer : TElfResourceWriter;
  679. begin
  680. resources:=TResources.Create;
  681. resources.LoadFromFile(paramstr(1));
  682. writer:=TElfResourceWriter.Create;
  683. writer.MachineType:=emtsparc;
  684. resources.WriteToFile(ChangeFileExt(paramstr(1),'.o'),writer);
  685. resources.Free;
  686. writer.Free;
  687. end.
  688. </code>
  689. <p>Note that the file to convert is taken from the command line. Its format is automatically detected among res (<link id="resreader"/>), coff (<link id="coffreader"/>), elf (<link id="elfreader"/>), PE (<link id="winpeimagereader"/>, e.g. a Windows exe or dll), and is written as an ELF file for SPARC. Note that we had to use <link id="elfconsts"/> unit since we used <link id="elfconsts.TElfMachineType.emtsparc">emtsparc</link> constant to specify the machine type of the object file to generate.</p>
  690. <p>With a small change to the above program we can let the user know which reader was selected to read the input file: we can use <link id="resource.TResources.FindReader">TResources.FindReader</link> class method to obtain the appropriate reader for a given stream.</p>
  691. <code>
  692. program res3;
  693. {$mode objfpc}
  694. uses
  695. Classes, SysUtils, resource,
  696. resreader, coffreader, elfreader, winpeimagereader, //readers
  697. elfwriter, elfconsts;
  698. var
  699. resources : TResources;
  700. writer : TElfResourceWriter;
  701. reader : TAbstractResourceReader;
  702. inFile : TFileStream;
  703. begin
  704. resources:=TResources.Create;
  705. inFile:=TFileStream.Create(paramstr(1), fmOpenRead or fmShareDenyNone);
  706. reader:=TResources.FindReader(inFile);
  707. writeln('Selected reader: ',reader.Description);
  708. resources.LoadFromStream(inFile,reader);
  709. writer:=TElfResourceWriter.Create;
  710. writer.MachineType:=emtsparc;
  711. resources.WriteToFile(ChangeFileExt(paramstr(1),'.o'),writer);
  712. resources.Free;
  713. reader.Free;
  714. writer.Free;
  715. inFile.Free;
  716. end.
  717. </code>
  718. <p>Output example:</p>
  719. <pre>
  720. user@localhost:~$ ./res3 myresource.res
  721. Selected reader: .res resource reader
  722. user@localhost:~$
  723. </pre>
  724. <p><b>Single resources</b></p>
  725. <p>You can do more with resources than simply converting between file formats.</p>
  726. <p><link id="resource.TResources.Items">TResources.Items</link> property provides a simple way to access all resources contained in the <link id="resource.TResources">TResources</link> object.</p>
  727. <p>In the following example we read a resource file and then dump each resource data in a file whose name is built from type and name of the dumped resource.</p>
  728. <code>
  729. program res4;
  730. {$mode objfpc}
  731. uses
  732. Classes, SysUtils, resource, resreader;
  733. var
  734. resources : TResources;
  735. dumpFile : TFileStream;
  736. i : integer;
  737. fname : string;
  738. begin
  739. resources:=TResources.Create;
  740. resources.LoadFromFile('myresource.res');
  741. for i:=0 to resources.Count-1 do
  742. begin
  743. fname:=resources[i]._Type.Name+'_'+resources[i].Name.Name;
  744. dumpFile:=TFileStream.Create(fname,fmCreate or fmShareDenyWrite);
  745. dumpFile.CopyFrom(resources[i].RawData,resources[i].RawData.Size);
  746. dumpFile.Free;
  747. end;
  748. resources.Free;
  749. end.
  750. </code>
  751. <p>This code simply copies the content of each resource's <link id="resource.TAbstractResource.RawData">RawData</link> stream to a file stream, whose name is <i>resourcetype_resourcename</i>.</p>
  752. <p>Resource raw data isn't always what one expected, however. While some resource types simply contain a copy of a file in their raw data, other types do some processing, so that dumping raw data doesn't result in a file in the format one expected.</p>
  753. <p>E.g. a resource of type <link id="resource.RT_MANIFEST">RT_MANIFEST</link> is of the former type: its raw data is like an XML manifest file. On the other hand, in a resource of type <link id="resource.RT_BITMAP">RT_BITMAP</link> the <link id="resource.TAbstractResource.RawData">RawData</link> stream isn't like a BMP file.</p>
  754. <p>For this reason, several classes (descendants of <link id="resource.TAbstractResource">TAbstractResource</link>) are provided to handle the peculiarities of this or that resource type. Much like it's done with readers and writers, resource classes can be registered: adding the unit that contains a resource class to the <var>uses</var> clause of your program registers that class. This way, when resources are read from a file, they are created with the class that is registered for their type (the class responsible to do this is <link id="resfactory.TResourceFactory">TResourceFactory</link>, but probably you won't need to use it unless you're implementing a new resource reader or resource class).</p>
  755. <p>In the following example, we read a resource file and then dump data of each resource of type <link id="resource.RT_BITMAP">RT_BITMAP</link> as a BMP file.</p>
  756. <code>
  757. program res5;
  758. {$mode objfpc}
  759. uses
  760. Classes, SysUtils, resource, resreader, bitmapresource;
  761. var
  762. resources : TResources;
  763. dumpFile : TFileStream;
  764. i : integer;
  765. fname : string;
  766. begin
  767. resources:=TResources.Create;
  768. resources.LoadFromFile('myresource.res');
  769. for i:=0 to resources.Count-1 do
  770. if resources[i] is TBitmapResource then
  771. with resources[i] as TBitmapResource do
  772. begin
  773. fname:=Name.Name+'.bmp';
  774. dumpFile:=TFileStream.Create(fname,fmCreate or fmShareDenyWrite);
  775. dumpFile.CopyFrom(BitmapData,BitmapData.Size);
  776. dumpFile.Free;
  777. end;
  778. resources.Free;
  779. end.
  780. </code>
  781. <p>Note that we included <link id="bitmapresource"/> in the <var>uses</var> clause of our program. This way, resources of type <link id="resource.RT_BITMAP">RT_BITMAP</link> are created from <link id="bitmapresource.TBitmapResource">TBitmapResource</link> class. This class provides a stream, <link id="bitmapresource.TBitmapResource.BitmapData">BitmapData</link> that allows resource raw data to be accessed as if it was a bmp file.</p>
  782. <p>We can of course do the opposite. In the following code we are creating a manifest resource from <var>manifest.xml</var> file.</p>
  783. <code>
  784. program res6;
  785. {$mode objfpc}
  786. uses
  787. Classes, SysUtils, resource, reswriter;
  788. var
  789. resources : TResources;
  790. inFile : TFileStream;
  791. res : TGenericResource;
  792. rname,rtype : TResourceDesc;
  793. begin
  794. inFile:=TFileStream.Create('manifest.xml',fmOpenRead or fmShareDenyNone);
  795. rtype:=TResourceDesc.Create(RT_MANIFEST);
  796. rname:=TResourceDesc.Create(1);
  797. res:=TGenericResource.Create(rtype,rname);
  798. rtype.Free; //no longer needed
  799. rname.Free;
  800. res.SetCustomRawDataStream(inFile);
  801. resources:=TResources.Create;
  802. resources.Add(res);
  803. resources.WriteToFile('myresource.res');
  804. resources.Free; //frees res as well
  805. inFile.Free;
  806. end.
  807. </code>
  808. <p>Note that resources of type <link id="resource.RT_MANIFEST">RT_MANIFEST</link> contain a straight copy of a xml file, so <link id="resource.TGenericResource">TGenericResource</link> class fits our needs. <link id="resource.TGenericResource">TGenericResource</link> is a basic implementation of <link id="resource.TAbstractResource">TAbstractResource</link>. It is the default class used by <link id="resfactory.TResourceFactory">TResourceFactory</link> when it must create a resource whose type wasn't registered with any resource class.</p>
  809. <p>Please note that instead of copying <var>inFile</var> contents to <link id="resource.TAbstractResource.RawData">RawData</link> we used <link id="resource.TAbstractResource.SetCustomRawDataStream">SetCustomRawDataStream</link> method: it sets a stream as the underlying stream for <link id="resource.TAbstractResource.RawData">RawData</link>, so that when final resource file is written, data is read directly from the original file.</p>
  810. <p>Let's see a similar example, in which we use a specific class instead of <link id="resource.TGenericResource">TGenericResource</link>. In the following code we are creating a resource containing the main program icon, which is read from <var>mainicon.ico</var> file.</p>
  811. <code>
  812. program res7;
  813. {$mode objfpc}
  814. uses
  815. Classes, SysUtils, resource, reswriter, groupiconresource;
  816. var
  817. resources : TResources;
  818. inFile : TFileStream;
  819. iconres : TGroupIconResource;
  820. name : TResourceDesc;
  821. begin
  822. inFile:=TFileStream.Create('mainicon.ico',fmOpenRead or fmShareDenyNone);
  823. name:=TResourceDesc.Create('MAINICON');
  824. //type is always RT_GROUP_ICON for this resource class
  825. iconres:=TGroupIconResource.Create(nil,name);
  826. iconres.SetCustomItemDataStream(inFile);
  827. resources:=TResources.Create;
  828. resources.Add(iconres);
  829. resources.WriteToFile('myicon.res');
  830. resources.Free; //frees iconres as well
  831. inFile.Free;
  832. name.Free;
  833. end.
  834. </code>
  835. <p>In this program we created a new <link id="groupiconresource.TGroupIconResource">TGroupIconResource</link> with 'MAINICON' as name, and we loaded its contents from file 'mainicon.ico'. Please note that <link id="resource.RT_GROUP_ICON">RT_GROUP_ICON</link> resource raw data doesn't contain a .ico file, so we have to write to <link id="groupresource.TGroupResource.ItemData">ItemData</link> which is a ico-like stream. As we did for <var>res6</var> program, we tell the resource to use our stream as the underlying stream for resource data: the only difference is that we are using <link id="groupresource.TGroupResource.SetCustomItemDataStream">TGroupResource.SetCustomItemDataStream</link> instead of <link id="resource.TAbstractResource.SetCustomRawDataStream">TAbstractResource.SetCustomRawDataStream</link> method, for obvious reasons.</p>
  836. <p><b>Other resource types</b></p>
  837. <p>There are other resource types that allow to easily deal with resource data. E.g. <link id="versionresource.TVersionResource">TVersionResource</link> makes it easy to create and read version information for Windows executables and dlls, <link id="stringtableresource.TStringTableResource">TStringTableResource</link> deals with string tables, and so on.</p>
  838. <p><b>Data caching</b></p>
  839. <p>Whenever possible, fcl-res tries to avoid to duplicate data. Generally a reader doesn't copy resource data from the original stream to <link id="resource.TAbstractResource.RawData">RawData</link> stream: instead, it only informs the resource about where its raw data is in the original stream. <link id="resource.TAbstractResource.RawData">RawData</link> uses a caching system so that it appears as a stream while it only redirects operations to its underlying stream, with a copy-on-write mechanism. Of course this behaviour can be controlled by the user. For further information, see <link id="resource.TAbstractResource">TAbstractResource</link> and <link id="resource.TAbstractResource.RawData">TAbstractResource.RawData</link>.</p>
  840. </descr>
  841. </topic>
  842. <topic name="Introduction">
  843. <short>Introduction</short>
  844. <descr>
  845. <p>This package contains a library to easily work with Microsoft Windows resources in a cross-platform way.</p>
  846. <p>Classes are provided to create, load and write resources from/to different file formats in a transparent way, and to handle most common resource types without having to deal with their internal format.</p>
  847. <p>Whenever possible data caching is performed, helped by a copy-on-write mechanism. This improves performance especially when converting big resources from a file format to another.</p>
  848. <p>Since fcl-res architecture is extensible, it's always possible to extend the library with custom resource types or new file readers/writers.</p>
  849. <p>Please note that resources aren't limited to Windows platform: Free Pascal can use them also on ELF and Mach-O targets. Moreover, this library can be useful for cross-compilation purposes even on other targets.</p>
  850. <p>It is highly recommended to read <link id="Basic Usage"/> topic if you are approaching this library for the first time.</p>
  851. </descr>
  852. </topic>
  853. <!--
  854. ====================================================================
  855. resource
  856. ====================================================================
  857. -->
  858. <module name="resource">
  859. <short>Contains base classes for resource handling</short>
  860. <descr>
  861. <p>This unit contains base classes needed to work with resources.</p>
  862. <p>Single resources are represented by an instance of a <link id="TAbstractResource"/> descendant. They are grouped in a <link id="TResources"/> instance which can be read (written) to (from) a stream via a <link id="TAbstractResourceReader"/> (<link id="TAbstractResourceWriter"/>) descendant.</p>
  863. <p><link id="TGenericResource"/> provides a basic implementation of <link id="TAbstractResource"/>.</p>
  864. </descr>
  865. <!-- unresolved type reference Visibility: default -->
  866. <element name="Classes">
  867. </element>
  868. <!-- unresolved type reference Visibility: default -->
  869. <element name="Sysutils">
  870. </element>
  871. <!-- constant Visibility: default -->
  872. <element name="RT_CURSOR">
  873. <short>Single cursor resource</short>
  874. <descr>
  875. A single image in a cursor. Don't use it directly.
  876. </descr>
  877. <seealso>
  878. <link id="RT_GROUP_CURSOR"/>
  879. <link id="groupcursorresource.TGroupCursorResource">TGroupCursorResource</link>
  880. </seealso>
  881. </element>
  882. <!-- constant Visibility: default -->
  883. <element name="RT_BITMAP">
  884. <short>Bitmap resource</short>
  885. <seealso>
  886. <link id="bitmapresource.TBitmapResource">TBitmapResource</link>
  887. </seealso>
  888. </element>
  889. <!-- constant Visibility: default -->
  890. <element name="RT_ICON">
  891. <short>Single icon resource</short>
  892. <descr>
  893. A single image in a icon. Don't use it directly.
  894. </descr>
  895. <seealso>
  896. <link id="RT_GROUP_ICON"/>
  897. <link id="groupiconresource.TGroupIconResource">TGroupIconResource</link>
  898. </seealso>
  899. </element>
  900. <!-- constant Visibility: default -->
  901. <element name="RT_MENU">
  902. <short>Menu resource</short>
  903. </element>
  904. <!-- constant Visibility: default -->
  905. <element name="RT_DIALOG">
  906. <short>Dialog resource</short>
  907. </element>
  908. <!-- constant Visibility: default -->
  909. <element name="RT_STRING">
  910. <short>String table resource</short>
  911. <seealso>
  912. <link id="stringtableresource.TStringTableResource">TStringTableResource</link>
  913. </seealso>
  914. </element>
  915. <!-- constant Visibility: default -->
  916. <element name="RT_FONTDIR">
  917. <short>Font directory resource</short>
  918. <descr>
  919. This resource type is obsolete and never appears in 32 bit resources.
  920. </descr>
  921. <seealso>
  922. <link id="RT_FONT"/>
  923. </seealso>
  924. </element>
  925. <!-- constant Visibility: default -->
  926. <element name="RT_FONT">
  927. <short>Single font resource</short>
  928. <descr>
  929. This resource type is obsolete and never appears in 32 bit resources.
  930. </descr>
  931. <seealso>
  932. <link id="RT_FONTDIR"/>
  933. </seealso>
  934. </element>
  935. <!-- constant Visibility: default -->
  936. <element name="RT_ACCELERATOR">
  937. <short>Accelerator table resource</short>
  938. <seealso>
  939. <link id="acceleratorsresource.TAcceleratorsResource">TAcceleratorsResource</link>
  940. </seealso>
  941. </element>
  942. <!-- constant Visibility: default -->
  943. <element name="RT_RCDATA">
  944. <short>Application-defined resource (raw data)</short>
  945. <descr>
  946. <p>This resource type contains arbitrary binary data</p>
  947. <p>Note that Delphi dfm files are stored in compiled form as a RCDATA resource</p>
  948. </descr>
  949. </element>
  950. <!-- constant Visibility: default -->
  951. <element name="RT_MESSAGETABLE">
  952. <short>Message table resource</short>
  953. </element>
  954. <!-- constant Visibility: default -->
  955. <element name="RT_GROUP_CURSOR">
  956. <short>Cursor resource</short>
  957. <descr>
  958. <p>This resource type contains a cursor and it's the equivalent of a .cur file</p>
  959. <remark>Please note that is is made up of several <link id="RT_CURSOR"/> resources (the single cursor images) that shouldn't be accessed singularly.</remark>
  960. </descr>
  961. <seealso>
  962. <link id="RT_CURSOR"/>
  963. <link id="groupcursorresource.TGroupCursorResource">TGroupCursorResource</link>
  964. </seealso>
  965. </element>
  966. <!-- constant Visibility: default -->
  967. <element name="RT_GROUP_ICON">
  968. <short>Icon resource</short>
  969. <descr>
  970. <p>This resource type contains an icon and it's the equivalent of a .ico file</p>
  971. <remark>Please note that is is made up of several <link id="RT_ICON"/> resources (the single icon images) that shouldn't be accessed singularly.</remark>
  972. </descr>
  973. <seealso>
  974. <link id="RT_ICON"/>
  975. <link id="groupiconresource.TGroupIconResource">TGroupIconResource</link>
  976. </seealso>
  977. </element>
  978. <!-- constant Visibility: default -->
  979. <element name="RT_VERSION">
  980. <short>Version resource</short>
  981. <descr>
  982. This resource defines version information which is visible when viewing properties of a Windows executable or DLL.
  983. </descr>
  984. <seealso>
  985. <link id="versionresource.TVersionResource">TVersionResource</link>
  986. </seealso>
  987. </element>
  988. <!-- constant Visibility: default -->
  989. <element name="RT_DLGINCLUDE">
  990. <short>Never present in compiled form</short>
  991. <descr>
  992. This resource is used internally by resource compilers but will never appear in compiled form
  993. </descr>
  994. </element>
  995. <!-- constant Visibility: default -->
  996. <element name="RT_PLUGPLAY">
  997. <short>Plug and Play resource</short>
  998. </element>
  999. <!-- constant Visibility: default -->
  1000. <element name="RT_VXD">
  1001. <short>VXD resource</short>
  1002. </element>
  1003. <!-- constant Visibility: default -->
  1004. <element name="RT_ANICURSOR">
  1005. <short>Animated cursor resource</short>
  1006. <descr>
  1007. This resource type contains raw binary data taken from a .ani file
  1008. </descr>
  1009. <seealso>
  1010. <link id="RT_ANIICON"/>
  1011. </seealso>
  1012. </element>
  1013. <!-- constant Visibility: default -->
  1014. <element name="RT_ANIICON">
  1015. <short>Animated icon resource</short>
  1016. <descr>
  1017. This resource type contains raw binary data taken from a .ani file
  1018. </descr>
  1019. <seealso>
  1020. <link id="RT_ANICURSOR"/>
  1021. </seealso>
  1022. </element>
  1023. <!-- constant Visibility: default -->
  1024. <element name="RT_HTML">
  1025. <short>HTML resource</short>
  1026. <descr>
  1027. This resource type contains an HTML file.
  1028. </descr>
  1029. </element>
  1030. <!-- constant Visibility: default -->
  1031. <element name="RT_MANIFEST">
  1032. <short>Windows XP Side-by-Side Assembly XML manifest</short>
  1033. <descr>
  1034. <p>This resource contains data taken from a .manifest file</p>
  1035. <remark>Resource name must be one of <link id ="CREATEPROCESS_MANIFEST_RESOURCE_ID"/> (mainly used for executables), <link id ="ISOLATIONAWARE_MANIFEST_RESOURCE_ID"/> or <link id="ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID"/> (mainly used for DLLs)</remark>
  1036. </descr>
  1037. </element>
  1038. <!-- constant Visibility: default -->
  1039. <element name="CREATEPROCESS_MANIFEST_RESOURCE_ID">
  1040. </element>
  1041. <!-- constant Visibility: default -->
  1042. <element name="ISOLATIONAWARE_MANIFEST_RESOURCE_ID">
  1043. </element>
  1044. <!-- constant Visibility: default -->
  1045. <element name="ISOLATIONAWARE_NOSTATICIMPORT_MANIFEST_RESOURCE_ID">
  1046. </element>
  1047. <!-- constant Visibility: default -->
  1048. <element name="MINIMUM_RESERVED_MANIFEST_RESOURCE_ID">
  1049. </element>
  1050. <!-- constant Visibility: default -->
  1051. <element name="MAXIMUM_RESERVED_MANIFEST_RESOURCE_ID">
  1052. </element>
  1053. <!-- constant Visibility: default -->
  1054. <element name="MF_MOVEABLE">
  1055. <short>The resource can be moved</short>
  1056. <descr>
  1057. This flag is ignored by Windows and Free Pascal RTL. It's provided for compatibility with 16-bit Windows.
  1058. </descr>
  1059. </element>
  1060. <!-- constant Visibility: default -->
  1061. <element name="MF_PURE">
  1062. <short>The resource contains dword-aligned data</short>
  1063. <descr>
  1064. This flag is ignored by Windows and Free Pascal RTL. It's provided for compatibility with 16-bit Windows.
  1065. </descr>
  1066. </element>
  1067. <!-- constant Visibility: default -->
  1068. <element name="MF_PRELOAD">
  1069. <short>The resource is loaded with the executable file</short>
  1070. <descr>
  1071. This flag is ignored by Windows and Free Pascal RTL. It's provided for compatibility with 16-bit Windows.
  1072. </descr>
  1073. </element>
  1074. <!-- constant Visibility: default -->
  1075. <element name="MF_DISCARDABLE">
  1076. <short>The resource can be discarded if no longer needed</short>
  1077. <descr>
  1078. This flag is ignored by Windows and Free Pascal RTL. It's provided for compatibility with 16-bit Windows.
  1079. </descr>
  1080. </element>
  1081. <!-- resource string Visibility: default -->
  1082. <element name="SReaderNotFoundExt">
  1083. </element>
  1084. <!-- resource string Visibility: default -->
  1085. <element name="SReaderNotFoundProbe">
  1086. </element>
  1087. <!-- resource string Visibility: default -->
  1088. <element name="SWriterNotFoundExt">
  1089. </element>
  1090. <!-- resource string Visibility: default -->
  1091. <element name="SDescChangeNotAllowed">
  1092. </element>
  1093. <!-- resource string Visibility: default -->
  1094. <element name="SLangIDChangeNotAllowed">
  1095. </element>
  1096. <!-- resource string Visibility: default -->
  1097. <element name="SResDuplicate">
  1098. </element>
  1099. <!-- alias type Visibility: default -->
  1100. <element name="TLangID">
  1101. <short>A resource language ID</short>
  1102. </element>
  1103. <!-- alias type Visibility: default -->
  1104. <element name="TResName">
  1105. <short>A resource type or name in string form</short>
  1106. <seealso>
  1107. <link id="TResID"/>
  1108. <link id="TDescType"/>
  1109. <link id="TResourceDesc"/>
  1110. </seealso>
  1111. </element>
  1112. <!-- alias type Visibility: default -->
  1113. <element name="TResID">
  1114. <short>A resource type or name in ID form</short>
  1115. <seealso>
  1116. <link id="TResName"/>
  1117. <link id="TDescType"/>
  1118. <link id="TResourceDesc"/>
  1119. </seealso>
  1120. </element>
  1121. <!-- enumeration type Visibility: default -->
  1122. <element name="TDescType">
  1123. <short>The type of a resource type or name</short>
  1124. <seealso>
  1125. <link id="TResName"/>
  1126. <link id="TResID"/>
  1127. <link id="TResourceDesc"/>
  1128. </seealso>
  1129. </element>
  1130. <!-- enumeration value Visibility: default -->
  1131. <element name="TDescType.dtName">
  1132. <short>The resource type or name is a string</short>
  1133. </element>
  1134. <!-- enumeration value Visibility: default -->
  1135. <element name="TDescType.dtID">
  1136. <short>The resource type or name is an ID</short>
  1137. </element>
  1138. <!-- object Visibility: default -->
  1139. <element name="EResourceException">
  1140. <short>Base class for resource-related exceptions</short>
  1141. </element>
  1142. <!-- object Visibility: default -->
  1143. <element name="EResourceDescTypeException">
  1144. <short>Wrong description type error</short>
  1145. <descr>
  1146. <p>This exception is raised when a resource description is of type <link id="TDescType.dtName">dtName</link> and <link id="TResourceDesc.ID"/> property is read.</p>
  1147. </descr>
  1148. <seealso>
  1149. <link id="TResourceDesc.ID"/>
  1150. </seealso>
  1151. </element>
  1152. <!-- object Visibility: default -->
  1153. <element name="EResourceDescChangeNotAllowedException">
  1154. <short>Description is not allowed to change</short>
  1155. <descr>
  1156. <p>This exception is raised when a resource description (either type or name) is tried to be changed, but the resource class doesn't allow it.</p>
  1157. </descr>
  1158. <seealso>
  1159. <link id="TAbstractResource._Type"/>
  1160. <link id="TAbstractResource.Name"/>
  1161. </seealso>
  1162. </element>
  1163. <!-- object Visibility: default -->
  1164. <element name="EResourceLangIDChangeNotAllowedException">
  1165. <short>Language ID is not allowed to change</short>
  1166. <descr>
  1167. <p>This exception is raised when the resource language ID is tried to be changed, but the resource is contained in a <link id="TResources"/> object.</p>
  1168. </descr>
  1169. <seealso>
  1170. <link id="TAbstractResource.LangID"/>
  1171. </seealso>
  1172. </element>
  1173. <!-- object Visibility: default -->
  1174. <element name="EResourceDuplicateException">
  1175. <short>There is already a resource with same type, name and language ID</short>
  1176. <descr>
  1177. <p>This exception is raised when a resource is being added to a <link id="TResources"/> object, but another resource with the same type, name and language ID already exists.</p>
  1178. </descr>
  1179. <seealso>
  1180. <link id="TResources.Add"/>
  1181. <link id="TResources.MoveFrom"/>
  1182. </seealso>
  1183. </element>
  1184. <!-- object Visibility: default -->
  1185. <element name="EResourceNotFoundException">
  1186. <short>No resource matching the search criteria is found</short>
  1187. <descr>
  1188. <p>This exception is raised when searching for a resource in a <link id="TResources"/> object fails.</p>
  1189. </descr>
  1190. <seealso>
  1191. <link id="TResources.Find"/>
  1192. <link id="TResources.Remove"/>
  1193. </seealso>
  1194. </element>
  1195. <!-- object Visibility: default -->
  1196. <element name="ENoMoreFreeIDsException">
  1197. <short>There are no more free IDs to use as name for a resource</short>
  1198. <descr>
  1199. <p>This exception is raised by <link id="TResources.AddAutoID"/> method when it is not possible to generate an ID to use as a name for the given resource, because all possible 65536 IDs are already assigned to resources of the same type as the given one.</p>
  1200. </descr>
  1201. <seealso>
  1202. <link id="TResources.AddAutoID"/>
  1203. </seealso>
  1204. </element>
  1205. <!-- object Visibility: default -->
  1206. <element name="EResourceReaderException">
  1207. <short>Base class for resource reader-related exceptions</short>
  1208. </element>
  1209. <!-- object Visibility: default -->
  1210. <element name="EResourceReaderNotFoundException">
  1211. <short>No suitable resource reader was found</short>
  1212. <descr>
  1213. <p>This exception is raised when no <link id="TAbstractResourceReader"/> descendant able to read a stream was found.</p>
  1214. </descr>
  1215. <seealso>
  1216. <link id="TResources.FindReader"/>
  1217. <link id="TResources.LoadFromStream"/>
  1218. <link id="TResources.LoadFromFile"/>
  1219. </seealso>
  1220. </element>
  1221. <!-- object Visibility: default -->
  1222. <element name="EResourceReaderWrongFormatException">
  1223. <short>The stream is not in the format the reader supports</short>
  1224. <descr>
  1225. <p>This exception is raised by <link id="TAbstractResourceReader.Load">Load</link> method of a <link id="TAbstractResourceReader"/> descendant when the stream it was asked to read resources from is not in the format it supports.</p>
  1226. </descr>
  1227. <seealso>
  1228. <link id="TAbstractResourceReader.Load"/>
  1229. </seealso>
  1230. </element>
  1231. <!-- object Visibility: default -->
  1232. <element name="EResourceReaderUnexpectedEndOfStreamException">
  1233. <short>The stream ended prematurely</short>
  1234. <descr>
  1235. <p>This exception is raised by <link id="TAbstractResourceReader.Load">Load</link> method of a <link id="TAbstractResourceReader"/> descendant when the stream it was asked to read resources from ended prematurely.</p>
  1236. </descr>
  1237. <seealso>
  1238. <link id="TAbstractResourceReader.Load"/>
  1239. </seealso>
  1240. </element>
  1241. <!-- object Visibility: default -->
  1242. <element name="EResourceWriterException">
  1243. <short>Base class for resource writer-related exceptions</short>
  1244. </element>
  1245. <!-- object Visibility: default -->
  1246. <element name="EResourceWriterNotFoundException">
  1247. <short>No suitable resource writer was found</short>
  1248. <descr>
  1249. <p>This exception is raised by <link id="TResources.WriteToFile">WriteToFile</link> method of <link id="TResources"/> when no <link id="TAbstractResourceWriter"/> descendant matching filename extension was found.</p>
  1250. </descr>
  1251. <seealso>
  1252. <link id="TResources.WriteToFile"/>
  1253. </seealso>
  1254. </element>
  1255. <!-- object Visibility: default -->
  1256. <element name="TAbstractResource">
  1257. <short>Base abstract resource class</short>
  1258. <descr>
  1259. <p>This is the base class that represents a resource.</p>
  1260. <p>A resource is identified by its <link id="TAbstractResource._Type">type</link>, <link id="TAbstractResource.Name">name</link> and <link id="TAbstractResource.LangID">language ID</link> even if some file formats or operating systems don't consider the latter.</p>
  1261. <p>There are also additional properties that aren't always present in all file formats, so their values aren't always meaningful: however, they can be used to display detailed information when possible.</p>
  1262. <p>Every resource has a <link id="TAbstractResource.RawData">RawData</link> stream that holds resource data. This stream uses a copy-on-write mechanism: if the resource has been read from a stream or file, <link id="TAbstractResource.RawData">RawData</link> redirects read operations to the original stream. This is particularly useful when a resource file must be converted from a format to another, or when more resource files must be merged, since (potentially large) resource data is directly copied from the original to the destination stream without the need of allocating a lot of memory.</p>
  1263. <p>When resource data is encoded in a resource-specific format, <link id="TAbstractResource.RawData">RawData</link> can be uncomfortable: it's often better to use a more specialized descendant class that provides additional properties and methods.</p>
  1264. <p>Resources cannot be read or written alone from/to a stream: they need to be contained in a <link id="TResources"/> object, which represents an abstract view of a resource file.</p>
  1265. <p>Usually each descendant registers itself with <link id="resfactory.TResourceFactory">TResourceFactory</link> class in the <var>initialization</var> section of the unit in which it is implemented: this way <link id="resfactory.TResourceFactory">TResourceFactory</link> class can know which class to use to instantiate a resource of a given type.</p>
  1266. <remark>An object of this class should never be directly instantiated: use a descendant class instead.</remark>
  1267. </descr>
  1268. <seealso>
  1269. <link id="TGenericResource"/>
  1270. <link id="acceleratorsresource.TAcceleratorsResource">TAcceleratorsResource</link>
  1271. <link id="bitmapresource.TBitmapResource">TBitmapResource</link>
  1272. <link id="groupcursorresource.TGroupCursorResource">TGroupCursorResource</link>
  1273. <link id="groupiconresource.TGroupIconResource">TGroupIconResource</link>
  1274. <link id="stringtableresource.TStringTableResource">TStringTableResource</link>
  1275. <link id="versionresource.TVersionResource">TVersionResource</link>
  1276. <link id="TResources"/>
  1277. <link id="resfactory.TResourceFactory">TResourceFactory</link>
  1278. </seealso>
  1279. </element>
  1280. <!-- object Visibility: default -->
  1281. <element name="TResourceDesc">
  1282. <short>A resource description (type or name)</short>
  1283. <descr>
  1284. <p>This class represent a resource description (type or name).</p>
  1285. <p>Resources are identified by a type, name and (optionally) a language ID.</p>
  1286. <p>Type and name can be either a <b>name</b> (a string identifier) or an <b>ID</b> (an integer identifier in the range 0..65535).</p>
  1287. <remark>
  1288. Unfortunately, <i>name</i> is used both to refer to a the name of the resource and both to the format of a resource description
  1289. </remark>
  1290. <p><b>Example:</b></p>
  1291. <p>Typically, a Windows executable has a main icon, which is a resource of type <link id ="RT_GROUP_ICON"/> (type is an ID) and name <var>MAINICON</var> (name is a name).</p>
  1292. </descr>
  1293. <seealso>
  1294. <link id="TAbstractResource"/>
  1295. </seealso>
  1296. </element>
  1297. <!-- procedure Visibility: protected -->
  1298. <element name="TResourceDesc.SetOwner">
  1299. <short>Protected method to let a resource set itself as owner of the TResourceDesc</short>
  1300. </element>
  1301. <!-- argument Visibility: default -->
  1302. <element name="TResourceDesc.SetOwner.aOwner">
  1303. <short>The resource that is to become the owner of the TResourceDesc</short>
  1304. </element>
  1305. <!-- constructor Visibility: public -->
  1306. <element name="TResourceDesc.Create">
  1307. <short>Creates a new TResourceDesc object</short>
  1308. <descr>
  1309. <p>Creates a new TResourceDesc object.</p>
  1310. <p>Without arguments, resource description is of type <link id="TDescType.dtName">dtName</link> and its name is empty.</p>
  1311. <p>If an argument is specified, resource description and name/id are set accordingly to the value passed as parameter.</p>
  1312. </descr>
  1313. </element>
  1314. <!-- argument Visibility: default -->
  1315. <element name="TResourceDesc.Create.aID">
  1316. <short>The ID to use as the resource description ID</short>
  1317. </element>
  1318. <!-- argument Visibility: default -->
  1319. <element name="TResourceDesc.Create.aName">
  1320. <short>The name to use as the resource description name</short>
  1321. </element>
  1322. <!-- procedure Visibility: public -->
  1323. <element name="TResourceDesc.Assign">
  1324. <short>Assigns the contents of another TResourceDesc object to this one</short>
  1325. <descr>
  1326. </descr>
  1327. <errors>
  1328. <p>
  1329. If changing values is not permitted because owner resource doesn't allow it (e.g. because owner resource is a <link id="bitmapresource.TBitmapResource">TBitmapResource</link> and values other than <link id ="RT_BITMAP"/> are not permitted for the resource type) an <link id="EResourceDescChangeNotAllowedException"/> exception is raised.</p>
  1330. </errors>
  1331. <seealso>
  1332. </seealso>
  1333. </element>
  1334. <!-- argument Visibility: default -->
  1335. <element name="TResourceDesc.Assign.aResourceDesc">
  1336. <short>The object from which data must be copied</short>
  1337. </element>
  1338. <!-- function Visibility: public -->
  1339. <element name="TResourceDesc.Equals">
  1340. <short>Compares the contents of another TResourceDesc object to this one</short>
  1341. </element>
  1342. <!-- function result Visibility: default -->
  1343. <element name="TResourceDesc.Equals.Result">
  1344. <short>True if the contents of the two objects are the same</short>
  1345. </element>
  1346. <!-- argument Visibility: default -->
  1347. <element name="TResourceDesc.Equals.aResDesc">
  1348. <short>The object to compare with this one</short>
  1349. </element>
  1350. <!-- property Visibility: public -->
  1351. <element name="TResourceDesc.Name">
  1352. <short>The value of the resource description as a name</short>
  1353. <descr>
  1354. <p>Setting this property causes <link id="TResourceDesc.DescType">DescType</link> to be <link id="TDescType.dtName">dtName</link></p>
  1355. <p>When reading, if <link id="TResourceDesc.DescType">DescType</link> is <link id="TDescType.dtID">dtID</link>, the ID is returned as a string value.</p>
  1356. </descr>
  1357. <seealso>
  1358. <link id="TResourceDesc.ID"/>
  1359. <link id="TResourceDesc.DescType"/>
  1360. </seealso>
  1361. </element>
  1362. <!-- property Visibility: public -->
  1363. <element name="TResourceDesc.ID">
  1364. <short>The value of the resource description as an ID</short>
  1365. <descr>
  1366. <p>Setting this property causes <link id="TResourceDesc.DescType">DescType</link> to be <link id="TDescType.dtID">dtID</link></p>
  1367. <remark>When reading, if <link id="TResourceDesc.DescType">DescType</link> is <link id="TDescType.dtName">dtName</link>, an <link id="EResourceDescTypeException"/> exception is raised.</remark>
  1368. </descr>
  1369. <seealso>
  1370. <link id="TResourceDesc.Name"/>
  1371. <link id="TResourceDesc.DescType"/>
  1372. </seealso>
  1373. </element>
  1374. <!-- property Visibility: public -->
  1375. <element name="TResourceDesc.DescType">
  1376. <short>The type of the resource description</short>
  1377. <descr>
  1378. <p>When DescType is <link id="TDescType.dtName">dtName</link>, resource description value is a name and can be accessed via <link id="TResourceDesc.Name">Name</link> property</p>
  1379. <p>When DescType is <link id="TDescType.dtID">dtID</link>, resource description value is an ID and can be accessed via <link id="TResourceDesc.ID">ID</link> property</p>
  1380. </descr>
  1381. <seealso>
  1382. <link id="TResourceDesc.Name"/>
  1383. <link id="TResourceDesc.ID"/>
  1384. <link id="TDescType"/>
  1385. </seealso>
  1386. </element>
  1387. <!-- object Visibility: default -->
  1388. <element name="TResources">
  1389. <short>A collection of resources</short>
  1390. <descr>
  1391. <p>This class represents a format-independent view of a resource file. It holds a collection of resources (<link id="TAbstractResource"/> descendants).</p>
  1392. <p>Typically, a TResource object is loaded from and written to a stream via format-dependent readers and writers, which are descendants of <link id="TAbstractResourceReader"/> and <link id="TAbstractResourceWriter"/>, respectively.</p>
  1393. <p>Single resources can be added, removed, searched and modified: a resource compiler or editor probably will create resources, set their data, and add them to a TResources object which can then be written to file in the desired format.</p>
  1394. <p>This class also provides some class methods to register and find resource readers and writers: these classes, once registered, will be used by a TResources object when it is asked to load or save itself to a stream and the user didn't specify a reader or writer.</p>
  1395. <remark>Because of the copy-on-write mechanism of <link id="TAbstractResource"/>, care should be taken when loading resources, since by default resource data isn't immediately read from the stream: resources hold a reference to the original stream because they need it when their data is requested. For further information, see <link id="TResources.LoadFromStream"/> and <link id="TResources.LoadFromFile"/>.</remark>
  1396. </descr>
  1397. <seealso>
  1398. <link id="TAbstractResource"/>
  1399. <link id="TAbstractResourceReader"/>
  1400. <link id="TAbstractResourceWriter"/>
  1401. </seealso>
  1402. </element>
  1403. <!-- procedure Visibility: protected -->
  1404. <element name="TAbstractResource.SetDescOwner">
  1405. <short>Sets this resource as the owner of the given TResourceDesc</short>
  1406. <descr>
  1407. <p>This method is provided so that descendants of <link id="TAbstractResource"/> can set themselves as the owners of the given TResourceDesc</p>
  1408. </descr>
  1409. </element>
  1410. <!-- argument Visibility: default -->
  1411. <element name="TAbstractResource.SetDescOwner.aDesc">
  1412. <short>The TResourceDesc that the resource must own</short>
  1413. </element>
  1414. <!-- procedure Visibility: protected -->
  1415. <element name="TAbstractResource.SetOwnerList">
  1416. <short>Protected method to let a resource list set itself as the owner of the resource</short>
  1417. </element>
  1418. <!-- argument Visibility: default -->
  1419. <element name="TAbstractResource.SetOwnerList.aResources">
  1420. <short>The resource list that is to become the owner of the resource</short>
  1421. </element>
  1422. <!-- procedure Visibility: protected -->
  1423. <element name="TAbstractResource.SetChildOwner">
  1424. <short>Protected method to let a resource set itself as the owner of a sub-resource</short>
  1425. </element>
  1426. <!-- argument Visibility: default -->
  1427. <element name="TAbstractResource.SetChildOwner.aChild">
  1428. <short>The sub-resource that the resource must own</short>
  1429. </element>
  1430. <!-- function Visibility: protected -->
  1431. <element name="TAbstractResource.GetType">
  1432. <short>Returns the type of the resource</short>
  1433. <descr>
  1434. <p>Descendant classes must implement this method to provide access to the resource type.</p>
  1435. </descr>
  1436. </element>
  1437. <!-- function result Visibility: default -->
  1438. <element name="TAbstractResource.GetType.Result">
  1439. <short>The <link id="TResourceDesc"/> object representing the type of the resource</short>
  1440. </element>
  1441. <!-- function Visibility: protected -->
  1442. <element name="TAbstractResource.GetName">
  1443. <short>Returns the name of the resource</short>
  1444. <descr>
  1445. <p>Descendant classes must implement this method to provide access to the resource name.</p>
  1446. </descr>
  1447. </element>
  1448. <!-- function result Visibility: default -->
  1449. <element name="TAbstractResource.GetName.Result">
  1450. <short>The <link id="TResourceDesc"/> object representing the name of the resource</short>
  1451. </element>
  1452. <!-- function Visibility: protected -->
  1453. <element name="TAbstractResource.ChangeDescTypeAllowed">
  1454. <short>Reports whether changing the type of resource type or name is allowed</short>
  1455. <descr>
  1456. <p>Descendant classes must implement this method to declare if the resource allows changing the type of one of its resource description (type or name): that is, if it allows one of its descriptions type to change from <link id="TDescType.dtName">dtName</link> to <link id="TDescType.dtID">dtID</link> or vice versa.</p>
  1457. <p><b>Example:</b></p>
  1458. <p>A certain resource class allows its name only to be changed: e.g. a <link id="bitmapresource.TBitmapResource">TBitmapResource</link> doesn't want its type to be anything else than <link id="RT_BITMAP"/>. It then allows changing the type of the description only if the description is the resource name:</p>
  1459. <code>
  1460. Result:=aDesc=fName;
  1461. </code>
  1462. </descr>
  1463. <seealso>
  1464. <link id="TAbstractResource.ChangDescValueAllowed"/>
  1465. </seealso>
  1466. </element>
  1467. <!-- function result Visibility: default -->
  1468. <element name="TAbstractResource.ChangeDescTypeAllowed.Result">
  1469. <short>True if the resource allows the given <link id="TResourceDesc"/> to change type</short>
  1470. </element>
  1471. <!-- argument Visibility: default -->
  1472. <element name="TAbstractResource.ChangeDescTypeAllowed.aDesc">
  1473. <short>The <link id="TResourceDesc"/> whose type should be changed</short>
  1474. </element>
  1475. <!-- function Visibility: protected -->
  1476. <element name="TAbstractResource.ChangeDescValueAllowed">
  1477. <short>Reports whether changing the value of resource type or name is allowed</short>
  1478. <descr>
  1479. <p>Descendant classes must implement this method to declare if the resource allows changing the value of one of its resource description (type or name).</p>
  1480. <p><b>Example:</b></p>
  1481. <p>A certain resource class allows its name only to be changed: e.g. a <link id="bitmapresource.TBitmapResource">TBitmapResource</link> doesn't want its type to be anything else than <link id="RT_BITMAP"/>. It then allows changing the value of the description only if the description is the resource name:</p>
  1482. <code>
  1483. Result:=aDesc=fName;
  1484. </code>
  1485. </descr>
  1486. <seealso>
  1487. <link id="TAbstractResource.ChangDescTypeAllowed"/>
  1488. </seealso>
  1489. </element>
  1490. <!-- function result Visibility: default -->
  1491. <element name="TAbstractResource.ChangeDescValueAllowed.Result">
  1492. <short>True if the resource allows the given <link id="TResourceDesc"/> to change value</short>
  1493. </element>
  1494. <!-- argument Visibility: default -->
  1495. <element name="TAbstractResource.ChangeDescValueAllowed.aDesc">
  1496. <short>The <link id="TResourceDesc"/> whose value should be changed</short>
  1497. </element>
  1498. <!-- procedure Visibility: protected -->
  1499. <element name="TAbstractResource.NotifyResourcesLoaded">
  1500. <short>Tells the resource that all resources have been loaded</short>
  1501. <descr>
  1502. <p>This method is called by a <link id="TResources"/> object when the loading of all resources from a stream has completed.</p>
  1503. <p><b>Example:</b></p>
  1504. <p>A Group resource (e.g. <link id="groupiconresource.TGroupIconResource">TGroupIconResource</link>) can use this method to find all its sub-resources, since all resources have been loaded from a stream.</p>
  1505. </descr>
  1506. </element>
  1507. <!-- constructor Visibility: protected -->
  1508. <element name="TAbstractResource.Create">
  1509. <short>Creates a new resource</short>
  1510. <descr>
  1511. <p>A new resource is created with the given type and name.</p>
  1512. <remark>Please note that the resource doesn't take ownership of the <link id="TResourceDesc"/> objects passed as parameters, it simply copies them: it's user responsibility to free them when no longer needed.</remark>
  1513. </descr>
  1514. </element>
  1515. <!-- argument Visibility: default -->
  1516. <element name="TAbstractResource.Create.aType">
  1517. <short>The type of the resource to be created</short>
  1518. </element>
  1519. <!-- argument Visibility: default -->
  1520. <element name="TAbstractResource.Create.aName">
  1521. <short>The name of the resource to be created</short>
  1522. </element>
  1523. <!-- destructor Visibility: public -->
  1524. <element name="TAbstractResource.Destroy">
  1525. <short>Destroys the object</short>
  1526. </element>
  1527. <!-- function Visibility: public -->
  1528. <element name="TAbstractResource.CompareContents">
  1529. <short>Compares the contents of the resource to the contents of another one</short>
  1530. <descr>
  1531. <p>This methods compares the contents of the resource with the ones of <var>aResource</var>. If they are of the same length and their contents are the same, <var>true</var> is returned, <var>false</var> otherwise.</p>
  1532. <p>Usually this methods compares the contents of the two <link id="TAbstractResource.RawData">RawData</link> streams, calling <link id="resdatastream.TResourceDataStream.Compare">TResourceDataStream.Compare</link>, but descendent classes can implement a different algorithm.</p>
  1533. </descr>
  1534. <seealso>
  1535. <link id="resdatastream.TResourceDataStream.Compare">TResourceDataStream.Compare</link>
  1536. </seealso>
  1537. </element>
  1538. <!-- function result Visibility: default -->
  1539. <element name="TAbstractResource.CompareContents.Result">
  1540. <short>True if the contents of the two resources are the same</short>
  1541. </element>
  1542. <!-- argument Visibility: default -->
  1543. <element name="TAbstractResource.CompareContents.aResource">
  1544. <short>The resource to compare to this one</short>
  1545. </element>
  1546. <!-- procedure Visibility: public -->
  1547. <element name="TAbstractResource.UpdateRawData">
  1548. <short>Updates RawData stream.</short>
  1549. <descr>
  1550. <p>When operating on resource data with more high-level streams than <link id="TAbstractResource.RawData">RawData</link> (e.g: <link id="bitmapresource.TBitmapResource.BitmapData">TBitmapResource.BitmapData</link>) RawData contents are no longer valid. This method ensures that <link id="TAbstractResource.RawData">RawData</link> stream is properly synchronized with the contents of the higher-level stream.</p>
  1551. <remark>Normally a resource writer doesn't need to call this method when it is about to write the resource data to a stream, since <link id="TResources"/> class takes care of this before telling the resource writer to write resources to a stream.</remark>
  1552. </descr>
  1553. <seealso>
  1554. <link id="TAbstractResource.RawData"/>
  1555. </seealso>
  1556. </element>
  1557. <!-- procedure Visibility: public -->
  1558. <element name="TAbstractResource.SetCustomRawDataStream">
  1559. <short>Sets a custom stream as the underlying stream for RawData</short>
  1560. <descr>
  1561. <p>Normally, <link id="TAbstractResource.RawData">RawData</link> uses a memory stream or the original resource stream (e.g. the original file containing the resource) as its underlying stream. This method allows the user to use a custom stream as the underlying stream. This can be useful when a resource must be created from the contents of an original file as-is.</p>
  1562. <p>If <var>aStream</var> is <var>nil</var>, a new memory stream is used as the underlying stream. This can be used to remove a previously set custom stream as the underlying stream.</p>
  1563. <p><b>Sample code</b></p>
  1564. <p>This code creates a resource containing an html file</p>
  1565. <code>
  1566. var
  1567. aType, aName : TResourceDesc;
  1568. aRes : TGenericResource;
  1569. aFile : TFileStream;
  1570. begin
  1571. aType:=TResourceDesc.Create(RT_HTML);
  1572. aName:=TResourceDesc.Create('index');
  1573. aRes:=TGenericResource.Create(aType,aName);
  1574. aFile:=TFileStream.Create('index.html',fmOpenRead or fmShareDenyNone);
  1575. aRes.SetCustomRawDataStream(aFile);
  1576. //do something...
  1577. aRes.Free;
  1578. aFile.Free;
  1579. aType.Free;
  1580. aName.Free;
  1581. end;
  1582. </code>
  1583. </descr>
  1584. <seealso>
  1585. <link id="TAbstractResource.RawData"/>
  1586. </seealso>
  1587. </element>
  1588. <!-- argument Visibility: default -->
  1589. <element name="TAbstractResource.SetCustomRawDataStream.aStream">
  1590. <short>The custom stream to use as the underlying <link id="TAbstractResource.RawData">RawData</link> stream. It can be <var>nil</var></short>
  1591. </element>
  1592. <!-- property Visibility: public -->
  1593. <element name="TAbstractResource._Type">
  1594. <short>The type of the resource</short>
  1595. <descr>
  1596. <remark>
  1597. <p>Please note that some <link id="TAbstractResource"/> descendants don't allow resource type to be changed (e.g: it's not possible for a <link id="bitmapresource.TBitmapResource">TBitmapResource</link> to have a type other than <link id="RT_BITMAP"/>). If it is the case, an <link id="EResourceDescChangeNotAllowedException"/> exception is raised.</p>
  1598. <p>Moreover, if the resource is contained in a <link id="TResources"/> object, type change is not allowed.</p>
  1599. </remark>
  1600. </descr>
  1601. <seealso>
  1602. <link id="TAbstractResource.ChangeDescTypeAllowed"/>
  1603. <link id="TAbstractResource.ChangeDescValueAllowed"/>
  1604. </seealso>
  1605. </element>
  1606. <!-- property Visibility: public -->
  1607. <element name="TAbstractResource.Name">
  1608. <short>The name of the resource</short>
  1609. <descr>
  1610. <remark>
  1611. <p>Please note that some <link id="TAbstractResource"/> descendants don't allow resource name to be changed (e.g: a <link id="stringtableresource.TStringTableResource">TStringTableResource</link> name is determined by the range of strings' ID it contains). If it is the case, an <link id="EResourceDescChangeNotAllowedException"/> exception is raised.</p>
  1612. <p>Moreover, if the resource is contained in a <link id="TResources"/> object, name change is not allowed.</p>
  1613. </remark>
  1614. </descr>
  1615. <seealso>
  1616. <link id="TAbstractResource.ChangeDescTypeAllowed"/>
  1617. <link id="TAbstractResource.ChangeDescValueAllowed"/>
  1618. </seealso>
  1619. </element>
  1620. <!-- property Visibility: public -->
  1621. <element name="TAbstractResource.LangID">
  1622. <short>The language ID of the resource</short>
  1623. <descr>
  1624. <remark>Please note that if the resource is contained in a <link id="TResources"/> object, language ID change is not allowed: trying to do so results in an <link id="EResourceLangIDChangeNotAllowedException"/> exception being raised.</remark>
  1625. </descr>
  1626. </element>
  1627. <!-- property Visibility: public -->
  1628. <element name="TAbstractResource.DataSize">
  1629. <short>The size of resource raw data</short>
  1630. <descr>
  1631. <p>DataSize is the length, in bytes, of the resource data, accessible via <link id="TAbstractResource.RawData">RawData</link> property.</p>
  1632. </descr>
  1633. <seealso>
  1634. <link id="TAbstractResource.RawData"/>
  1635. <link id="TAbstractResource.DataOffset"/>
  1636. </seealso>
  1637. </element>
  1638. <!-- property Visibility: public -->
  1639. <element name="TAbstractResource.HeaderSize">
  1640. <short>The size of resource header</short>
  1641. <descr>
  1642. <p>This property is not always meaningful, since not all file formats support it.</p>
  1643. <p>Its value, when nonzero, can be used for information purposes.</p>
  1644. </descr>
  1645. </element>
  1646. <!-- property Visibility: public -->
  1647. <element name="TAbstractResource.DataVersion">
  1648. <short>The version of the resource data</short>
  1649. <descr>
  1650. <p>This property is not always meaningful, since not all file formats support it.</p>
  1651. <p>Its value, when nonzero, can be used for information purposes.</p>
  1652. </descr>
  1653. </element>
  1654. <!-- property Visibility: public -->
  1655. <element name="TAbstractResource.MemoryFlags">
  1656. <short>The memory flags of the resource</short>
  1657. <descr>
  1658. <p>This field is a combination of the following flags</p>
  1659. <ul>
  1660. <li><link id="MF_MOVEABLE"/></li>
  1661. <li><link id="MF_PURE"/></li>
  1662. <li><link id="MF_PRELOAD"/></li>
  1663. <li><link id="MF_DISCARDABLE"/></li>
  1664. </ul>
  1665. <p>By default, a newly created resource has <link id="MF_MOVEABLE"/> and <link id="MF_DISCARDABLE"/> flags set.</p>
  1666. <remark>Please note that memory flags are ignored by Windows and Free Pascal RTL. They are provided only for compatibility with 16-bit Windows.</remark>
  1667. <p>This property is not always meaningful, since not all file formats support it.</p>
  1668. <p>Its value, when nonzero, can be used for information purposes.</p>
  1669. </descr>
  1670. </element>
  1671. <!-- property Visibility: public -->
  1672. <element name="TAbstractResource.Version">
  1673. <short>A user defined version number</short>
  1674. <descr>
  1675. <p>A tool that writes resource files can write version information in this field.</p>
  1676. <p>This property is not always meaningful, since not all file formats support it.</p>
  1677. <p>Its value, when nonzero, can be used for information purposes.</p>
  1678. </descr>
  1679. <seealso>
  1680. <link id="TAbstractResource.Characteristics"/>
  1681. </seealso>
  1682. </element>
  1683. <!-- property Visibility: public -->
  1684. <element name="TAbstractResource.Characteristics">
  1685. <short>A user defined piece of data</short>
  1686. <descr>
  1687. <p>A tool that writes resource files can write arbitrary data in this field.</p>
  1688. <p>This property is not always meaningful, since not all file formats support it.</p>
  1689. <p>Its value, when nonzero, can be used for information purposes.</p>
  1690. </descr>
  1691. <seealso>
  1692. <link id="TAbstractResource.Version"/>
  1693. </seealso>
  1694. </element>
  1695. <!-- property Visibility: public -->
  1696. <element name="TAbstractResource.DataOffset">
  1697. <short>The offset of resource data from the beginning of the stream</short>
  1698. <descr>
  1699. <p>A reader sets this property to let the resource know where its raw data begins in the resource stream.</p>
  1700. </descr>
  1701. <seealso>
  1702. <link id="TAbstractResource.RawData"/>
  1703. <link id="TAbstractResource.DataSize"/>
  1704. </seealso>
  1705. </element>
  1706. <!-- property Visibility: public -->
  1707. <element name="TAbstractResource.CodePage">
  1708. <short>The code page of the resource</short>
  1709. <descr>
  1710. <p>This property is not always meaningful, since not all file formats support it.</p>
  1711. <p>Its value, when nonzero, can be used for information purposes.</p>
  1712. </descr>
  1713. </element>
  1714. <!-- property Visibility: public -->
  1715. <element name="TAbstractResource.RawData">
  1716. <short>The raw resource data stream</short>
  1717. <descr>
  1718. <p>This property provides access to the resource raw data in a stream-like way.</p>
  1719. <p>When a resource has been read from a stream, RawData redirects read operations to the original stream. When RawData is written to, a copy-on-write mechanism copies data from the original stream to a memory stream.</p>
  1720. <p>The copy-on-write behaviour can be controlled via <link id="TAbstractResource.CacheData">CacheData</link> property.</p>
  1721. <p>Note that for some predefined resource types there are better ways to read and write resource data: some resource types use specific formats, so RawData might not always be what one expected. E.g. in a resource of type <link id="RT_BITMAP"/>, RawData doesn't contain a valid BMP file: in this case it's better to use <link id="bitmapresource.TBitmapResource.BitmapData">BitmapData</link> stream of <link id="bitmapresource.TBitmapResource">TBitmapResource</link> class to work with a BMP-like stream.</p>
  1722. <remark>When writing to a "specialized" stream in a descendant class (like the <link id="bitmapresource.TBitmapResource.BitmapData">TBitmapResource.BitmapData</link> stream mentioned earlier), RawData contents might not be valid anymore. If you need to access RawData again, be sure to call <link id="TAbstractResource.UpdateRawData">UpdateRawData</link> method first.</remark>
  1723. <p>Usually there isn't much penalty in using specialized streams in descendant classes, since data isn't duplicated in two or more streams, whenever possible. So, having a very large bitmap resource and reading/writing it via <link id="bitmapresource.TBitmapResource.BitmapData">TBitmapResource.BitmapData</link> doesn't mean the bitmap is allocated two times.</p>
  1724. </descr>
  1725. <seealso>
  1726. <link id="TAbstractResource.CacheData"/>
  1727. <link id="TAbstractResource.UpdateRawData"/>
  1728. <link id="TAbstractResource.SetCustomRawDataStream"/>
  1729. </seealso>
  1730. </element>
  1731. <!-- property Visibility: public -->
  1732. <element name="TAbstractResource.CacheData">
  1733. <short>Controls the copy-on-write behaviour of the resource</short>
  1734. <descr>
  1735. <p>When CacheData is true, copy-on-write mechanism of <link id="TAbstractResource.RawData">RawData</link> is enabled.</p>
  1736. <p>Setting CacheData to false forces the raw resource data to be loaded in memory without performing any caching.</p>
  1737. <p>By default, CacheData is true.</p>
  1738. </descr>
  1739. <seealso>
  1740. <link id="TAbstractResource.RawData"/>
  1741. <link id="TResources.CacheData"/>
  1742. </seealso>
  1743. </element>
  1744. <!-- property Visibility: public -->
  1745. <element name="TAbstractResource.OwnerList">
  1746. <short>The resource list that owns this resource</short>
  1747. <descr>
  1748. <p>This property identifies the <link id="TResources"/> object to which this resource belongs to.</p>
  1749. <p>This property can be <var>nil</var> if the resource isn't part of a resource list.</p>
  1750. </descr>
  1751. </element>
  1752. <!-- property Visibility: public -->
  1753. <element name="TAbstractResource.Owner">
  1754. <short>The owner of this resource</short>
  1755. <descr>
  1756. <p>This property is meaningful only for those sub-resources that are part of a larger <i>group resource</i>.</p>
  1757. <p><b>Example</b>: an icon is made by a <link id="RT_GROUP_ICON"/> resource and many <link id="RT_ICON"/> resources that hold single-image data. Each <link id="RT_ICON"/> resource has a pointer to the <link id="RT_GROUP_ICON"/> resource in its Owner property.</p>
  1758. </descr>
  1759. </element>
  1760. <!-- "class of" type Visibility: default -->
  1761. <element name="TResourceClass">
  1762. <short>Resource metaclass</short>
  1763. </element>
  1764. <!-- object Visibility: default -->
  1765. <element name="TGenericResource">
  1766. <short>Generic resource class</short>
  1767. <descr>
  1768. <p>This class represents a generic resource.</p>
  1769. <p>It is suitable to use in all situations where a higher level class is not needed (e.g. the resource raw data is made of arbitrary data) or when total low-level control is desirable.</p>
  1770. <p>This class is also the default one that is used by <link id="resfactory.TResourceFactory">TResourceFactory</link> when it finds no class matching the given type.</p>
  1771. </descr>
  1772. <seealso>
  1773. <link id="resfactory.TResourceFactory.CreateResource">TResourceFactory.CreateResource</link>
  1774. </seealso>
  1775. </element>
  1776. <!-- object Visibility: default -->
  1777. <element name="TAbstractResourceReader">
  1778. <short>Base abstract resource reader class</short>
  1779. <descr>
  1780. <p>This is the base class that represents a resource reader.</p>
  1781. <p>A resource reader is an object whose job is to populate a <link id="TResources"/> object with resources read from a stream in a specific format.</p>
  1782. <p>Typically, a <link id="TResources"/> object invokes <link id="TAbstractResourceReader.CheckMagic">CheckMagic</link> method of the resource reader when it's searching for a reader able to read a certain stream, and <link id="TAbstractResourceReader.Load">Load</link> method when it wants the reader to read data from the stream.</p>
  1783. <p>Usually each resource reader registers itself with <link id="TResources"/> class in the <var>initialization</var> section of the unit in which it is implemented: this way a <link id="TResources"/> object can find it when probing a stream that is to be read.</p>
  1784. <remark>An object of this class should never be directly instantiated: use a descendant class instead.</remark>
  1785. </descr>
  1786. <seealso>
  1787. <link id="TResources"/>
  1788. <link id="TAbstractResource"/>
  1789. <link id="TAbstractResourceWriter"/>
  1790. <link id="resreader.TResResourceReader">TResResourceReader</link>
  1791. <link id="coffreader.TCoffResourceReader">TCoffResourceReader</link>
  1792. <link id="winpeimagereader.TWinPEImageResourceReader">TWinPEResourceReader</link>
  1793. <link id="elfreader.TElfResourceReader">TElfResourceReader</link>
  1794. <link id="externalreader.TExternalResourceReader">TExternalResourceReader</link>
  1795. <link id="dfmreader.TDfmResourceReader">TDfmResourceReader</link>
  1796. </seealso>
  1797. </element>
  1798. <!-- object Visibility: default -->
  1799. <element name="TAbstractResourceWriter">
  1800. <short>Base abstract resource writer class</short>
  1801. <descr>
  1802. <p>This is the base class that represents a resource writer.</p>
  1803. <p>A resource writer is an object whose job is to write all resources contained in a <link id="TResources"/> object to a stream in a specific format.</p>
  1804. <p>Typically, a <link id="TResources"/> object invokes <link id="TAbstractResourceWriter.Write">Write</link> method of the resource writer when it wants the writer to write data to a stream.</p>
  1805. <p>Usually each resource writer registers itself with <link id="TResources"/> class in the <var>initialization</var> section of the unit in which it is implemented: this way a <link id="TResources"/> object can find it when it is asked to write itself to a file, and no writer was specified (the writer is found based on the extension of the file to write to).</p>
  1806. <remark>An object of this class should never be directly instantiated: use a descendant class instead.</remark>
  1807. </descr>
  1808. <seealso>
  1809. <link id="TResources"/>
  1810. <link id="TAbstractResource"/>
  1811. <link id="TAbstractResourceReader"/>
  1812. <link id="reswriter.TResResourceWriter">TResResourceWriter</link>
  1813. <link id="coffwriter.TCoffResourceWriter">TCoffResourceWriter</link>
  1814. <link id="elfwriter.TElfResourceWriter">TElfResourceWriter</link>
  1815. <link id="externalwriter.TExternalResourceWriter">TExternalResourceWriter</link>
  1816. </seealso>
  1817. </element>
  1818. <!-- "class of" type Visibility: default -->
  1819. <element name="TResourceReaderClass">
  1820. <short>Resource reader metaclass</short>
  1821. </element>
  1822. <!-- "class of" type Visibility: default -->
  1823. <element name="TResourceWriterClass">
  1824. <short>Resource writer metaclass</short>
  1825. </element>
  1826. <!-- function Visibility: public -->
  1827. <element name="TResources.Find">
  1828. <short>Searches for a resource</short>
  1829. <descr>
  1830. <p>This method searches for a resource with the given type and name. If a language ID is not provided, the first resource found that matches <var>aType</var> and <var>aName</var> is returned.</p>
  1831. </descr>
  1832. <errors>
  1833. <p>If the resource is not found, an <link id="EResourceNotFoundException"/> exception is raised.</p>
  1834. </errors>
  1835. </element>
  1836. <!-- function result Visibility: default -->
  1837. <element name="TResources.Find.Result">
  1838. <short>The resource that matches the search criteria</short>
  1839. </element>
  1840. <!-- argument Visibility: default -->
  1841. <element name="TResources.Find.aType">
  1842. <short>The type of the resource to search for</short>
  1843. </element>
  1844. <!-- argument Visibility: default -->
  1845. <element name="TResources.Find.aName">
  1846. <short>The name of the resource to search for</short>
  1847. </element>
  1848. <!-- argument Visibility: default -->
  1849. <element name="TResources.Find.aLangID">
  1850. <short>The language ID of the resource to search for</short>
  1851. </element>
  1852. <!-- constructor Visibility: public -->
  1853. <element name="TResources.Create">
  1854. <short>Creates a new TResources object</short>
  1855. </element>
  1856. <!-- destructor Visibility: public -->
  1857. <element name="TResources.Destroy">
  1858. <short>Destroys the object</short>
  1859. <descr>
  1860. <remark>All resources are destroyed as well.</remark>
  1861. </descr>
  1862. </element>
  1863. <!-- procedure Visibility: public -->
  1864. <element name="TResources.Add">
  1865. <short>Adds a resource</short>
  1866. <descr>
  1867. <p>This method adds <var>aResource</var> to the object, and sets itself as the owner list of the resource.</p>
  1868. </descr>
  1869. <errors>
  1870. <p>If a resource with the same type, name and language ID already exists, an <link id="EResourceDuplicateException"/> exception is raised.</p>
  1871. </errors>
  1872. <seealso>
  1873. <link id="TResources.AddAutoID"/>
  1874. </seealso>
  1875. </element>
  1876. <!-- argument Visibility: default -->
  1877. <element name="TResources.Add.aResource">
  1878. <short>The resource to add</short>
  1879. </element>
  1880. <!-- function Visibility: public -->
  1881. <element name="TResources.AddAutoID">
  1882. <short>Adds a resource and gives it a new autogenerated name</short>
  1883. <descr>
  1884. <p>This method tries to find a spare ID to use as a name for the given resource, assigns it to the resource, and adds it.</p>
  1885. <p>This method is useful when the name of the resource is not important. E.g. a group resource doesn't care about the names of its sub-resources, so it could use this method to ensure that its sub-resources don't clash with names of other sub-resources of the same type.</p>
  1886. </descr>
  1887. <errors>
  1888. <p>If there are no more free IDs for the resource type of the given resource (that is, when the number of resources of the same type of <var>aResource</var> with an ID name is equal to 65536) an <link id="ENoMoreFreeIDsException"/> exception is raised.</p>
  1889. </errors>
  1890. <seealso>
  1891. <link id="TResources.Add"/>
  1892. </seealso>
  1893. </element>
  1894. <!-- function result Visibility: default -->
  1895. <element name="TResources.AddAutoID.Result">
  1896. <short>The autogenerated ID of the added resource</short>
  1897. </element>
  1898. <!-- argument Visibility: default -->
  1899. <element name="TResources.AddAutoID.aResource">
  1900. <short>The resource to add</short>
  1901. </element>
  1902. <!-- procedure Visibility: public -->
  1903. <element name="TResources.Clear">
  1904. <short>Deletes all resources</short>
  1905. <descr>
  1906. <p>This method empties the TResources object destroying all resources.</p>
  1907. </descr>
  1908. </element>
  1909. <!-- function Visibility: public -->
  1910. <element name="TResources.FindReader">
  1911. <short>Searches for a suitable resource reader</short>
  1912. <descr>
  1913. <p>This method tries to find a resource reader able to read the stream passed as parameter.</p>
  1914. <p>If an extension is specified, only readers matching that extension are tried. The extension is case-insensitive and includes the leading dot, unless the empty string is passed (which means "no extension", e.g. a unix executable, which doesn't have an extension).</p>
  1915. <p>If a suitable reader is found, an instance of that reader is returned.</p>
  1916. <remark>To make a resource reader class known, add that resource reader unit to the uses clause of your program.</remark>
  1917. </descr>
  1918. <errors>
  1919. <p>If no suitable reader is found, an <link id="EResourceReaderNotFoundException"/> exception is raised.</p>
  1920. </errors>
  1921. <seealso>
  1922. <link id="TAbstractResourceReader"/>
  1923. </seealso>
  1924. </element>
  1925. <!-- function result Visibility: default -->
  1926. <element name="TResources.FindReader.Result">
  1927. <short>An instance of a <link id="TAbstractResourceReader"/> descendant.</short>
  1928. </element>
  1929. <!-- argument Visibility: default -->
  1930. <element name="TResources.FindReader.aStream">
  1931. <short>The stream to be probed</short>
  1932. </element>
  1933. <!-- argument Visibility: default -->
  1934. <element name="TResources.FindReader.aExtension">
  1935. <short>The extension the reader is registered for</short>
  1936. </element>
  1937. <!-- procedure Visibility: public -->
  1938. <element name="TResources.MoveFrom">
  1939. <short>Moves all resources of another TResources object to itself</short>
  1940. <descr>
  1941. <p>This method takes all resources from object <var>aResources</var> and adds them to this object. <var>aResources</var> object is left empty.</p>
  1942. </descr>
  1943. <errors>
  1944. <p>If a resource with the same type, name and language ID already exists, an <link id="EResourceDuplicateException"/> exception is raised.</p>
  1945. </errors>
  1946. <seealso>
  1947. <link id="TResources.Add"/>
  1948. </seealso>
  1949. </element>
  1950. <!-- argument Visibility: default -->
  1951. <element name="TResources.MoveFrom.aResources">
  1952. <short>The TResources object from which resources must be taken</short>
  1953. </element>
  1954. <!-- function Visibility: public -->
  1955. <element name="TResources.Remove">
  1956. <short>Removes a resource</short>
  1957. <descr>
  1958. <p>This method searches for a resource based on passed parameters and removes it from the object.</p>
  1959. <p>The removed resource is then returned.</p>
  1960. </descr>
  1961. <errors>
  1962. <p>If no matching resource is found, an <link id="EResourceNotFoundException"/> exception is raised.</p>
  1963. </errors>
  1964. <seealso>
  1965. <link id="TResources.Find"/>
  1966. </seealso>
  1967. </element>
  1968. <!-- function result Visibility: default -->
  1969. <element name="TResources.Remove.Result">
  1970. <short>The removed resource</short>
  1971. </element>
  1972. <!-- argument Visibility: default -->
  1973. <element name="TResources.Remove.aType">
  1974. <short>The type of the resource to search for</short>
  1975. </element>
  1976. <!-- argument Visibility: default -->
  1977. <element name="TResources.Remove.aName">
  1978. <short>The name of the resource to search for</short>
  1979. </element>
  1980. <!-- argument Visibility: default -->
  1981. <element name="TResources.Remove.aLangID">
  1982. <short>The language ID of the resource to search for</short>
  1983. </element>
  1984. <!-- argument Visibility: default -->
  1985. <element name="TResources.Remove.aResource">
  1986. <short>The resource to remove</short>
  1987. </element>
  1988. <!-- argument Visibility: default -->
  1989. <element name="TResources.Remove.aIndex">
  1990. <short>The index of the resource to remove</short>
  1991. </element>
  1992. <!-- procedure Visibility: public -->
  1993. <element name="TResources.LoadFromStream">
  1994. <short>Loads the contents of the object from a stream</short>
  1995. <descr>
  1996. <p>This method clears the TResources object and loads its contents from the stream passed as parameter.</p>
  1997. <p>If a reader is specified, that reader is used. Otherwise, the stream is probed to find a suitable reader.</p>
  1998. <remark>If <link id="TResources.CacheData">CacheData</link> is set to <var>true</var>, the stream will be used as the underlying stream of each resource <link id="TAbstractResource.RawData">RawData</link> stream. This means that the stream must not be freed until all resources in the TResources object are freed: this happens when the TResources object is cleared or is loaded again from a different source. If you need to free the stream while there are still resources, disable the copy-on-write mechanism by setting <link id="TResources.CacheData">CacheData</link> property to <var>false</var>.</remark>
  1999. </descr>
  2000. <errors>
  2001. <p>If no reader is passed and probing fails, an <link id="EResourceReaderNotFoundException"/> exception is raised.</p>
  2002. </errors>
  2003. <seealso>
  2004. <link id="TAbstractResourceReader"/>
  2005. <link id="TAbstractResource.RawData"/>
  2006. <link id="TAbstractResource.CacheData"/>
  2007. <link id="TResources.CacheData"/>
  2008. <link id="TResources.LoadFromFile"/>
  2009. <link id="TResources.Clear"/>
  2010. <link id="TResources.FindReader"/>
  2011. </seealso>
  2012. </element>
  2013. <!-- argument Visibility: default -->
  2014. <element name="TResources.LoadFromStream.aStream">
  2015. <short>The stream to read from</short>
  2016. </element>
  2017. <!-- argument Visibility: default -->
  2018. <element name="TResources.LoadFromStream.aReader">
  2019. <short>The resource reader to use to read the stream</short>
  2020. </element>
  2021. <!-- procedure Visibility: public -->
  2022. <element name="TResources.LoadFromFile">
  2023. <short>Loads the contents of the object from a file</short>
  2024. <descr>
  2025. <p>This method clears the TResources object and loads its contents from the file passed as parameter.</p>
  2026. <p>If a reader is specified, that reader is used. Otherwise, the file is probed to find a suitable reader.</p>
  2027. <remark>If <link id="TResources.CacheData">CacheData</link> is set to <var>true</var>, the file will be left open and used as the underlying stream of each resource <link id="TAbstractResource.RawData">RawData</link> stream. This means that the file will be open until the TResources object is cleared or is loaded again from a different source. If you want the file to be closed while there are still resources, disable the copy-on-write mechanism by setting <link id="TResources.CacheData">CacheData</link> property to <var>false</var>.</remark>
  2028. <p><b>Sample code</b></p>
  2029. <p>This code extracts resources from an exe file</p>
  2030. <code>
  2031. var
  2032. resources : TResources;
  2033. begin
  2034. resources:=TResources.Create;
  2035. resources.LoadFromFile('myexe.exe');
  2036. resources.WriteToFile('myexe.res');
  2037. resources.Free;
  2038. end;
  2039. </code>
  2040. </descr>
  2041. <errors>
  2042. <p>If no reader is passed and probing fails, an <link id="EResourceReaderNotFoundException"/> exception is raised.</p>
  2043. </errors>
  2044. <seealso>
  2045. <link id="TAbstractResourceReader"/>
  2046. <link id="TAbstractResource.RawData"/>
  2047. <link id="TAbstractResource.CacheData"/>
  2048. <link id="TResources.CacheData"/>
  2049. <link id="TResources.LoadFromStream"/>
  2050. <link id="TResources.Clear"/>
  2051. <link id="TResources.FindReader"/>
  2052. </seealso>
  2053. </element>
  2054. <!-- argument Visibility: default -->
  2055. <element name="TResources.LoadFromFile.aFileName">
  2056. <short>The name of file to read from</short>
  2057. </element>
  2058. <!-- argument Visibility: default -->
  2059. <element name="TResources.LoadFromFile.aReader">
  2060. <short>The reader to use to read the file</short>
  2061. </element>
  2062. <!-- procedure Visibility: public -->
  2063. <element name="TResources.RegisterReader">
  2064. <short>Registers a resource reader class</short>
  2065. <descr>
  2066. <p>This class method registers a resource reader class.</p>
  2067. <p>When registered, a class is known to TResources class, and can be used by <link id="TResources.FindReader">FindReader</link>, <link id="TResources.LoadFromStream">LoadFromStream</link> and <link id="TResources.LoadFromFile">LoadFromFile</link> methods when probing.</p>
  2068. <p>Usually this method is called in the <var>initialization</var> section of the unit implementing a <link id="TAbstractResourceReader"/> descendant.</p>
  2069. <p>A class can be registered multiple times, one for each extension it is able to read. Multiple class can be registered for the same extension (e.g. both a coff and a elf reader can be registered for the .o extension). The extension must include the leading dot unless the empty string is used (which means "no extension", e.g. a unix executable, which doesn't have an extension).</p>
  2070. </descr>
  2071. <seealso>
  2072. <link id="TAbstractResourceReader"/>
  2073. <link id="TResources.FindReader"/>
  2074. <link id="TResources.LoadFromStream"/>
  2075. <link id="TResources.LoadFromFile"/>
  2076. </seealso>
  2077. </element>
  2078. <!-- argument Visibility: default -->
  2079. <element name="TResources.RegisterReader.aExtension">
  2080. <short>The extension for which the class must be registered</short>
  2081. </element>
  2082. <!-- argument Visibility: default -->
  2083. <element name="TResources.RegisterReader.aClass">
  2084. <short>The <link id="TAbstractResourceReader"/> descendant to register</short>
  2085. </element>
  2086. <!-- procedure Visibility: public -->
  2087. <element name="TResources.RegisterWriter">
  2088. <short>Registers a resource writer class</short>
  2089. <descr>
  2090. <p>This class method registers a resource writer class.</p>
  2091. <p>When registered, a class is known to TResources class, and can be used by <link id="TResources.WriteToFile">WriteToFile</link> method when probing.</p>
  2092. <p>Usually this method is called in the <var>initialization</var> section of the unit implementing a <link id="TAbstractResourceWriter"/> descendant.</p>
  2093. <p>A class can be registered multiple times, one for each extension it is able to write. Multiple class can be registered for the same extension (e.g. both a coff and a elf writer can be registered for the .o extension) although only the first one found will be used when probing. The extension must include the leading dot unless the empty string is used (which means "no extension", e.g. a unix executable, which doesn't have an extension).</p>
  2094. </descr>
  2095. <seealso>
  2096. <link id="TAbstractResourceWriter"/>
  2097. <link id="TResources.WriteToFile"/>
  2098. </seealso>
  2099. </element>
  2100. <!-- argument Visibility: default -->
  2101. <element name="TResources.RegisterWriter.aExtension">
  2102. <short>The extension for which the class must be registered</short>
  2103. </element>
  2104. <!-- argument Visibility: default -->
  2105. <element name="TResources.RegisterWriter.aClass">
  2106. <short>The <link id="TAbstractResourceWriter"/> descendant to register</short>
  2107. </element>
  2108. <!-- procedure Visibility: public -->
  2109. <element name="TResources.WriteToStream">
  2110. <short>Writes the contents of the object to a stream</short>
  2111. <descr>
  2112. <p>This method writes the contents of the object to a stream via the specified <link id="TAbstractResourceWriter"/> descendant</p>
  2113. </descr>
  2114. <seealso>
  2115. <link id="TAbstractResourceWriter"/>
  2116. <link id="TResources.WriteToFile"/>
  2117. </seealso>
  2118. </element>
  2119. <!-- argument Visibility: default -->
  2120. <element name="TResources.WriteToStream.aStream">
  2121. <short>The stream to write to</short>
  2122. </element>
  2123. <!-- argument Visibility: default -->
  2124. <element name="TResources.WriteToStream.aWriter">
  2125. <short>The resource writer to use to write the stream</short>
  2126. </element>
  2127. <!-- procedure Visibility: public -->
  2128. <element name="TResources.WriteToFile">
  2129. <short>Writes the contents of the object to a file</short>
  2130. <descr>
  2131. <p>This method writes the contents of the object to a file whose name is passed as parameter.</p>
  2132. <p>If a writer is specified, that writer is used. Otherwise, the first registered writer matching the file name extension is used.</p>
  2133. </descr>
  2134. <errors>
  2135. <p>If no writer is passed and no suitable writer is found, an <link id="EResourceWriterNotFoundException"/> exception is raised.</p>
  2136. </errors>
  2137. <seealso>
  2138. <link id="TAbstractResourceWriter"/>
  2139. <link id="TResources.WriteToStream"/>
  2140. </seealso>
  2141. </element>
  2142. <!-- argument Visibility: default -->
  2143. <element name="TResources.WriteToFile.aFileName">
  2144. <short>The name of the file to write to</short>
  2145. </element>
  2146. <!-- argument Visibility: default -->
  2147. <element name="TResources.WriteToFile.aWriter">
  2148. <short>The resource writer to use to write to the file</short>
  2149. </element>
  2150. <!-- property Visibility: public -->
  2151. <element name="TResources.Count">
  2152. <short>The number of resources in the object</short>
  2153. <seealso>
  2154. <link id="TResources.Items"/>
  2155. </seealso>
  2156. </element>
  2157. <!-- property Visibility: public -->
  2158. <element name="TResources.Items">
  2159. <short>Indexed array of resources in the object</short>
  2160. <descr>
  2161. <p>This property can be used to access all resources in the object.</p>
  2162. <remark>This array is 0-based: valid elements range from 0 to <link id="TResources.Count">Count</link>-1.</remark>
  2163. </descr>
  2164. <seealso>
  2165. <link id="TResources.Count"/>
  2166. <link id="TAbstractResource"/>
  2167. </seealso>
  2168. </element>
  2169. <!-- argument Visibility: default -->
  2170. <element name="TResources.Items.Index">
  2171. <short>The index of the resource to access</short>
  2172. </element>
  2173. <!-- property Visibility: public -->
  2174. <element name="TResources.CacheData">
  2175. <short>Controls the copy-on-write behaviour of all resources</short>
  2176. <descr>
  2177. <p>Changing this property changes <link id="TAbstractResource.CacheData">CacheData</link> property of all resources contained in the object.</p>
  2178. <p>This property affects existing resources and resources that are added or loaded.</p>
  2179. <p>By default, CacheData is true.</p>
  2180. </descr>
  2181. <seealso>
  2182. <link id="TAbstractResource.CacheData"/>
  2183. <link id="TAbstractResource.RawData"/>
  2184. </seealso>
  2185. </element>
  2186. <!-- procedure Visibility: protected -->
  2187. <element name="TAbstractResourceReader.SetDataSize">
  2188. <short>Protected method to let a reader set a resource <link id="TAbstractResource.DataSize">DataSize</link> property</short>
  2189. <descr>
  2190. <p>This method allows a descendant class to set <link id="TAbstractResource.DataSize">DataSize</link> property of a resource that is being loaded.</p>
  2191. </descr>
  2192. <seealso>
  2193. <link id="TAbstractResourceReader.SetHeaderSize"/>
  2194. <link id="TAbstractResourceReader.SetDataOffset"/>
  2195. <link id="TAbstractResourceReader.SetRawData"/>
  2196. </seealso>
  2197. </element>
  2198. <!-- argument Visibility: default -->
  2199. <element name="TAbstractResourceReader.SetDataSize.aResource">
  2200. <short>The resource whose <link id="TAbstractResource.DataSize">DataSize</link> property must be set</short>
  2201. </element>
  2202. <!-- argument Visibility: default -->
  2203. <element name="TAbstractResourceReader.SetDataSize.aValue">
  2204. <short>The value to set the property to</short>
  2205. </element>
  2206. <!-- procedure Visibility: protected -->
  2207. <element name="TAbstractResourceReader.SetHeaderSize">
  2208. <short>Protected method to let a reader set a resource <link id="TAbstractResource.HeaderSize">HeaderSize</link> property</short>
  2209. <descr>
  2210. <p>This method allows a descendant class to set <link id="TAbstractResource.HeaderSize">HeaderSize</link> property of a resource that is being loaded.</p>
  2211. </descr>
  2212. <seealso>
  2213. <link id="TAbstractResourceReader.SetDataSize"/>
  2214. <link id="TAbstractResourceReader.SetDataOffset"/>
  2215. <link id="TAbstractResourceReader.SetRawData"/>
  2216. </seealso>
  2217. </element>
  2218. <!-- argument Visibility: default -->
  2219. <element name="TAbstractResourceReader.SetHeaderSize.aResource">
  2220. <short>The resource whose <link id="TAbstractResource.HeaderSize">HeaderSize</link> property must be set</short>
  2221. </element>
  2222. <!-- argument Visibility: default -->
  2223. <element name="TAbstractResourceReader.SetHeaderSize.aValue">
  2224. <short>The value to set the property to</short>
  2225. </element>
  2226. <!-- procedure Visibility: protected -->
  2227. <element name="TAbstractResourceReader.SetDataOffset">
  2228. <short>Protected method to let a reader set a resource <link id="TAbstractResource.DataOffset">DataOffset</link> property</short>
  2229. <descr>
  2230. <p>This method allows a descendant class to set <link id="TAbstractResource.DataOffset">DataOffset</link> property of a resource that is being loaded.</p>
  2231. </descr>
  2232. <seealso>
  2233. <link id="TAbstractResourceReader.SetDataSize"/>
  2234. <link id="TAbstractResourceReader.SetHeaderSize"/>
  2235. <link id="TAbstractResourceReader.SetRawData"/>
  2236. </seealso>
  2237. </element>
  2238. <!-- argument Visibility: default -->
  2239. <element name="TAbstractResourceReader.SetDataOffset.aResource">
  2240. <short>The resource whose <link id="TAbstractResource.DataOffset">DataOffset</link> property must be set</short>
  2241. </element>
  2242. <!-- argument Visibility: default -->
  2243. <element name="TAbstractResourceReader.SetDataOffset.aValue">
  2244. <short>The value to set the property to</short>
  2245. </element>
  2246. <!-- procedure Visibility: protected -->
  2247. <element name="TAbstractResourceReader.SetRawData">
  2248. <short>Protected method to let a reader set a resource <link id="TAbstractResource.RawData">RawData</link> property</short>
  2249. <descr>
  2250. <p>This method allows a descendant class to set <link id="TAbstractResource.RawData">RawData</link> property of a resource that is being loaded.</p>
  2251. </descr>
  2252. <seealso>
  2253. <link id="TAbstractResourceReader.SetDataSize"/>
  2254. <link id="TAbstractResourceReader.SetHeaderSize"/>
  2255. <link id="TAbstractResourceReader.SetDataOffset"/>
  2256. </seealso>
  2257. </element>
  2258. <!-- argument Visibility: default -->
  2259. <element name="TAbstractResourceReader.SetRawData.aResource">
  2260. <short>The resource whose <link id="TAbstractResource.RawData">RawData</link> property must be set</short>
  2261. </element>
  2262. <!-- argument Visibility: default -->
  2263. <element name="TAbstractResourceReader.SetRawData.aStream">
  2264. <short>The value to set the property to</short>
  2265. </element>
  2266. <!-- procedure Visibility: protected -->
  2267. <element name="TAbstractResourceReader.CallSubReaderLoad">
  2268. <short>Calls another reader's <link id="TAbstractResourceReader.Load">Load</link> method</short>
  2269. <descr>
  2270. <p>This method allows a descendant class to call another reader's <link id="TAbstractResourceReader.Load">Load</link> method. This can be useful when a reader needs to use another one.</p>
  2271. </descr>
  2272. </element>
  2273. <!-- argument Visibility: default -->
  2274. <element name="TAbstractResourceReader.CallSubReaderLoad.aReader">
  2275. <short>The reader whose <link id="TAbstractResourceReader.Load">Load</link> method must be called</short>
  2276. </element>
  2277. <!-- argument Visibility: default -->
  2278. <element name="TAbstractResourceReader.CallSubReaderLoad.aResources">
  2279. <short>The <var>aResources</var> parameter of <link id="TAbstractResourceReader.Load">Load</link> method</short>
  2280. </element>
  2281. <!-- argument Visibility: default -->
  2282. <element name="TAbstractResourceReader.CallSubReaderLoad.aStream">
  2283. <short>The <var>aStream</var> parameter of <link id="TAbstractResourceReader.Load">Load</link> method</short>
  2284. </element>
  2285. <!-- procedure Visibility: protected -->
  2286. <element name="TAbstractResourceReader.AddNoTree">
  2287. <short>Adds a resource without updating the internal tree</short>
  2288. <descr>
  2289. <p>This protected method is used by descendents of <link id="TAbstractResourceReader"/> after they add new resources to the internal resource tree used by a <link id="TResources"/> object. Calling this method notifies the <link id="TResources"/> object about the newly-added resource.</p>
  2290. </descr>
  2291. <seealso>
  2292. <link id="TAbstractResourceReader.GetTree"/>
  2293. <link id="resourcetree.TRootResTreeNode">TRootResTreeNode</link>
  2294. </seealso>
  2295. </element>
  2296. <!-- argument Visibility: default -->
  2297. <element name="TAbstractResourceReader.AddNoTree.aResources">
  2298. <short>The TResources object to be notified</short>
  2299. </element>
  2300. <!-- argument Visibility: default -->
  2301. <element name="TAbstractResourceReader.AddNoTree.aResource">
  2302. <short>The resource that has been added to the tree</short>
  2303. </element>
  2304. <!-- procedure Visibility: protected -->
  2305. <element name="TAbstractResourceReader.GetTree">
  2306. <short>Gets the internal resource tree of a TResources object</short>
  2307. <descr>
  2308. <p>This protected method can be used by descendents of <link id="TAbstractResourceReader"/> to obtain the internal resource tree used by a <link id="TResources"/> object. The internal resource tree is an instance of <link id="resourcetree.TRootResTreeNode">TRootResTreeNode</link>.</p>
  2309. <p>Some resource readers can improve their performance if, instead of calling <link id="TResources.Add"/>, add themselves resources to the internal tree used by a <link id="TResources"/> object.</p>
  2310. <remark>After adding a resource to a resource tree, a reader must always call <link id="TAbstractResourceReader.AddNoTree">AddNoTree</link> method to let the <link id="TResources"/> object know about the newly-added resource.</remark>
  2311. </descr>
  2312. <seealso>
  2313. <link id="TAbstractResourceReader.AddNoTree"/>
  2314. <link id="resourcetree.TRootResTreeNode">TRootResTreeNode</link>
  2315. </seealso>
  2316. </element>
  2317. <!-- argument Visibility: default -->
  2318. <element name="TAbstractResourceReader.GetTree.aResources">
  2319. <short>The <link id="TResources"/> object whose tree must be returned</short>
  2320. </element>
  2321. <!-- function result Visibility: default -->
  2322. <element name="TAbstractResourceReader.GetTree.Result">
  2323. <short>The resource tree. It is an instance of <var>TRootResTreeNode</var>.</short>
  2324. </element>
  2325. <!-- function Visibility: protected -->
  2326. <element name="TAbstractResourceReader.GetExtensions">
  2327. <short>Returns the extensions the reader is registered for</short>
  2328. <descr>
  2329. <p>Descendant classes must implement this method to provide access to <link id="TAbstractResourceReader.Extensions">Extensions</link> property.</p>
  2330. </descr>
  2331. <seealso>
  2332. <link id="TAbstractResourceReader.Extensions"/>
  2333. </seealso>
  2334. </element>
  2335. <!-- function result Visibility: default -->
  2336. <element name="TAbstractResourceReader.GetExtensions.Result">
  2337. <short>The extensions the reader is registered for</short>
  2338. </element>
  2339. <!-- function Visibility: protected -->
  2340. <element name="TAbstractResourceReader.GetDescription">
  2341. <short>Returns the description of the reader</short>
  2342. <descr>
  2343. <p>Descendant classes must implement this method to provide access to <link id="TAbstractResourceReader.Description">Description</link> property.</p>
  2344. </descr>
  2345. <seealso>
  2346. <link id="TAbstractResourceReader.Description"/>
  2347. </seealso>
  2348. </element>
  2349. <!-- function result Visibility: default -->
  2350. <element name="TAbstractResourceReader.GetDescription.Result">
  2351. <short>The description of the reader</short>
  2352. </element>
  2353. <!-- procedure Visibility: protected -->
  2354. <element name="TAbstractResourceReader.Load">
  2355. <short>Loads resources from a stream</short>
  2356. <descr>
  2357. <p>A <link id="TResources"/> object invokes this method when it needs to be loaded from a stream, passing itself as the <var>aResources</var> parameter and the stream as the <var>aStream</var> parameter.</p>
  2358. <p><var>aStream</var> position is already correctly set: the reader must start to read from there.</p>
  2359. <p>Descendant classes must ensure that the the stream is in a format they recognize, otherwise an <link id="EResourceReaderWrongFormatException"/> exception must be raised.</p>
  2360. <p>Each resource is then created, read from the stream and added to the <link id="TResources"/> object.</p>
  2361. <p>When reading a resource, a reader must:</p>
  2362. <ul>
  2363. <li>Create the resource via <link id="resfactory.TResourceFactory.CreateResource">TResourceFactory.CreateResource</link> class method with the correct type and name.</li>
  2364. <li><p>Set at least the following resource properties:</p>
  2365. <ul>
  2366. <li><link id="TAbstractResource.DataSize">DataSize</link>, via <link id="TAbstractResourceReader.SetDataSize">SetDataSize</link> method.</li>
  2367. <li><link id="TAbstractResource.DataOffset">DataOffset</link>, via <link id="TAbstractResourceReader.SetDataOffset">SetDataSize</link> method. This is the offset of the resource data from the beginning of the stream.</li>
  2368. <li><link id="TAbstractResource.RawData">RawData</link>. The reader must create a <link id="resdatastream.TResourceDataStream">TResourceDataStream</link> object and assign it to the resource via <link id="TAbstractResourceReader.SetRawData">SetRawData</link> method.</li>
  2369. </ul>
  2370. </li>
  2371. </ul>
  2372. </descr>
  2373. <errors>
  2374. <p>If the stream is in a format not recognized by the reader, a <link id="EResourceReaderWrongFormatException"/> exception must be raised.</p>
  2375. <p>If the stream ends prematurely, a <link id="EResourceReaderUnexpectedEndOfStreamException"/> exception must be raised.</p>
  2376. </errors>
  2377. <seealso>
  2378. <link id="TResources"/>
  2379. <link id="TResources.LoadFromStream"/>
  2380. <link id="TResources.LoadFromFile"/>
  2381. <link id="TAbstractResource"/>
  2382. <link id="TAbstractResource.DataSize"/>
  2383. <link id="TAbstractResource.DataOffset"/>
  2384. <link id="TAbstractResource.RawData"/>
  2385. <link id="TAbstractResourceReader.SetDataSize"/>
  2386. <link id="TAbstractResourceReader.SetDataOffset"/>
  2387. <link id="TAbstractResourceReader.SetRawData"/>
  2388. <link id="TAbstractResourceReader.CheckMagic"/>
  2389. <link id="resdatastream.TResourceDataStream">TResourceDataStream</link>
  2390. </seealso>
  2391. </element>
  2392. <!-- argument Visibility: default -->
  2393. <element name="TAbstractResourceReader.Load.aResources">
  2394. <short>The <link id="TResources"/> object to be loaded from the stream</short>
  2395. </element>
  2396. <!-- argument Visibility: default -->
  2397. <element name="TAbstractResourceReader.Load.aStream">
  2398. <short>The stream which resources must be loaded from </short>
  2399. </element>
  2400. <!-- function Visibility: protected -->
  2401. <element name="TAbstractResourceReader.CheckMagic">
  2402. <short>Checks whether a stream is in a format the reader recognizes</short>
  2403. <descr>
  2404. <p>A <link id="TResources"/> object invokes this method when it is searching for a reader able to read a stream, passing that stream as the <var>aStream</var> parameter.</p>
  2405. <p><var>aStream</var> position is already correctly set: the reader must start to read from there.</p>
  2406. <p>This method should read the minimum amount of information needed to recognize the contents of a stream as a valid format: it usually means reading a magic number or a file header.</p>
  2407. </descr>
  2408. <seealso>
  2409. <link id="TAbstractResourceReader.Load"/>
  2410. <link id="TResources.FindReader"/>
  2411. <link id="TResources.LoadFromStream"/>
  2412. <link id="TResources.LoadFromFile"/>
  2413. </seealso>
  2414. </element>
  2415. <!-- function result Visibility: default -->
  2416. <element name="TAbstractResourceReader.CheckMagic.Result">
  2417. <short><var>true</var> if the format of the stream is recognized</short>
  2418. </element>
  2419. <!-- argument Visibility: default -->
  2420. <element name="TAbstractResourceReader.CheckMagic.aStream">
  2421. <short>The stream to check</short>
  2422. </element>
  2423. <!-- constructor Visibility: public -->
  2424. <element name="TAbstractResourceReader.Create">
  2425. <short>Creates a new reader object</short>
  2426. </element>
  2427. <!-- property Visibility: public -->
  2428. <element name="TAbstractResourceReader.Extensions">
  2429. <short>The extensions of file types the reader is able to read</short>
  2430. <descr>
  2431. <p>This property is a string made of space-separated file extensions (each including the leading dot), all lowercase.</p>
  2432. <p>This property signals which file types the reader is able to read.</p>
  2433. </descr>
  2434. </element>
  2435. <!-- property Visibility: public -->
  2436. <element name="TAbstractResourceReader.Description">
  2437. <short>The reader description</short>
  2438. <descr>
  2439. <p>This property provides a textual description of the reader, e.g. "FOO resource reader"</p>
  2440. </descr>
  2441. </element>
  2442. <!-- procedure Visibility: protected -->
  2443. <element name="TAbstractResourceWriter.GetTree">
  2444. <short>Gets the internal resource tree of a TResources object</short>
  2445. <descr>
  2446. <p>This protected method can be used by descendents of <link id="TAbstractResourceWriter"/> to obtain the internal resource tree used by a <link id="TResources"/> object. The internal resource tree is an instance of <link id="resourcetree.TRootResTreeNode">TRootResTreeNode</link>.</p>
  2447. <p>Some resource writers need to order resources with a tree structure before writing them to a file. Instead of doing this work themselves, they can use the already-ordered internal resource tree of the <link id="TResources"/> object they must write.</p>
  2448. </descr>
  2449. <seealso>
  2450. <link id="resourcetree.TRootResTreeNode">TRootResTreeNode</link>
  2451. </seealso>
  2452. </element>
  2453. <!-- argument Visibility: default -->
  2454. <element name="TAbstractResourceWriter.GetTree.aResources">
  2455. <short>The <link id="TResources"/> object whose tree must be returned</short>
  2456. </element>
  2457. <!-- function result Visibility: default -->
  2458. <element name="TAbstractResourceWriter.GetTree.Result">
  2459. <short>The resource tree. It is an instance of <var>TRootResTreeNode</var>.</short>
  2460. </element>
  2461. <!-- function Visibility: protected -->
  2462. <element name="TAbstractResourceWriter.GetExtensions">
  2463. <short>Returns the extensions the writer is registered for</short>
  2464. <descr>
  2465. <p>Descendant classes must implement this method to provide access to <link id="TAbstractResourceWriter.Extensions">Extensions</link> property.</p>
  2466. </descr>
  2467. <seealso>
  2468. <link id="TAbstractResourceWriter.Extensions"/>
  2469. </seealso>
  2470. </element>
  2471. <!-- function result Visibility: default -->
  2472. <element name="TAbstractResourceWriter.GetExtensions.Result">
  2473. <short>The extensions the writer is registered for</short>
  2474. </element>
  2475. <!-- function Visibility: protected -->
  2476. <element name="TAbstractResourceWriter.GetDescription">
  2477. <short>Returns the description of the writer</short>
  2478. <descr>
  2479. <p>Descendant classes must implement this method to provide access to <link id="TAbstractResourceWriter.Description">Description</link> property.</p>
  2480. </descr>
  2481. <seealso>
  2482. <link id="TAbstractResourceWriter.Description"/>
  2483. </seealso>
  2484. </element>
  2485. <!-- function result Visibility: default -->
  2486. <element name="TAbstractResourceWriter.GetDescription.Result">
  2487. <short>The description of the writer</short>
  2488. </element>
  2489. <!-- procedure Visibility: protected -->
  2490. <element name="TAbstractResourceWriter.Write">
  2491. <short>Writes resources to a stream</short>
  2492. <descr>
  2493. <p>A <link id="TResources"/> object invokes this method when it needs to be written to a stream, passing itself as the <var>aResources</var> parameter and the stream as the <var>aStream</var> parameter.</p>
  2494. <p><var>aStream</var> position is already correctly set: the writer must start to write from there.</p>
  2495. <p>A writer must write data in the way specified by the format it supports: usually this means writing a header and all resources contained in the <link id="TResources"/> object.</p>
  2496. <p>For each resource, a writer should write some information about the resource (like type and name) in a way defined by the format it implements, and the resource data, which is accessible by <link id="TAbstractResource.RawData">RawData</link> property of the resource.</p>
  2497. </descr>
  2498. <seealso>
  2499. <link id="TResources"/>
  2500. <link id="TResources.WriteToStream"/>
  2501. <link id="TResources.WriteToFile"/>
  2502. <link id="TAbstractResource"/>
  2503. <link id="TAbstractResource.DataSize"/>
  2504. <link id="TAbstractResource.RawData"/>
  2505. </seealso>
  2506. </element>
  2507. <!-- argument Visibility: default -->
  2508. <element name="TAbstractResourceWriter.Write.aResources">
  2509. <short>The <link id="TResources"/> object to be written to the stream</short>
  2510. </element>
  2511. <!-- argument Visibility: default -->
  2512. <element name="TAbstractResourceWriter.Write.aStream">
  2513. <short>The stream which resources must be written to</short>
  2514. </element>
  2515. <!-- constructor Visibility: public -->
  2516. <element name="TAbstractResourceWriter.Create">
  2517. <short>Creates a new writer object</short>
  2518. </element>
  2519. <!-- property Visibility: public -->
  2520. <element name="TAbstractResourceWriter.Extensions">
  2521. <short>The extensions of file types the writer is able to write</short>
  2522. <descr>
  2523. <p>This property is a string made of space-separated file extensions (each including the leading dot), all lowercase.</p>
  2524. <p>This property signals which file types the writer is able to write.</p>
  2525. </descr>
  2526. </element>
  2527. <!-- property Visibility: public -->
  2528. <element name="TAbstractResourceWriter.Description">
  2529. <short>The writer description</short>
  2530. <descr>
  2531. <p>This property provides a textual description of the writer, e.g. "FOO resource writer"</p>
  2532. </descr>
  2533. </element>
  2534. </module> <!-- resource -->
  2535. </package>
  2536. </fpdoc-descriptions>