objects.tex 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220
  1. %
  2. % $Id$
  3. % This file is part of the FPC documentation.
  4. % Copyright (C) 1998, by Michael Van Canneyt
  5. %
  6. % The FPC documentation is free text; you can redistribute it and/or
  7. % modify it under the terms of the GNU Library General Public License as
  8. % published by the Free Software Foundation; either version 2 of the
  9. % License, or (at your option) any later version.
  10. %
  11. % The FPC Documentation is distributed in the hope that it will be useful,
  12. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. % Library General Public License for more details.
  15. %
  16. % You should have received a copy of the GNU Library General Public
  17. % License along with the FPC documentation; see the file COPYING.LIB. If not,
  18. % write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. % Boston, MA 02111-1307, USA.
  20. %
  21. \chapter{The Objects unit.}
  22. This chapter documents the \file{objects} unit. The unit was implemented by
  23. many people, and was mainly taken from the FreeVision sources.
  24. The methods and fields that are in a \var{Private} part of an object
  25. declaration have been left out of this documentation.
  26. \section{Constants}
  27. The following constants are error codes, returned by the various stream
  28. objects.
  29. \begin{verbatim}
  30. CONST
  31. stOk = 0; { No stream error }
  32. stError = -1; { Access error }
  33. stInitError = -2; { Initialize error }
  34. stReadError = -3; { Stream read error }
  35. stWriteError = -4; { Stream write error }
  36. stGetError = -5; { Get object error }
  37. stPutError = -6; { Put object error }
  38. stSeekError = -7; { Seek error in stream }
  39. stOpenError = -8; { Error opening stream }
  40. \end{verbatim}
  41. These constants can be passed to constructors of file streams:
  42. \begin{verbatim}
  43. CONST
  44. stCreate = $3C00; { Create new file }
  45. stOpenRead = $3D00; { Read access only }
  46. stOpenWrite = $3D01; { Write access only }
  47. stOpen = $3D02; { Read/write access }
  48. \end{verbatim}
  49. The following constants are error codes, returned by the collection list
  50. objects:
  51. \begin{verbatim}
  52. CONST
  53. coIndexError = -1; { Index out of range }
  54. coOverflow = -2; { Overflow }
  55. \end{verbatim}
  56. Maximum data sizes (used in determining how many data can be used.
  57. \begin{verbatim}
  58. CONST
  59. MaxBytes = 128*1024*1024; { Maximum data size }
  60. MaxWords = MaxBytes DIV SizeOf(Word); { Max word data size }
  61. MaxPtrs = MaxBytes DIV SizeOf(Pointer); { Max ptr data size }
  62. MaxCollectionSize = MaxBytes DIV SizeOf(Pointer); { Max collection size }
  63. \end{verbatim}
  64. \section{Types}
  65. The follwing auxiliary types are defined:
  66. \begin{verbatim}
  67. TYPE
  68. { Character set }
  69. TCharSet = SET Of Char;
  70. PCharSet = ^TCharSet;
  71. { Byte array }
  72. TByteArray = ARRAY [0..MaxBytes-1] Of Byte;
  73. PByteArray = ^TByteArray;
  74. { Word array }
  75. TWordArray = ARRAY [0..MaxWords-1] Of Word;
  76. PWordArray = ^TWordArray;
  77. { Pointer array }
  78. TPointerArray = Array [0..MaxPtrs-1] Of Pointer;
  79. PPointerArray = ^TPointerArray;
  80. { String pointer }
  81. PString = ^String;
  82. { Filename array }
  83. AsciiZ = Array [0..255] Of Char;
  84. Sw_Word = Cardinal;
  85. Sw_Integer = LongInt;
  86. \end{verbatim}
  87. The following records are used internaly for easy type conversion:
  88. \begin{verbatim}
  89. TYPE
  90. { Word to bytes}
  91. WordRec = packed RECORD
  92. Lo, Hi: Byte;
  93. END;
  94. { LongInt to words }
  95. LongRec = packed RECORD
  96. Lo, Hi: Word;
  97. END;
  98. { Pointer to words }
  99. PtrRec = packed RECORD
  100. Ofs, Seg: Word;
  101. END;
  102. \end{verbatim}
  103. The following record is used when streaming objects:
  104. \begin{verbatim}
  105. TYPE
  106. PStreamRec = ^TStreamRec;
  107. TStreamRec = Packed RECORD
  108. ObjType: Sw_Word;
  109. VmtLink: pointer;
  110. Load : Pointer;
  111. Store: Pointer;
  112. Next : PStreamRec;
  113. END;
  114. \end{verbatim}
  115. The \var{TPoint} basic object is used in the \var{TRect} object (see
  116. \sees{TRect}):
  117. \begin{verbatim}
  118. TYPE
  119. PPoint = ^TPoint;
  120. TPoint = OBJECT
  121. X, Y: Sw_Integer;
  122. END;
  123. \end{verbatim}
  124. \section{TRect}
  125. \label{se:TRect}
  126. The \var{TRect} object is declared as follows:
  127. \begin{verbatim}
  128. TRect = OBJECT
  129. A, B: TPoint;
  130. FUNCTION Empty: Boolean;
  131. FUNCTION Equals (R: TRect): Boolean;
  132. FUNCTION Contains (P: TPoint): Boolean;
  133. PROCEDURE Copy (R: TRect);
  134. PROCEDURE Union (R: TRect);
  135. PROCEDURE Intersect (R: TRect);
  136. PROCEDURE Move (ADX, ADY: Sw_Integer);
  137. PROCEDURE Grow (ADX, ADY: Sw_Integer);
  138. PROCEDURE Assign (XA, YA, XB, YB: Sw_Integer);
  139. END;
  140. \end{verbatim}
  141. \begin{function}{TRect.Empty}
  142. \Declaration
  143. Function TRect.Empty: Boolean;
  144. \Description
  145. \var{Empty} returns \var{True} if the rectangle defined by the corner points
  146. \var{A}, \var{B} has zero or negative surface.
  147. \Errors
  148. None.
  149. \SeeAlso
  150. \seef{TRect.Equals}, \seef{TRect.Contains}
  151. \end{function}
  152. \latex{\inputlisting{objectex/ex1.pp}}
  153. \html{\input{objectex/ex1.tex}}
  154. \begin{function}{TRect.Equals}
  155. \Declaration
  156. Function TRect.Equals (R: TRect): Boolean;
  157. \Description
  158. \var{Equals} returns \var{True} if the rectangle has the
  159. same corner points \var{A,B} as the rectangle R, and \var{False}
  160. otherwise.
  161. \Errors
  162. None.
  163. \SeeAlso
  164. \seefl{Empty}{TRect.Empty}, \seefl{Contains}{TRect.Contains}
  165. \end{function}
  166. For an example, see \seef{TRect.Empty}
  167. \begin{function}{TRect.Contains}
  168. \Declaration
  169. Function TRect.Contains (P: TPoint): Boolean;
  170. \Description
  171. \var{Contains} returns \var{True} if the point \var{P} is contained
  172. in the rectangle (including borders), \var{False} otherwise.
  173. \Errors
  174. None.
  175. \SeeAlso
  176. \seepl{Intersect}{TRect.Intersect}, \seefl{Equals}{TRect.Equals}
  177. \end{function}
  178. \begin{procedure}{TRect.Copy}
  179. \Declaration
  180. Procedure TRect.Copy (R: TRect);
  181. \Description
  182. Assigns the rectangle R to the object. After the call to \var{Copy}, the
  183. rectangle R has been copied to the object that invoked \var{Copy}.
  184. \Errors
  185. None.
  186. \SeeAlso
  187. \seepl{Assign}{TRect.Assign}
  188. \end{procedure}
  189. \latex{\inputlisting{objectex/ex2.pp}}
  190. \html{\input{objectex/ex2.tex}}
  191. \begin{procedure}{TRect.Union}
  192. \Declaration
  193. Procedure TRect.Union (R: TRect);
  194. \Description
  195. \var{Union} enlarges the current rectangle so that it becomes the union
  196. of the current rectangle with the rectangle \var{R}.
  197. \Errors
  198. None.
  199. \SeeAlso
  200. \seepl{Intersect}{TRect.Intersect}
  201. \end{procedure}
  202. \latex{\inputlisting{objectex/ex3.pp}}
  203. \html{\input{objectex/ex3.tex}}
  204. \begin{procedure}{TRect.Intersect}
  205. \Declaration
  206. Procedure TRect.Intersect (R: TRect);
  207. \Description
  208. \var{Intersect} makes the intersection of the current rectangle with
  209. \var{R}. If the intersection is empty, then the rectangle is set to the empty
  210. rectangle at coordinate (0,0).
  211. \Errors
  212. None.
  213. \SeeAlso
  214. \seepl{Union}{TRect.Union}
  215. \end{procedure}
  216. \latex{\inputlisting{objectex/ex4.pp}}
  217. \html{\input{objectex/ex4.tex}}
  218. \begin{procedure}{TRect.Move}
  219. \Declaration
  220. Procedure TRect.Move (ADX, ADY: Sw\_Integer);
  221. \Description
  222. \var{Move} moves the current rectangle along a vector with components
  223. \var{(ADX,ADY)}. It adds \var{ADX} to the X-coordinate of both corner
  224. points, and \var{ADY} to both end points.
  225. \Errors
  226. None.
  227. \SeeAlso
  228. \seepl{Grow}{TRect.Grow}
  229. \end{procedure}
  230. \latex{\inputlisting{objectex/ex5.pp}}
  231. \html{\input{objectex/ex5.tex}}
  232. \begin{procedure}{TRect.Grow}
  233. \Declaration
  234. Procedure TRect.Grow (ADX, ADY: Sw\_Integer);
  235. \Description
  236. \var{Grow} expands the rectangle with an amount \var{ADX} in the \var{X}
  237. direction (both on the left and right side of the rectangle, thus adding a
  238. length 2*ADX to the width of the rectangle), and an amount \var{ADY} in
  239. the \var{Y} direction (both on the top and the bottom side of the rectangle,
  240. adding a length 2*ADY to the height of the rectangle.
  241. \var{ADX} and \var{ADY} can be negative. If the resulting rectangle is empty, it is set
  242. to the empty rectangle at \var{(0,0)}.
  243. \Errors
  244. None.
  245. \SeeAlso
  246. \seepl{Move}{TRect.Move}.
  247. \end{procedure}
  248. \latex{\inputlisting{objectex/ex6.pp}}
  249. \html{\input{objectex/ex7.tex}}
  250. \begin{procedure}{TRect.Assign}
  251. \Declaration
  252. Procedure Trect.Assign (XA, YA, XB, YB: Sw\_Integer);
  253. \Description
  254. \var{Assign} sets the corner points of the rectangle to \var{(XA,YA)} and
  255. \var{(Xb,Yb)}.
  256. \Errors
  257. None.
  258. \SeeAlso
  259. \seepl{Copy}{TRect.Copy}
  260. \end{procedure}
  261. For an example, see \seep{TRect.Copy}.
  262. \section{TObject}
  263. \label{se:TObject}
  264. The full declaration of the \var{TObject} type is:
  265. \begin{verbatim}
  266. TYPE
  267. TObject = OBJECT
  268. CONSTRUCTOR Init;
  269. PROCEDURE Free;
  270. DESTRUCTOR Done;Virtual;
  271. END;
  272. PObject = ^TObject;
  273. \end{verbatim}
  274. \begin{procedure}{TObject.Init}
  275. \Declaration
  276. Constructor TObject.Init;
  277. \Description
  278. Instantiates a new object of type \var{TObject}. It fills the instance up
  279. with Zero bytes.
  280. \Errors
  281. None.
  282. \SeeAlso
  283. \seepl{Free}{TObject.Free}, \seepl{Done}{TObject.Done}
  284. \end{procedure}
  285. For an example, see \seepl{Free}{TObject.Free}
  286. \begin{procedure}{TObject.Free}
  287. \Declaration
  288. Procedure TObject.Free;
  289. \Description
  290. \var{Free} calls the destructor of the object, and releases the memory
  291. occupied by the instance of the object.
  292. \Errors
  293. No checking is performed to see whether \var{self} is \var{nil} and whether
  294. the object is indeed allocated on the heap.
  295. \SeeAlso
  296. \seepl{Init}{TObject.Init}, \seepl{Done}{TObject.Done}
  297. \end{procedure}
  298. \latex{\inputlisting{objectex/ex7.pp}}
  299. \html{\input{objectex/ex7.tex}}
  300. \begin{procedure}{TObject.Done}
  301. \Declaration
  302. Destructor TObject.Done;Virtual;
  303. \Description
  304. \var{Done}, the destructor of \var{TObject} does nothing. It is mainly
  305. intended to be used in the \seep{TObject.Free} method.
  306. \Errors
  307. None.
  308. \SeeAlso
  309. \seepl{Free}{TObject.Free}, \seepl{Init}{TObject.Init}
  310. \end{procedure}
  311. \section{TStream}
  312. \label{se:TStream}
  313. The \var{TStream} object is the ancestor for all streaming objects, i.e.
  314. objects that have the capability to store and retrieve data.
  315. It defines a number of methods that are common to all objects that implement
  316. streaming, many of them are virtual, and are only implemented in the
  317. descendrnt types.
  318. Programs should not instantiate objects of type TStream directly, but
  319. instead instantiate a descendant type, such as \var{TDosStream},
  320. \var{TMemoryStream}.
  321. This is the full declaration of the \var{TStream} object:
  322. \begin{verbatim}
  323. TYPE
  324. TStream = OBJECT (TObject)
  325. Status : Integer; { Stream status }
  326. ErrorInfo : Integer; { Stream error info }
  327. StreamSize: LongInt; { Stream current size }
  328. Position : LongInt; { Current position }
  329. FUNCTION Get: PObject;
  330. FUNCTION StrRead: PChar;
  331. FUNCTION GetPos: Longint; Virtual;
  332. FUNCTION GetSize: Longint; Virtual;
  333. FUNCTION ReadStr: PString;
  334. PROCEDURE Open (OpenMode: Word); Virtual;
  335. PROCEDURE Close; Virtual;
  336. PROCEDURE Reset;
  337. PROCEDURE Flush; Virtual;
  338. PROCEDURE Truncate; Virtual;
  339. PROCEDURE Put (P: PObject);
  340. PROCEDURE StrWrite (P: PChar);
  341. PROCEDURE WriteStr (P: PString);
  342. PROCEDURE Seek (Pos: LongInt); Virtual;
  343. PROCEDURE Error (Code, Info: Integer); Virtual;
  344. PROCEDURE Read (Var Buf; Count: Sw_Word); Virtual;
  345. PROCEDURE Write (Var Buf; Count: Sw_Word); Virtual;
  346. PROCEDURE CopyFrom (Var S: TStream; Count: Longint);
  347. END;
  348. PStream = ^TStream;
  349. \end{verbatim}
  350. \begin{function}{TStream.Get}
  351. \Declaration
  352. Function TStream.Get : PObject;
  353. \Description
  354. \var{Get} reads an object definition from a stream, and returns
  355. a pointer to an instance of this object.
  356. \Errors
  357. On error, \var{TStream.Status} is set, and NIL is returned.
  358. \SeeAlso
  359. \seepl{Put}{TStream.Put}
  360. \end{function}
  361. \begin{function}{TStream.StrRead}
  362. \Declaration
  363. Function TStream.StrRead: PChar;
  364. \Description
  365. \var{StrRead} reads a string from the stream, allocates memory
  366. for it, and returns a pointer to a null-terminated copy of the string
  367. on the heap.
  368. \Errors
  369. On error, \var{Nil} is returned.
  370. \SeeAlso
  371. \seepl{StrWrite}{TStream.StrWrite}, \seefl{ReadStr}{TStream.ReadStr}
  372. \end{function}
  373. \begin{function}{TStream.GetPos}
  374. \Declaration
  375. TSTream.GetPos : Longint; Virtual;
  376. \Description
  377. If the stream's status is \var{stOk}, \var{GetPos} returns the current
  378. position in the stream. Otherwise it returns \var{-1}
  379. \Errors
  380. \var{-1} is returned if the status is an error condition.
  381. \SeeAlso
  382. \seepl{Seek}{TStream.Seek}, \seefl{GetSize}{TStream.GetSize}
  383. \end{function}
  384. \begin{function}{TStream.GetSize}
  385. \Declaration
  386. Function TStream.GetSize: Longint; Virtual;
  387. \Description
  388. If the stream's status is \var{stOk} then \var{GetSize} returns
  389. the size of the stream, otherwise it returns \var{-1}.
  390. \Errors
  391. \var{-1} is returned if the status is an error condition.
  392. \SeeAlso
  393. \seepl{Seek}{TStream.Seek}, \seefl{GetPos}{TStream.GetPos}
  394. \end{function}
  395. \begin{function}{TStream.ReadStr}
  396. \Declaration
  397. Function TStream.ReadStr: PString;
  398. \Description
  399. \var{ReadStr} reads a string from the stream, copies it to the heap
  400. and returns a pointer to this copy. The string is saved as a pascal
  401. string, and hence is NOT null terminated.
  402. \Errors
  403. On error (e.g. not enough memory), \var{Nil} is returned.
  404. \SeeAlso
  405. \seefl{StrRead}{TStream.StrRead}
  406. \end{function}
  407. \begin{procedure}{TStream.Open}
  408. \Declaration
  409. Procedure TStream.Open (OpenMode: Word); Virtual;
  410. \Description
  411. \var{Open} is an abstract method, that should be overridden by descendent
  412. objects. Since opening a stream depends on the stream's type this is not
  413. surprising.
  414. \Errors
  415. None.
  416. \SeeAlso
  417. \seepl{Close}{TStream.Close}, \seepl{Reset}{TStream.Reset}
  418. \end{procedure}
  419. \begin{procedure}{TStream.Close}
  420. \Declaration
  421. Procedure TStream.Close; Virtual;
  422. \Description
  423. \var{Close} is an abstract method, that should be overridden by descendent
  424. objects. Since Closing a stream depends on the stream's type this is not
  425. surprising.
  426. \Errors
  427. None.
  428. \SeeAlso
  429. \seepl{Open}{TStream.Open}, \seepl{Reset}{TStream.Reset}
  430. \end{procedure}
  431. \begin{procedure}{TStream.Reset}
  432. \Declaration
  433. PROCEDURE TStream.Reset;
  434. \Description
  435. \var{Reset} sets the stream's status to \var{0}, as well as the ErrorInfo
  436. \Errors
  437. None.
  438. \SeeAlso
  439. \seepl{Open}{TStream.Open}, \seepl{Close}{TStream.Close}
  440. \end{procedure}
  441. \begin{procedure}{TStream.Flush}
  442. \Declaration
  443. Procedure TStream.Flush; Virtual;
  444. \Description
  445. \var{Flush} is an abstract method that should be overridden by descendent
  446. objects. It serves to enable the programmer to tell streams that implement
  447. a buffer to clear the buffer.
  448. \Errors
  449. None.
  450. \SeeAlso
  451. \seepl{Truncate}{TStream.Truncate}
  452. \end{procedure}
  453. \begin{procedure}{TStream.Truncate}
  454. \Declaration
  455. Procedure TStream.Truncate; Virtual;
  456. \Description
  457. \var{Truncate} is an abstract procedure that should be overridden by
  458. descendent objects. It serves to enable the programmer to truncate the
  459. size of the stream to the current file position.
  460. \Errors
  461. None.
  462. \SeeAlso
  463. \seepl{Seek}{TStream.Seek}
  464. \end{procedure}
  465. \begin{procedure}{TStream.Put}
  466. \Declaration
  467. Procedure TStream.Put (P: PObject);
  468. \Description
  469. \var{Put} writes the object pointed to by \var{P}. \var{P} should be
  470. non-nil. The object type must have been registered with \seep{RegisterType}.
  471. After the object has been written, it can be read again with \seefl{Get}{TStream.Get}.
  472. \Errors
  473. No check is done whether P is \var{Nil} or not. Passing \var{Nil} will cause
  474. a run-time error 216 to be generated. If the object has not been registered,
  475. the status of the stream will be set to \var{stPutError}.
  476. \SeeAlso
  477. \seefl{Get}{TStream.Get}
  478. \end{procedure}
  479. \begin{procedure}{TStream.StrWrite}
  480. \Declaration
  481. Procedure TStream.StrWrite (P: PChar);
  482. \Description
  483. \var{StrWrite} writes the null-terminated string \var{P} to the stream.
  484. \var{P} can only be 65355 bytes long.
  485. \Errors
  486. None.
  487. \SeeAlso
  488. \seepl{WriteStr}{TStream.WriteStr}, \seefl{StrRead}{TStream.StrRead},
  489. \seefl{ReadStr}{TStream.ReadStr}
  490. \end{procedure}
  491. \begin{procedure}{TStream.WriteStr}
  492. \Declaration
  493. Procedure TStream.WriteStr (P: PString);
  494. \Description
  495. \var{StrWrite} writes the pascal string pointed to by \var{P} to the stream.
  496. \Errors
  497. None.
  498. \SeeAlso
  499. \seepl{StrWrite}{TStream.StrWrite}, \seefl{StrRead}{TStream.StrRead},
  500. \seefl{ReadStr}{TStream.ReadStr}
  501. \end{procedure}
  502. \begin{procedure}{TStream.Seek}
  503. \Declaration
  504. PROCEDURE TStream.Seek (Pos: LongInt); Virtual;
  505. \Description
  506. Seek sets the position to \var{Pos}. This position is counted
  507. from the beginning, and is zero based. (i.e. seeek(0) sets the position
  508. pointer on the first byte of the stream)
  509. \Errors
  510. If \var{Pos} is larger than the stream size, \var{Status} is set to
  511. \var{StSeekError}.
  512. \SeeAlso
  513. \seefl{GetPos}{TStream.GetPos}, \seefl{GetSize}{TStream.GetSize}
  514. \end{procedure}
  515. \begin{procedure}{TStream.Error}
  516. \Declaration
  517. Procedure TStream.Error (Code, Info: Integer); Virtual;
  518. \Description
  519. \var{Error} sets the stream's status to \var{Code} and \var{ErrorInfo}
  520. to \var{Info}. If the \var{StreamError} procedural variable is set,
  521. \var{Error} executes it, passing \var{Self} as an argument.
  522. This method should not be called directly from a program. It is intended to
  523. be used in descendent objects.
  524. \Errors
  525. None.
  526. \SeeAlso
  527. \end{procedure}
  528. \begin{procedure}{TStream.Read}
  529. \Declaration
  530. Procedure TStream.Read (Var Buf; Count: Sw\_Word); Virtual;
  531. \Description
  532. \var{Read} is an abstract method that should be overridden by descendent
  533. objects.
  534. \var{Read} reads \var{Count} bytes from the stream into \var{Buf}.
  535. It updates the position pointer, increasing it's value with \var{Count}.
  536. \var{Buf} must be large enough to contain \var{Count} bytes.
  537. \Errors
  538. No checking is done to see if \var{Buf} is large enough to contain
  539. \var{Count} bytes.
  540. \SeeAlso
  541. \seepl{Write}{TStream.Write}, \seefl{ReadStr}{TStream.ReadStr},
  542. \seefl{StrRead}{TStream.StrRead}
  543. \end{procedure}
  544. \begin{procedure}{TStream.Write}
  545. \Declaration
  546. Procedure TStream.Write (Var Buf; Count: Sw\_Word); Virtual;
  547. \Description
  548. \var{Write} is an abstract method that should be overridden by descendent
  549. objects.
  550. \var{Write} writes \var{Count} bytes to the stream from \var{Buf}.
  551. It updates the position pointer, increasing it's value with \var{Count}.
  552. \Errors
  553. No checking is done to see if \var{Buf} actually contains \var{Count} bytes.
  554. \SeeAlso
  555. \seepl{Read}{TStream.Read}, \seepl{WriteStr}{TStream.WriteStr},
  556. \seepl{StrWrite}{TStream.StrWrite}
  557. \end{procedure}
  558. \begin{procedure}{TStream.CopyFrom}
  559. \Declaration
  560. Procedure TStream.CopyFrom (Var S: TStream; Count: Longint);
  561. \Description
  562. \var{CopyFrom} reads Count bytes from stream \var{S} and stores them
  563. in the current stream. It uses the \seepl{Read}{TStream.Read} method
  564. to read the data, and the \seepl{Write}{TStream.Write} method to
  565. write in the current stream.
  566. \Errors
  567. None.
  568. \SeeAlso
  569. \seepl{Read}{TStream.Read}, \seepl{Write}{TStream.Write}
  570. \end{procedure}
  571. \section{TDosStream}
  572. \label{se:TDosStream}
  573. \var{TDosStream} is a steam that stores it's contents in a file.
  574. it overrides a couple of methods of \var{TSteam} for this.
  575. In addition to the fields inherited from \var{TStream} (see \sees{TStream}),
  576. there are some extra fields, that describe the file. (mainly the name and
  577. the OS file handle)
  578. No buffering in memory is done when using \var{TDosStream}.
  579. All data are written directly to the file. For a stream that buffers
  580. in memory, see \sees{TBufStream}.
  581. Here is the full declaration of the \var{TDosStream} object:
  582. \begin{verbatim}
  583. TYPE
  584. TDosStream = OBJECT (TStream)
  585. Handle: THandle; { DOS file handle }
  586. FName : AsciiZ; { AsciiZ filename }
  587. CONSTRUCTOR Init (FileName: FNameStr; Mode: Word);
  588. DESTRUCTOR Done; Virtual;
  589. PROCEDURE Close; Virtual;
  590. PROCEDURE Truncate; Virtual;
  591. PROCEDURE Seek (Pos: LongInt); Virtual;
  592. PROCEDURE Open (OpenMode: Word); Virtual;
  593. PROCEDURE Read (Var Buf; Count: Sw_Word); Virtual;
  594. PROCEDURE Write (Var Buf; Count: Sw_Word); Virtual;
  595. END;
  596. PDosStream = ^TDosStream;
  597. \end{verbatim}
  598. \begin{procedure}{TDosStream.Init}
  599. \Declaration
  600. Constructor Init (FileName: FNameStr; Mode: Word);
  601. \Description
  602. \var{Init} instantiates an instance of \var{TDosStream}. The name of the
  603. file that contains (or will contain) the data of the stream is given in
  604. \var{FileName}. The \var{Mode} parameter determines whether a new file
  605. should be created and what access rights you have on the file.
  606. It can be one of the following constants:
  607. \begin{description}
  608. \item[stCreate] Creates a new file.
  609. \item[stOpenRead] Read access only.
  610. \item[stOpenWrite] Write access only.
  611. \item[stOpen] Read and write access.
  612. \end{description}
  613. \Errors
  614. On error, \var{Status} is set to \var{stInitError}, and \var{ErrorInfo}
  615. is set to the \dos error code.
  616. \SeeAlso
  617. \seepl{Done}{TDosStream.Done}
  618. \end{procedure}
  619. \begin{procedure}{TDosStream.Done}
  620. \Declaration
  621. Destructor TDosStream.Done; Virtual;
  622. \Description
  623. \var{Done} closes the file if it was open and cleans up the
  624. instance of \var{TDosStream}.
  625. \Errors
  626. None.
  627. \SeeAlso
  628. \seepl{Init}{TDosStream.Init},
  629. \seepl{Close}{TDosStream.Close}
  630. \end{procedure}
  631. \begin{procedure}{TDosStream.Close}
  632. \Declaration
  633. Pocedure TDosStream.Close; Virtual;
  634. \Description
  635. \var{Close} closes the file if it was open, and sets \var{Handle} to -1.
  636. Contrary to \seepl{Done}{TDosStream.Done} it does not clean up the instance
  637. of \var{TDosStream}
  638. \Errors
  639. None.
  640. \SeeAlso
  641. \seep{TStream.Close}, \seepl{Init}{TDosStream.Init},
  642. \seepl{Done}{TDosStream.Done}
  643. \end{procedure}
  644. \begin{procedure}{TDosStream.Truncate}
  645. \Declaration
  646. Procedure TDosStream.Truncate; Virtual;
  647. \Description
  648. If the status of the stream is \var{stOK}, then \var{Truncate} tries to
  649. truncate the stream size to the current file position.
  650. \Errors
  651. If an error occurs, the stream's status is set to \var{stError} and
  652. \var{ErrorInfo} is set to the OS error code.
  653. \SeeAlso
  654. \seep{TStream.Truncate}, \seefl{GetSize}{TStream.GetSize}
  655. \end{procedure}
  656. \begin{procedure}{TDosStream.Seek}
  657. \Declaration
  658. Procedure TDosStream.Seek (Pos: LongInt); Virtual;
  659. \Description
  660. If the stream's status is \var{stOK}, then \var{Seek} sets the
  661. file position to \var{Pos}. \var{Pos} is a zero-based offset, counted from
  662. the beginning of the file.
  663. \Errors
  664. In case an error occurs, the stream's status is set to \var{stSeekError},
  665. and the OS error code is stored in \var{ErrorInfo}.
  666. \SeeAlso
  667. \seep{TStream.Seek}, \seefl{GetPos}{TStream.GetPos}
  668. \end{procedure}
  669. \begin{procedure}{TDosStream.Open}
  670. \Declaration
  671. Procedure TDosStream.Open (OpenMode: Word); Virtual;
  672. \Description
  673. If the stream's status is \var{stOK}, and the stream is closed then
  674. \var{Open} re-opens the file stream with mode \var{OpenMode}.
  675. This call can be used after a \seepl{Close}{TDosStream.Close} call.
  676. \Errors
  677. If an error occurs when re-opening the file, then \var{Status} is set
  678. to \var{stOpenError}, and the OS error code is stored in \var{ErrorInfo}
  679. \SeeAlso
  680. \seep{TStream.Open}, \seepl{Close}{TDosStream.Close}
  681. \end{procedure}
  682. \begin{procedure}{TDosStream.Read}
  683. \Declaration
  684. Procedure TDosStream.Read (Var Buf; Count: Sw\_Word); Virtual;
  685. \Description
  686. If the Stream is open and the stream status is \var{stOK} then
  687. \var{Read} will read \var{Count} bytes from the stream and place them
  688. in \var{Buf}.
  689. \Errors
  690. In case of an error, \var{Status} is set to \var{StReadError}, and
  691. \var{ErrorInfo} gets the OS specific error, or 0 when an attempt was
  692. made to read beyond the end of the stream.
  693. \SeeAlso
  694. \seep{TStream.Read}, \seepl{Write}{TDosStream.Write}
  695. \end{procedure}
  696. \begin{procedure}{TDosStream.Write}
  697. \Declaration
  698. Procedure TDosStream.Write (Var Buf; Count: Sw\_Word); Virtual;
  699. \Description
  700. If the Stream is open and the stream status is \var{stOK} then
  701. \var{Write} will write \var{Count} bytes from \var{Buf} and place them
  702. in the stream.
  703. \Errors
  704. In case of an error, \var{Status} is set to \var{StWriteError}, and
  705. \var{ErrorInfo} gets the OS specific error.
  706. \SeeAlso
  707. \seep{TStream.Write}, \seepl{Read}{TDosStream.Read}
  708. \end{procedure}
  709. \section{TBufStream}
  710. \label{se:TBufStream}
  711. \var{Bufstream} implements a buffered file stream. That is, all data written
  712. to the stream is written to memory first. Only when the buffer is full, or
  713. on explicit request, the data is written to disk.
  714. Also, when reading from the stream, first the buffer is checked if there is
  715. any unread data in it. If so, this is read first. If not the buffer is
  716. filled again, and then the data is read from the buffer.
  717. The size of the buffer is fixed and is set when constructing the file.
  718. This is useful if you need heavy throughput for your stream, because it
  719. speeds up operations.
  720. \begin{verbatim}
  721. TYPE
  722. TBufStream = OBJECT (TDosStream)
  723. LastMode: Byte; { Last buffer mode }
  724. BufSize : Sw_Word; { Buffer size }
  725. BufPtr : Sw_Word; { Buffer start }
  726. BufEnd : Sw_Word; { Buffer end }
  727. Buffer : PByteArray; { Buffer allocated }
  728. CONSTRUCTOR Init (FileName: FNameStr; Mode, Size: Word);
  729. DESTRUCTOR Done; Virtual;
  730. PROCEDURE Close; Virtual;
  731. PROCEDURE Flush; Virtual;
  732. PROCEDURE Truncate; Virtual;
  733. PROCEDURE Seek (Pos: LongInt); Virtual;
  734. PROCEDURE Open (OpenMode: Word); Virtual;
  735. PROCEDURE Read (Var Buf; Count: Sw_Word); Virtual;
  736. PROCEDURE Write (Var Buf; Count: Sw_Word); Virtual;
  737. END;
  738. PBufStream = ^TBufStream;
  739. \end{verbatim}
  740. \begin{procedure}{TBufStream.Init}
  741. \Declaration
  742. Constructor Init (FileName: FNameStr; Mode,Size: Word);
  743. \Description
  744. \var{Init} instantiates an instance of \var{TBufStream}. The name of the
  745. file that contains (or will contain) the data of the stream is given in
  746. \var{FileName}. The \var{Mode} parameter determines whether a new file
  747. should be created and what access rights you have on the file.
  748. It can be one of the following constants:
  749. \begin{description}
  750. \item[stCreate] Creates a new file.
  751. \item[stOpenRead] Read access only.
  752. \item[stOpenWrite] Write access only.
  753. \item[stOpen] Read and write access.
  754. \end{description}
  755. The \var{Size} parameter determines the size of the buffer that will be
  756. created. It should be different from zero.
  757. \Errors
  758. On error, \var{Status} is set to \var{stInitError}, and \var{ErrorInfo}
  759. is set to the \dos error code.
  760. \SeeAlso
  761. \seep{TDosStream.Init}, \seepl{Done}{TBufStream.Done}
  762. \end{procedure}
  763. \begin{procedure}{TBufStream.Done}
  764. \Declaration
  765. Destructor TBufStream.Done; Virtual;
  766. \Description
  767. \var{Done} flushes and closes the file if it was open and cleans up the
  768. instance of \var{TBufStream}.
  769. \Errors
  770. None.
  771. \SeeAlso
  772. \seep{TDosStream.Done}, \seepl{Init}{TBufStream.Init},
  773. \seepl{Close}{TBufStream.Close}
  774. \end{procedure}
  775. \begin{procedure}{TBufStream.Close}
  776. \Declaration
  777. Pocedure TBufStream.Close; Virtual;
  778. \Description
  779. \var{Close} flushes and closes the file if it was open, and sets \var{Handle} to -1.
  780. Contrary to \seepl{Done}{TBufStream.Done} it does not clean up the instance
  781. of \var{TBufStream}
  782. \Errors
  783. None.
  784. \SeeAlso
  785. \seep{TStream.Close}, \seepl{Init}{TBufStream.Init},
  786. \seepl{Done}{TBufStream.Done}
  787. \end{procedure}
  788. \begin{procedure}{TBufStream.Flush}
  789. \Declaration
  790. Pocedure TBufStream.Flush; Virtual;
  791. \Description
  792. When the stream is in write mode, the contents of the buffer are written to
  793. disk, and the buffer position is set to zero.
  794. When the stream is in read mode, the buffer position is set to zero.
  795. \Errors
  796. Write errors may occur if the file was in write mode.
  797. see \seepl{Write}{TBufStream.Write} for more info on the errors.
  798. \SeeAlso
  799. \seep{TStream.Close}, \seepl{Init}{TBufStream.Init},
  800. \seepl{Done}{TBufStream.Done}
  801. \end{procedure}
  802. \begin{procedure}{TBufStream.Truncate}
  803. \Declaration
  804. Procedure TBufStream.Truncate; Virtual;
  805. \Description
  806. If the status of the stream is \var{stOK}, then \var{Truncate} tries to
  807. flush the buffer, and then truncates the stream size to the current
  808. file position.
  809. \Errors
  810. Errors can be those of \seepl{Flush}{TBufStream.Flush} or
  811. \seep{TDosStream.Truncate}.
  812. \SeeAlso
  813. \seep{TStream.Truncate}, \seep{TDosStream.Truncate},
  814. \seefl{GetSize}{TStream.GetSize}
  815. \end{procedure}
  816. \begin{procedure}{TBufStream.Seek}
  817. \Declaration
  818. Procedure TBufStream.Seek (Pos: LongInt); Virtual;
  819. \Description
  820. If the stream's status is \var{stOK}, then \var{Seek} sets the
  821. file position to \var{Pos}. \var{Pos} is a zero-based offset, counted from
  822. the beginning of the file.
  823. \Errors
  824. In case an error occurs, the stream's status is set to \var{stSeekError},
  825. and the OS error code is stored in \var{ErrorInfo}.
  826. \SeeAlso
  827. \seep{TStream.Seek}, \seefl{GetPos}{TStream.GetPos}
  828. \end{procedure}
  829. \begin{procedure}{TBufStream.Open}
  830. \Declaration
  831. Procedure TBufStream.Open (OpenMode: Word); Virtual;
  832. \Description
  833. If the stream's status is \var{stOK}, and the stream is closed then
  834. \var{Open} re-opens the file stream with mode \var{OpenMode}.
  835. This call can be used after a \seepl{Close}{TBufStream.Close} call.
  836. \Errors
  837. If an error occurs when re-opening the file, then \var{Status} is set
  838. to \var{stOpenError}, and the OS error code is stored in \var{ErrorInfo}
  839. \SeeAlso
  840. \seep{TStream.Open}, \seepl{Close}{TBufStream.Close}
  841. \end{procedure}
  842. \begin{procedure}{TBufStream.Read}
  843. \Declaration
  844. Procedure TBufStream.Read (Var Buf; Count: Sw\_Word); Virtual;
  845. \Description
  846. If the Stream is open and the stream status is \var{stOK} then
  847. \var{Read} will read \var{Count} bytes from the stream and place them
  848. in \var{Buf}.
  849. \var{Read} will first try to read the data from the stream's internal
  850. buffer. If insufficient data is available, the buffer will be filled before
  851. contiunuing to read. This process is repeated until all needed data
  852. has been read.
  853. \Errors
  854. In case of an error, \var{Status} is set to \var{StReadError}, and
  855. \var{ErrorInfo} gets the OS specific error, or 0 when an attempt was
  856. made to read beyond the end of the stream.
  857. \SeeAlso
  858. \seep{TStream.Read}, \seepl{Write}{TBufStream.Write}
  859. \end{procedure}
  860. \begin{procedure}{TBufStream.Write}
  861. \Declaration
  862. Procedure TBufStream.Write (Var Buf; Count: Sw\_Word); Virtual;
  863. \Description
  864. If the Stream is open and the stream status is \var{stOK} then
  865. \var{Write} will write \var{Count} bytes from \var{Buf} and place them
  866. in the stream.
  867. \var{Write} will first try to write the data to the stream's internal
  868. buffer. When the internal buffer is full, then the contents will be written
  869. to disk. This process is repeated until all data has been written.
  870. \Errors
  871. In case of an error, \var{Status} is set to \var{StWriteError}, and
  872. \var{ErrorInfo} gets the OS specific error.
  873. \SeeAlso
  874. \seep{TStream.Write}, \seepl{Read}{TBufStream.Read}
  875. \end{procedure}
  876. \section{TMemoryStream}
  877. \section{se:TMemoryStream}
  878. \begin{verbatim}
  879. TYPE
  880. TMemoryStream = OBJECT (TStream)
  881. BlkCount: Sw_Word; { Number of segments }
  882. BlkSize : Word; { Memory block size }
  883. MemSize : LongInt; { Memory alloc size }
  884. BlkList : PPointerArray; { Memory block list }
  885. CONSTRUCTOR Init (ALimit: Longint; ABlockSize: Word);
  886. DESTRUCTOR Done; Virtual;
  887. PROCEDURE Truncate; Virtual;
  888. PROCEDURE Read (Var Buf; Count: Sw_Word); Virtual;
  889. PROCEDURE Write (Var Buf; Count: Sw_Word); Virtual;
  890. PRIVATE
  891. FUNCTION ChangeListSize (ALimit: Sw_Word): Boolean;
  892. END;
  893. PMemoryStream = ^TMemoryStream;
  894. \end{verbatim}
  895. \section{TCollection}
  896. \label{se:TCollection}
  897. \begin{verbatim}
  898. TYPE
  899. TItemList = Array [0..MaxCollectionSize - 1] Of Pointer;
  900. PItemList = ^TItemList;
  901. TCollection = OBJECT (TObject)
  902. Items: PItemList; { Item list pointer }
  903. Count: Sw_Integer; { Item count }
  904. Limit: Sw_Integer; { Item limit count }
  905. Delta: Sw_Integer; { Inc delta size }
  906. CONSTRUCTOR Init (ALimit, ADelta: Sw_Integer);
  907. CONSTRUCTOR Load (Var S: TStream);
  908. DESTRUCTOR Done; Virtual;
  909. FUNCTION At (Index: Sw_Integer): Pointer;
  910. FUNCTION IndexOf (Item: Pointer): Sw_Integer; Virtual;
  911. FUNCTION GetItem (Var S: TStream): Pointer; Virtual;
  912. FUNCTION LastThat (Test: Pointer): Pointer;
  913. FUNCTION FirstThat (Test: Pointer): Pointer;
  914. PROCEDURE Pack;
  915. PROCEDURE FreeAll;
  916. PROCEDURE DeleteAll;
  917. PROCEDURE Free (Item: Pointer);
  918. PROCEDURE Insert (Item: Pointer); Virtual;
  919. PROCEDURE Delete (Item: Pointer);
  920. PROCEDURE AtFree (Index: Sw_Integer);
  921. PROCEDURE FreeItem (Item: Pointer); Virtual;
  922. PROCEDURE AtDelete (Index: Sw_Integer);
  923. PROCEDURE ForEach (Action: Pointer);
  924. PROCEDURE SetLimit (ALimit: Sw_Integer); Virtual;
  925. PROCEDURE Error (Code, Info: Integer); Virtual;
  926. PROCEDURE AtPut (Index: Sw_Integer; Item: Pointer);
  927. PROCEDURE AtInsert (Index: Sw_Integer; Item: Pointer);
  928. PROCEDURE Store (Var S: TStream);
  929. PROCEDURE PutItem (Var S: TStream; Item: Pointer); Virtual;
  930. END;
  931. PCollection = ^TCollection;
  932. \end{verbatim}
  933. \section{TSortedCollection}
  934. \label{se:TSortedCollection}
  935. \begin{verbatim}
  936. TYPE
  937. TSortedCollection = OBJECT (TCollection)
  938. Duplicates: Boolean; { Duplicates flag }
  939. CONSTRUCTOR Init (ALimit, ADelta: Sw_Integer);
  940. CONSTRUCTOR Load (Var S: TStream);
  941. FUNCTION KeyOf (Item: Pointer): Pointer; Virtual;
  942. FUNCTION IndexOf (Item: Pointer): Sw_Integer; Virtual;
  943. FUNCTION Compare (Key1, Key2: Pointer): Sw_Integer; Virtual;
  944. FUNCTION Search (Key: Pointer; Var Index: Sw_Integer): Boolean;Virtual;
  945. PROCEDURE Insert (Item: Pointer); Virtual;
  946. PROCEDURE Store (Var S: TStream);
  947. END;
  948. PSortedCollection = ^TSortedCollection;
  949. \end{verbatim}
  950. \section{TStringCollection}
  951. \label{se:TStringCollection}
  952. \begin{verbatim}
  953. TYPE
  954. TStringCollection = OBJECT (TSortedCollection)
  955. FUNCTION GetItem (Var S: TStream): Pointer; Virtual;
  956. FUNCTION Compare (Key1, Key2: Pointer): Sw_Integer; Virtual;
  957. PROCEDURE FreeItem (Item: Pointer); Virtual;
  958. PROCEDURE PutItem (Var S: TStream; Item: Pointer); Virtual;
  959. END;
  960. PStringCollection = ^TStringCollection;
  961. \end{verbatim}
  962. \section{TStrCollection}
  963. \label{se:TStrCollection}
  964. \begin{verbatim}
  965. TYPE
  966. TStrCollection = OBJECT (TSortedCollection)
  967. FUNCTION Compare (Key1, Key2: Pointer): Sw_Integer; Virtual;
  968. FUNCTION GetItem (Var S: TStream): Pointer; Virtual;
  969. PROCEDURE FreeItem (Item: Pointer); Virtual;
  970. PROCEDURE PutItem (Var S: TStream; Item: Pointer); Virtual;
  971. END;
  972. PStrCollection = ^TStrCollection;
  973. \end{verbatim}
  974. \section{TUnSortedStrCollection}
  975. \label{se:TUnSortedStrCollection}
  976. \begin{verbatim}
  977. TYPE
  978. TUnSortedStrCollection = OBJECT (TStringCollection)
  979. PROCEDURE Insert (Item: Pointer); Virtual;
  980. END;
  981. PUnSortedStrCollection = ^TUnSortedStrCollection;
  982. \end{verbatim}
  983. \section{TResourceCollection}
  984. \label{se:TResourceCollection}
  985. \begin{verbatim}
  986. TYPE
  987. TResourceCollection = OBJECT (TStringCollection)
  988. FUNCTION KeyOf (Item: Pointer): Pointer; Virtual;
  989. FUNCTION GetItem (Var S: TStream): Pointer; Virtual;
  990. PROCEDURE FreeItem (Item: Pointer); Virtual;
  991. PROCEDURE PutItem (Var S: TStream; Item: Pointer); Virtual;
  992. END;
  993. PResourceCollection = ^TResourceCollection;
  994. \end{verbatim}
  995. \section{TResourceFile}
  996. \label{se:TResourceFile}
  997. \begin{verbatim}
  998. TYPE
  999. TResourceFile = OBJECT (TObject)
  1000. Stream : PStream; { File as a stream }
  1001. Modified: Boolean; { Modified flag }
  1002. CONSTRUCTOR Init (AStream: PStream);
  1003. DESTRUCTOR Done; Virtual;
  1004. FUNCTION Count: Sw_Integer;
  1005. FUNCTION KeyAt (I: Sw_Integer): String;
  1006. FUNCTION Get (Key: String): PObject;
  1007. FUNCTION SwitchTo (AStream: PStream; Pack: Boolean): PStream;
  1008. PROCEDURE Flush;
  1009. PROCEDURE Delete (Key: String);
  1010. PROCEDURE Put (Item: PObject; Key: String);
  1011. END;
  1012. PResourceFile = ^TResourceFile;
  1013. \end{verbatim}
  1014. \section{TStringList}
  1015. \label{se:TStringList}
  1016. \begin{verbatim}
  1017. TYPE
  1018. TStrIndexRec = Packed RECORD
  1019. Key, Count, Offset: Word;
  1020. END;
  1021. TStrIndex = Array [0..9999] Of TStrIndexRec;
  1022. PStrIndex = ^TStrIndex;
  1023. TStringList = OBJECT (TObject)
  1024. CONSTRUCTOR Load (Var S: TStream);
  1025. DESTRUCTOR Done; Virtual;
  1026. FUNCTION Get (Key: Sw_Word): String;
  1027. END;
  1028. PStringList = ^TStringList;
  1029. \end{verbatim}
  1030. \section{TStrListMaker}
  1031. \label{se:TStrListMaker}
  1032. \begin{verbatim}
  1033. TYPE
  1034. TStrListMaker = OBJECT (TObject)
  1035. CONSTRUCTOR Init (AStrSize, AIndexSize: Sw_Word);
  1036. DESTRUCTOR Done; Virtual;
  1037. PROCEDURE Put (Key: Sw_Word; S: String);
  1038. PROCEDURE Store (Var S: TStream);
  1039. END;
  1040. PStrListMaker = ^TStrListMaker;
  1041. \end{verbatim}
  1042. \begin{verbatim}
  1043. FUNCTION NewStr (Const S: String): PString;
  1044. PROCEDURE DisposeStr (P: PString);
  1045. PROCEDURE Abstract;
  1046. PROCEDURE RegisterObjects;
  1047. \end{verbatim}
  1048. \begin{procedure}{RegisterType}
  1049. \Declaration
  1050. PROCEDURE RegisterType (Var S: TStreamRec);
  1051. \end{procedure}
  1052. \begin{verbatim}
  1053. FUNCTION LongMul (X, Y: Integer): LongInt;
  1054. FUNCTION LongDiv (X: Longint; Y: Integer): Integer;
  1055. CONST
  1056. StreamError: Pointer = Nil; { Stream error ptr }
  1057. DosStreamError: Word = $0; { Dos stream error }
  1058. CONST
  1059. RCollection: TStreamRec = (
  1060. ObjType: 50;
  1061. VmtLink: Ofs(TypeOf(TCollection)^);
  1062. Load: @TCollection.Load;
  1063. Store: @TCollection.Store);
  1064. RStringCollection: TStreamRec = (
  1065. ObjType: 51;
  1066. VmtLink: Ofs(TypeOf(TStringCollection)^);
  1067. Load: @TStringCollection.Load;
  1068. Store: @TStringCollection.Store);
  1069. RStrCollection: TStreamRec = (
  1070. ObjType: 69;
  1071. VmtLink: Ofs(TypeOf(TStrCollection)^);
  1072. Load: @TStrCollection.Load;
  1073. Store: @TStrCollection.Store);
  1074. RStringList: TStreamRec = (
  1075. ObjType: 52;
  1076. VmtLink: Ofs(TypeOf(TStringList)^);
  1077. Load: @TStringList.Load;
  1078. Store: Nil);
  1079. RStrListMaker: TStreamRec = (
  1080. ObjType: 52;
  1081. VmtLink: Ofs(TypeOf(TStrListMaker)^);
  1082. Load: Nil;
  1083. Store: @TStrListMaker.Store);
  1084. \end{verbatim}