objects.pp 135 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945
  1. {
  2. This file is part of the Free Pascal run time library.
  3. Copyright (c) 1999-2000 by the Free Pascal development team.
  4. Objects.pas clone for Free Pascal
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {************[ SOURCE FILE OF FREE VISION ]****************}
  12. { }
  13. { System independent clone of objects.pas }
  14. { }
  15. { Interface Copyright (c) 1992 Borland International }
  16. { }
  17. { Parts Copyright (c) 1999-2000 by Florian Klaempfl }
  18. { [email protected] }
  19. { }
  20. { Parts Copyright (c) 1999-2000 by Frank ZAGO }
  21. { [email protected] }
  22. { }
  23. { Parts Copyright (c) 1999-2000 by MH Spiegel }
  24. { }
  25. { Parts Copyright (c) 1996, 1999-2000 by Leon de Boer }
  26. { [email protected] }
  27. { }
  28. { Free Vision project coordinator Balazs Scheidler }
  29. { [email protected] }
  30. { }
  31. UNIT Objects;
  32. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  33. INTERFACE
  34. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  35. {==== Select assembler ==============================================}
  36. {$IFDEF CPU86}
  37. {$ASMMODE ATT}
  38. {$ENDIF}
  39. {==== Compiler directives ===========================================}
  40. {$H-} { No ansistrings }
  41. {$X+} { Extended syntax is ok }
  42. {$R-} { Disable range checking }
  43. {$ifndef Unix}
  44. {$S-} { Disable Stack Checking }
  45. {$endif}
  46. {$I-} { Disable IO Checking }
  47. {$Q-} { Disable Overflow Checking }
  48. {$V-} { Turn off strict VAR strings }
  49. {$INLINE ON} {Turn on inlining.}
  50. {====================================================================}
  51. {$ifdef win32}
  52. uses
  53. Windows;
  54. {$endif}
  55. {***************************************************************************}
  56. { PUBLIC CONSTANTS }
  57. {***************************************************************************}
  58. {---------------------------------------------------------------------------}
  59. { STREAM ERROR STATE MASKS }
  60. {---------------------------------------------------------------------------}
  61. CONST
  62. stOk = 0; { No stream error }
  63. stError = -1; { Access error }
  64. stInitError = -2; { Initialize error }
  65. stReadError = -3; { Stream read error }
  66. stWriteError = -4; { Stream write error }
  67. stGetError = -5; { Get object error }
  68. stPutError = -6; { Put object error }
  69. stSeekError = -7; { Seek error in stream }
  70. stOpenError = -8; { Error opening stream }
  71. {---------------------------------------------------------------------------}
  72. { STREAM ACCESS MODE CONSTANTS }
  73. {---------------------------------------------------------------------------}
  74. CONST
  75. stCreate = $3C00; { Create new file }
  76. stOpenRead = $3D00; { Read access only }
  77. stOpenWrite = $3D01; { Write access only }
  78. stOpen = $3D02; { Read/write access }
  79. {---------------------------------------------------------------------------}
  80. { TCollection ERROR CODES }
  81. {---------------------------------------------------------------------------}
  82. CONST
  83. coIndexError = -1; { Index out of range }
  84. coOverflow = -2; { Overflow }
  85. {---------------------------------------------------------------------------}
  86. { VMT HEADER CONSTANT - HOPEFULLY WE CAN DROP THIS LATER }
  87. {---------------------------------------------------------------------------}
  88. CONST
  89. vmtHeaderSize = 8; { VMT header size }
  90. CONST
  91. {---------------------------------------------------------------------------}
  92. { MAXIUM DATA SIZES }
  93. {---------------------------------------------------------------------------}
  94. {$IFDEF FPC}
  95. MaxBytes = 128*1024*128; { Maximum data size }
  96. {$ELSE}
  97. MaxBytes = 16384;
  98. {$ENDIF}
  99. MaxWords = MaxBytes DIV SizeOf(Word); { Max word data size }
  100. MaxPtrs = MaxBytes DIV SizeOf(Pointer); { Max ptr data size }
  101. MaxCollectionSize = MaxBytes DIV SizeOf(Pointer); { Max collection size }
  102. MaxTPCompatibleCollectionSize = 65520 div 4;
  103. {***************************************************************************}
  104. { PUBLIC TYPE DEFINITIONS }
  105. {***************************************************************************}
  106. {---------------------------------------------------------------------------}
  107. { CHARACTER SET }
  108. {---------------------------------------------------------------------------}
  109. TYPE
  110. TCharSet = SET Of Char; { Character set }
  111. PCharSet = ^TCharSet; { Character set ptr }
  112. {---------------------------------------------------------------------------}
  113. { GENERAL ARRAYS }
  114. {---------------------------------------------------------------------------}
  115. TYPE
  116. TByteArray = ARRAY [0..MaxBytes-1] Of Byte; { Byte array }
  117. PByteArray = ^TByteArray; { Byte array pointer }
  118. TWordArray = ARRAY [0..MaxWords-1] Of Word; { Word array }
  119. PWordArray = ^TWordArray; { Word array pointer }
  120. TPointerArray = Array [0..MaxPtrs-1] Of Pointer; { Pointer array }
  121. PPointerArray = ^TPointerArray; { Pointer array ptr }
  122. {---------------------------------------------------------------------------}
  123. { POINTER TO STRING }
  124. {---------------------------------------------------------------------------}
  125. TYPE
  126. PString = PShortString; { String pointer }
  127. {---------------------------------------------------------------------------}
  128. { OS dependent File type / consts }
  129. {---------------------------------------------------------------------------}
  130. type
  131. FNameStr = String;
  132. const
  133. MaxReadBytes = $7fffffff;
  134. var
  135. invalidhandle : THandle;
  136. {---------------------------------------------------------------------------}
  137. { DOS ASCIIZ FILENAME }
  138. {---------------------------------------------------------------------------}
  139. TYPE
  140. AsciiZ = Array [0..255] Of Char; { Filename array }
  141. {---------------------------------------------------------------------------}
  142. { BIT SWITCHED TYPE CONSTANTS }
  143. {---------------------------------------------------------------------------}
  144. TYPE
  145. Sw_Word = Cardinal; { Long Word now }
  146. Sw_Integer = LongInt; { Long integer now }
  147. {***************************************************************************}
  148. { PUBLIC RECORD DEFINITIONS }
  149. {***************************************************************************}
  150. {---------------------------------------------------------------------------}
  151. { TYPE CONVERSION RECORDS }
  152. {---------------------------------------------------------------------------}
  153. TYPE
  154. WordRec = packed RECORD
  155. {$ifdef ENDIAN_LITTLE}
  156. Lo, Hi: Byte; { Word to bytes }
  157. {$else}
  158. Hi,Lo: Byte;
  159. {$endif}
  160. END;
  161. LongRec = packed RECORD
  162. {$ifdef ENDIAN_LITTLE}
  163. Lo, Hi: Word; { LongInt to words }
  164. {$else}
  165. Hi,Lo: Word; { LongInt to words }
  166. {$endif}
  167. END;
  168. PtrRec = packed RECORD
  169. Ofs, Seg: Word; { Pointer to words }
  170. END;
  171. {---------------------------------------------------------------------------}
  172. { TStreamRec RECORD - STREAM OBJECT RECORD }
  173. {---------------------------------------------------------------------------}
  174. TYPE
  175. PStreamRec = ^TStreamRec; { Stream record ptr }
  176. TStreamRec = Packed RECORD
  177. ObjType: Sw_Word; { Object type id }
  178. VmtLink: pointer; { VMT link }
  179. Load : Pointer; { Object load code }
  180. Store: Pointer; { Object store code }
  181. Next : PStreamRec; { Next stream record }
  182. END;
  183. {***************************************************************************}
  184. { PUBLIC OBJECT DEFINITIONS }
  185. {***************************************************************************}
  186. {---------------------------------------------------------------------------}
  187. { TPoint OBJECT - POINT OBJECT }
  188. {---------------------------------------------------------------------------}
  189. TYPE
  190. PPoint = ^TPoint;
  191. TPoint = OBJECT
  192. X, Y: Sw_Integer;
  193. END;
  194. {---------------------------------------------------------------------------}
  195. { TRect OBJECT - RECTANGLE OBJECT }
  196. {---------------------------------------------------------------------------}
  197. PRect = ^TRect;
  198. TRect = OBJECT
  199. A, B: TPoint; { Corner points }
  200. FUNCTION Empty: Boolean;
  201. FUNCTION Equals (R: TRect): Boolean;
  202. FUNCTION Contains (P: TPoint): Boolean;
  203. PROCEDURE Copy (R: TRect);
  204. PROCEDURE Union (R: TRect);
  205. PROCEDURE Intersect (R: TRect);
  206. PROCEDURE Move (ADX, ADY: Sw_Integer);
  207. PROCEDURE Grow (ADX, ADY: Sw_Integer);
  208. PROCEDURE Assign (XA, YA, XB, YB: Sw_Integer);
  209. END;
  210. {---------------------------------------------------------------------------}
  211. { TObject OBJECT - BASE ANCESTOR OBJECT }
  212. {---------------------------------------------------------------------------}
  213. TYPE
  214. TObject = OBJECT
  215. CONSTRUCTOR Init;
  216. PROCEDURE Free;
  217. FUNCTION Is_Object(P:Pointer):Boolean;
  218. DESTRUCTOR Done; Virtual;
  219. END;
  220. PObject = ^TObject;
  221. { ******************************* REMARK ****************************** }
  222. { Two new virtual methods have been added to the object in the form of }
  223. { Close and Open. The main use here is in the Disk Based Descendants }
  224. { the calls open and close the given file so these objects can be }
  225. { used like standard files. Two new fields have also been added to }
  226. { speed up seeks on descendants. All existing code will compile and }
  227. { work completely normally oblivious to these new methods and fields. }
  228. { ****************************** END REMARK *** Leon de Boer, 15May96 * }
  229. {---------------------------------------------------------------------------}
  230. { TStream OBJECT - STREAM ANCESTOR OBJECT }
  231. {---------------------------------------------------------------------------}
  232. TYPE
  233. TStream = OBJECT (TObject)
  234. Status : Integer; { Stream status }
  235. ErrorInfo : Integer; { Stream error info }
  236. StreamSize: LongInt; { Stream current size }
  237. Position : LongInt; { Current position }
  238. TPCompatible : Boolean;
  239. CONSTRUCTOR Init;
  240. FUNCTION Get: PObject;
  241. FUNCTION StrRead: PChar;
  242. FUNCTION GetPos: Longint; Virtual;
  243. FUNCTION GetSize: Longint; Virtual;
  244. FUNCTION ReadStr: PString;
  245. PROCEDURE Open (OpenMode: Word); Virtual;
  246. PROCEDURE Close; Virtual;
  247. PROCEDURE Reset;
  248. PROCEDURE Flush; Virtual;
  249. PROCEDURE Truncate; Virtual;
  250. PROCEDURE Put (P: PObject);
  251. PROCEDURE StrWrite (P: PChar);
  252. PROCEDURE WriteStr (P: PString);
  253. PROCEDURE Seek (Pos: LongInt); Virtual;
  254. PROCEDURE Error (Code, Info: Integer); Virtual;
  255. PROCEDURE Read (Var Buf; Count: LongInt); Virtual;
  256. PROCEDURE Write (Var Buf; Count: LongInt); Virtual;
  257. PROCEDURE CopyFrom (Var S: TStream; Count: Longint);
  258. END;
  259. PStream = ^TStream;
  260. { ******************************* REMARK ****************************** }
  261. { A few minor changes to this object and an extra field added called }
  262. { FName which holds an AsciiZ array of the filename this allows the }
  263. { streams file to be opened and closed like a normal text file. All }
  264. { existing code should work without any changes. }
  265. { ****************************** END REMARK *** Leon de Boer, 19May96 * }
  266. {---------------------------------------------------------------------------}
  267. { TDosStream OBJECT - DOS FILE STREAM OBJECT }
  268. {---------------------------------------------------------------------------}
  269. TYPE
  270. TDosStream = OBJECT (TStream)
  271. Handle: THandle; { DOS file handle }
  272. FName : AsciiZ; { AsciiZ filename }
  273. CONSTRUCTOR Init (FileName: FNameStr; Mode: Word);
  274. DESTRUCTOR Done; Virtual;
  275. PROCEDURE Close; Virtual;
  276. PROCEDURE Truncate; Virtual;
  277. PROCEDURE Seek (Pos: LongInt); Virtual;
  278. PROCEDURE Open (OpenMode: Word); Virtual;
  279. PROCEDURE Read (Var Buf; Count: Longint); Virtual;
  280. PROCEDURE Write (Var Buf; Count: Longint); Virtual;
  281. private
  282. FileInfo : File;
  283. END;
  284. PDosStream = ^TDosStream;
  285. { ******************************* REMARK ****************************** }
  286. { A few minor changes to this object and an extra field added called }
  287. { lastmode which holds the read or write condition last using the }
  288. { speed up buffer which helps speed up the flush, position and size }
  289. { functions. All existing code should work without any changes. }
  290. { ****************************** END REMARK *** Leon de Boer, 19May96 * }
  291. {---------------------------------------------------------------------------}
  292. { TBufStream OBJECT - BUFFERED DOS FILE STREAM }
  293. {---------------------------------------------------------------------------}
  294. TYPE
  295. TBufStream = OBJECT (TDosStream)
  296. LastMode: Byte; { Last buffer mode }
  297. BufSize : Longint; { Buffer size }
  298. BufPtr : Longint; { Buffer start }
  299. BufEnd : Longint; { Buffer end }
  300. Buffer : PByteArray; { Buffer allocated }
  301. CONSTRUCTOR Init (FileName: FNameStr; Mode, Size: Word);
  302. DESTRUCTOR Done; Virtual;
  303. PROCEDURE Close; Virtual;
  304. PROCEDURE Flush; Virtual;
  305. PROCEDURE Truncate; Virtual;
  306. PROCEDURE Seek (Pos: LongInt); Virtual;
  307. PROCEDURE Open (OpenMode: Word); Virtual;
  308. PROCEDURE Read (Var Buf; Count: Longint); Virtual;
  309. PROCEDURE Write (Var Buf; Count: Longint); Virtual;
  310. END;
  311. PBufStream = ^TBufStream;
  312. { ******************************* REMARK ****************************** }
  313. { All the changes here should be completely transparent to existing }
  314. { code. Basically the memory blocks do not have to be base segments }
  315. { but this means our list becomes memory blocks rather than segments. }
  316. { The stream will also expand like the other standard streams!! }
  317. { ****************************** END REMARK *** Leon de Boer, 19May96 * }
  318. {---------------------------------------------------------------------------}
  319. { TMemoryStream OBJECT - MEMORY STREAM OBJECT }
  320. {---------------------------------------------------------------------------}
  321. TYPE
  322. TMemoryStream = OBJECT (TStream)
  323. BlkCount: Longint; { Number of segments }
  324. BlkSize : Word; { Memory block size }
  325. MemSize : LongInt; { Memory alloc size }
  326. BlkList : PPointerArray; { Memory block list }
  327. CONSTRUCTOR Init (ALimit: Longint; ABlockSize: Word);
  328. DESTRUCTOR Done; Virtual;
  329. PROCEDURE Truncate; Virtual;
  330. PROCEDURE Read (Var Buf; Count: Longint); Virtual;
  331. PROCEDURE Write (Var Buf; Count: Longint); Virtual;
  332. PRIVATE
  333. FUNCTION ChangeListSize (ALimit: Longint): Boolean;
  334. END;
  335. PMemoryStream = ^TMemoryStream;
  336. TYPE
  337. TItemList = Array [0..MaxCollectionSize - 1] Of Pointer;
  338. PItemList = ^TItemList;
  339. { ******************************* REMARK ****************************** }
  340. { The changes here look worse than they are. The Sw_Integer simply }
  341. { switches between Integers and LongInts if switched between 16 and 32 }
  342. { bit code. All existing code will compile without any changes. }
  343. { ****************************** END REMARK *** Leon de Boer, 10May96 * }
  344. {---------------------------------------------------------------------------}
  345. { TCollection OBJECT - COLLECTION ANCESTOR OBJECT }
  346. {---------------------------------------------------------------------------}
  347. TCollection = OBJECT (TObject)
  348. Items: PItemList; { Item list pointer }
  349. Count: Sw_Integer; { Item count }
  350. Limit: Sw_Integer; { Item limit count }
  351. Delta: Sw_Integer; { Inc delta size }
  352. CONSTRUCTOR Init (ALimit, ADelta: Sw_Integer);
  353. CONSTRUCTOR Load (Var S: TStream);
  354. DESTRUCTOR Done; Virtual;
  355. FUNCTION At (Index: Sw_Integer): Pointer;
  356. FUNCTION IndexOf (Item: Pointer): Sw_Integer; Virtual;
  357. FUNCTION GetItem (Var S: TStream): Pointer; Virtual;
  358. FUNCTION LastThat (Test: Pointer): Pointer;
  359. FUNCTION FirstThat (Test: Pointer): Pointer;
  360. PROCEDURE Pack;
  361. PROCEDURE FreeAll;
  362. PROCEDURE DeleteAll;
  363. PROCEDURE Free (Item: Pointer);
  364. PROCEDURE Insert (Item: Pointer); Virtual;
  365. PROCEDURE Delete (Item: Pointer);
  366. PROCEDURE AtFree (Index: Sw_Integer);
  367. PROCEDURE FreeItem (Item: Pointer); Virtual;
  368. PROCEDURE AtDelete (Index: Sw_Integer);
  369. PROCEDURE ForEach (Action: Pointer);
  370. PROCEDURE SetLimit (ALimit: Sw_Integer); Virtual;
  371. PROCEDURE Error (Code, Info: Integer); Virtual;
  372. PROCEDURE AtPut (Index: Sw_Integer; Item: Pointer);
  373. PROCEDURE AtInsert (Index: Sw_Integer; Item: Pointer);
  374. PROCEDURE Store (Var S: TStream);
  375. PROCEDURE PutItem (Var S: TStream; Item: Pointer); Virtual;
  376. END;
  377. PCollection = ^TCollection;
  378. {---------------------------------------------------------------------------}
  379. { TSortedCollection OBJECT - SORTED COLLECTION ANCESTOR }
  380. {---------------------------------------------------------------------------}
  381. TYPE
  382. TSortedCollection = OBJECT (TCollection)
  383. Duplicates: Boolean; { Duplicates flag }
  384. CONSTRUCTOR Init (ALimit, ADelta: Sw_Integer);
  385. CONSTRUCTOR Load (Var S: TStream);
  386. FUNCTION KeyOf (Item: Pointer): Pointer; Virtual;
  387. FUNCTION IndexOf (Item: Pointer): Sw_Integer; Virtual;
  388. FUNCTION Compare (Key1, Key2: Pointer): Sw_Integer; Virtual;
  389. FUNCTION Search (Key: Pointer; Var Index: Sw_Integer): Boolean;Virtual;
  390. PROCEDURE Insert (Item: Pointer); Virtual;
  391. PROCEDURE Store (Var S: TStream);
  392. END;
  393. PSortedCollection = ^TSortedCollection;
  394. {---------------------------------------------------------------------------}
  395. { TStringCollection OBJECT - STRING COLLECTION OBJECT }
  396. {---------------------------------------------------------------------------}
  397. TYPE
  398. TStringCollection = OBJECT (TSortedCollection)
  399. FUNCTION GetItem (Var S: TStream): Pointer; Virtual;
  400. FUNCTION Compare (Key1, Key2: Pointer): Sw_Integer; Virtual;
  401. PROCEDURE FreeItem (Item: Pointer); Virtual;
  402. PROCEDURE PutItem (Var S: TStream; Item: Pointer); Virtual;
  403. END;
  404. PStringCollection = ^TStringCollection;
  405. {---------------------------------------------------------------------------}
  406. { TStrCollection OBJECT - STRING COLLECTION OBJECT }
  407. {---------------------------------------------------------------------------}
  408. TYPE
  409. TStrCollection = OBJECT (TSortedCollection)
  410. FUNCTION Compare (Key1, Key2: Pointer): Sw_Integer; Virtual;
  411. FUNCTION GetItem (Var S: TStream): Pointer; Virtual;
  412. PROCEDURE FreeItem (Item: Pointer); Virtual;
  413. PROCEDURE PutItem (Var S: TStream; Item: Pointer); Virtual;
  414. END;
  415. PStrCollection = ^TStrCollection;
  416. { ******************************* REMARK ****************************** }
  417. { This is a completely >> NEW << object which holds a collection of }
  418. { strings but does not alphabetically sort them. It is a very useful }
  419. { object for insert ordered list boxes! }
  420. { ****************************** END REMARK *** Leon de Boer, 15May96 * }
  421. {---------------------------------------------------------------------------}
  422. { TUnSortedStrCollection - UNSORTED STRING COLLECTION OBJECT }
  423. {---------------------------------------------------------------------------}
  424. TYPE
  425. TUnSortedStrCollection = OBJECT (TStringCollection)
  426. PROCEDURE Insert (Item: Pointer); Virtual;
  427. END;
  428. PUnSortedStrCollection = ^TUnSortedStrCollection;
  429. {---------------------------------------------------------------------------}
  430. { TResourceCollection OBJECT - RESOURCE COLLECTION OBJECT }
  431. {---------------------------------------------------------------------------}
  432. TYPE
  433. TResourceCollection = OBJECT (TStringCollection)
  434. FUNCTION KeyOf (Item: Pointer): Pointer; Virtual;
  435. FUNCTION GetItem (Var S: TStream): Pointer; Virtual;
  436. PROCEDURE FreeItem (Item: Pointer); Virtual;
  437. PROCEDURE PutItem (Var S: TStream; Item: Pointer); Virtual;
  438. END;
  439. PResourceCollection = ^TResourceCollection;
  440. {---------------------------------------------------------------------------}
  441. { TResourceFile OBJECT - RESOURCE FILE OBJECT }
  442. {---------------------------------------------------------------------------}
  443. TYPE
  444. TResourceFile = OBJECT (TObject)
  445. Stream : PStream; { File as a stream }
  446. Modified: Boolean; { Modified flag }
  447. CONSTRUCTOR Init (AStream: PStream);
  448. DESTRUCTOR Done; Virtual;
  449. FUNCTION Count: Sw_Integer;
  450. FUNCTION KeyAt (I: Sw_Integer): String;
  451. FUNCTION Get (Key: String): PObject;
  452. FUNCTION SwitchTo (AStream: PStream; Pack: Boolean): PStream;
  453. PROCEDURE Flush;
  454. PROCEDURE Delete (Key: String);
  455. PROCEDURE Put (Item: PObject; Key: String);
  456. PRIVATE
  457. BasePos: LongInt; { Base position }
  458. IndexPos: LongInt; { Index position }
  459. Index: TResourceCollection; { Index collection }
  460. END;
  461. PResourceFile = ^TResourceFile;
  462. TYPE
  463. TStrIndexRec = Packed RECORD
  464. Key : Sw_word;
  465. Count, Offset: Word;
  466. END;
  467. TStrIndex = Array [0..9999] Of TStrIndexRec;
  468. PStrIndex = ^TStrIndex;
  469. {---------------------------------------------------------------------------}
  470. { TStringList OBJECT - STRING LIST OBJECT }
  471. {---------------------------------------------------------------------------}
  472. TStringList = OBJECT (TObject)
  473. CONSTRUCTOR Load (Var S: TStream);
  474. DESTRUCTOR Done; Virtual;
  475. FUNCTION Get (Key: Sw_Word): String;
  476. PRIVATE
  477. Stream : PStream;
  478. BasePos : Longint;
  479. IndexSize: Longint;
  480. Index : PStrIndex;
  481. PROCEDURE ReadStr (Var S: String; Offset, Skip: Longint);
  482. END;
  483. PStringList = ^TStringList;
  484. {---------------------------------------------------------------------------}
  485. { TStrListMaker OBJECT - RESOURCE FILE OBJECT }
  486. {---------------------------------------------------------------------------}
  487. TYPE
  488. TStrListMaker = OBJECT (TObject)
  489. CONSTRUCTOR Init (AStrSize, AIndexSize: Sw_Word);
  490. DESTRUCTOR Done; Virtual;
  491. PROCEDURE Put (Key: Sw_Word; S: String);
  492. PROCEDURE Store (Var S: TStream);
  493. PRIVATE
  494. StrPos : Sw_Word;
  495. StrSize : Sw_Word;
  496. Strings : PByteArray;
  497. IndexPos : Sw_Word;
  498. IndexSize: Sw_Word;
  499. Index : PStrIndex;
  500. Cur : TStrIndexRec;
  501. PROCEDURE CloseCurrent;
  502. END;
  503. PStrListMaker = ^TStrListMaker;
  504. {***************************************************************************}
  505. { INTERFACE ROUTINES }
  506. {***************************************************************************}
  507. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  508. { CALL HELPERS INTERFACE ROUTINES }
  509. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  510. { Constructor calls.
  511. Ctor Pointer to the constructor.
  512. Obj Pointer to the instance. NIL if new instance to be allocated.
  513. VMT Pointer to the VMT (obtained by TypeOf()).
  514. returns Pointer to the instance.
  515. }
  516. function CallVoidConstructor(Ctor: pointer; Obj: pointer; VMT: pointer): pointer;inline;
  517. function CallPointerConstructor(Ctor: pointer; Obj: pointer; VMT: pointer; Param1: pointer): pointer;inline;
  518. { Method calls.
  519. Method Pointer to the method.
  520. Obj Pointer to the instance. NIL if new instance to be allocated.
  521. returns Pointer to the instance.
  522. }
  523. function CallVoidMethod(Method: pointer; Obj: pointer): pointer;inline;
  524. function CallPointerMethod(Method: pointer; Obj: pointer; Param1: pointer): pointer;inline;
  525. { Local-function/procedure calls.
  526. Func Pointer to the local function (which must be far-coded).
  527. Frame Frame pointer of the wrapping function.
  528. }
  529. function CallVoidLocal(Func: pointer; Frame: Pointer): pointer;inline;
  530. function CallPointerLocal(Func: pointer; Frame: Pointer; Param1: pointer): pointer;inline;
  531. { Calls of functions/procedures local to methods.
  532. Func Pointer to the local function (which must be far-coded).
  533. Frame Frame pointer of the wrapping method.
  534. Obj Pointer to the object that the method belongs to.
  535. }
  536. function CallVoidMethodLocal(Func: pointer; Frame: Pointer; Obj: pointer): pointer;inline;
  537. function CallPointerMethodLocal(Func: pointer; Frame: Pointer; Obj: pointer; Param1: pointer): pointer;inline;
  538. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  539. { DYNAMIC STRING INTERFACE ROUTINES }
  540. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  541. {-NewStr-------------------------------------------------------------
  542. Allocates a dynamic string into memory. If S is nil, NewStr returns
  543. a nil pointer, otherwise NewStr allocates Length(S)+1 bytes of memory
  544. containing a copy of S, and returns a pointer to the string.
  545. 12Jun96 LdB
  546. ---------------------------------------------------------------------}
  547. FUNCTION NewStr (Const S: String): PString;
  548. {-DisposeStr---------------------------------------------------------
  549. Disposes of a PString allocated by the function NewStr.
  550. 12Jun96 LdB
  551. ---------------------------------------------------------------------}
  552. PROCEDURE DisposeStr (P: PString);
  553. PROCEDURE SetStr(VAR p:pString; CONST s:STRING);
  554. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  555. { STREAM INTERFACE ROUTINES }
  556. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  557. {-Abstract-----------------------------------------------------------
  558. Terminates program with a run-time error 211. When implementing
  559. an abstract object type, call Abstract in those virtual methods that
  560. must be overridden in descendant types. This ensures that any
  561. attempt to use instances of the abstract object type will fail.
  562. 12Jun96 LdB
  563. ---------------------------------------------------------------------}
  564. PROCEDURE Abstract;
  565. {-RegisterObjects----------------------------------------------------
  566. Registers the three standard objects TCollection, TStringCollection
  567. and TStrCollection.
  568. 02Sep97 LdB
  569. ---------------------------------------------------------------------}
  570. PROCEDURE RegisterObjects;
  571. {-RegisterType-------------------------------------------------------
  572. Registers the given object type with Free Vision's streams, creating
  573. a list of known objects. Streams can only store and return these known
  574. object types. Each registered object needs a unique stream registration
  575. record, of type TStreamRec.
  576. 02Sep97 LdB
  577. ---------------------------------------------------------------------}
  578. PROCEDURE RegisterType (Var S: TStreamRec);
  579. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  580. { GENERAL FUNCTION INTERFACE ROUTINES }
  581. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  582. {-LongMul------------------------------------------------------------
  583. Returns the long integer value of X * Y integer values.
  584. 04Sep97 LdB
  585. ---------------------------------------------------------------------}
  586. FUNCTION LongMul (X, Y: Integer): LongInt;
  587. {-LongDiv------------------------------------------------------------
  588. Returns the integer value of long integer X divided by integer Y.
  589. 04Sep97 LdB
  590. ---------------------------------------------------------------------}
  591. FUNCTION LongDiv (X: Longint; Y: Integer): Integer;
  592. {***************************************************************************}
  593. { PUBLIC INITIALIZED VARIABLES }
  594. {***************************************************************************}
  595. CONST
  596. {---------------------------------------------------------------------------}
  597. { INITIALIZED DOS/DPMI/WIN/OS2 PUBLIC VARIABLES }
  598. {---------------------------------------------------------------------------}
  599. StreamError: Pointer = Nil; { Stream error ptr }
  600. DefaultTPCompatible: Boolean = false;
  601. {---------------------------------------------------------------------------}
  602. { STREAM REGISTRATION RECORDS }
  603. {---------------------------------------------------------------------------}
  604. CONST
  605. RCollection: TStreamRec = (
  606. ObjType: 50;
  607. VmtLink: Ofs(TypeOf(TCollection)^);
  608. Load: @TCollection.Load;
  609. Store: @TCollection.Store;
  610. Next: Nil);
  611. RStringCollection: TStreamRec = (
  612. ObjType: 51;
  613. VmtLink: Ofs(TypeOf(TStringCollection)^);
  614. Load: @TStringCollection.Load;
  615. Store: @TStringCollection.Store;
  616. Next: Nil);
  617. RStrCollection: TStreamRec = (
  618. ObjType: 69;
  619. VmtLink: Ofs(TypeOf(TStrCollection)^);
  620. Load: @TStrCollection.Load;
  621. Store: @TStrCollection.Store;
  622. Next: Nil);
  623. RStringList: TStreamRec = (
  624. ObjType: 52;
  625. VmtLink: Ofs(TypeOf(TStringList)^);
  626. Load: @TStringList.Load;
  627. Store: Nil;
  628. Next: Nil);
  629. RStrListMaker: TStreamRec = (
  630. ObjType: 52;
  631. VmtLink: Ofs(TypeOf(TStrListMaker)^);
  632. Load: Nil;
  633. Store: @TStrListMaker.Store;
  634. Next: Nil);
  635. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  636. IMPLEMENTATION
  637. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  638. Uses dos;
  639. {***************************************************************************}
  640. { HELPER ROUTINES FOR CALLING }
  641. {***************************************************************************}
  642. type
  643. VoidLocal = function(_EBP: Pointer): pointer;
  644. PointerLocal = function(_EBP: Pointer; Param1: pointer): pointer;
  645. VoidMethodLocal = function(_EBP: Pointer): pointer;
  646. PointerMethodLocal = function(_EBP: Pointer; Param1: pointer): pointer;
  647. VoidConstructor = function(VMT: pointer; Obj: pointer): pointer;
  648. PointerConstructor = function(VMT: pointer; Obj: pointer; Param1: pointer): pointer;
  649. VoidMethod = function(Obj: pointer): pointer;
  650. PointerMethod = function(Obj: pointer; Param1: pointer): pointer;
  651. function CallVoidConstructor(Ctor: pointer; Obj: pointer; VMT: pointer): pointer;inline;
  652. begin
  653. CallVoidConstructor := VoidConstructor(Ctor)(Obj, VMT);
  654. end;
  655. function CallPointerConstructor(Ctor: pointer; Obj: pointer; VMT: pointer; Param1: pointer): pointer;inline;
  656. {$undef FPC_CallPointerConstructor_Implemented}
  657. begin
  658. {$define FPC_CallPointerConstructor_Implemented}
  659. CallPointerConstructor := PointerConstructor(Ctor)(Obj, VMT, Param1)
  660. end;
  661. {$ifndef FPC_CallPointerConstructor_Implemented}
  662. {$error CallPointerConstructor function not implemented}
  663. {$endif not FPC_CallPointerConstructor_Implemented}
  664. function CallVoidMethod(Method: pointer; Obj: pointer): pointer;inline;
  665. begin
  666. CallVoidMethod := VoidMethod(Method)(Obj)
  667. end;
  668. function CallPointerMethod(Method: pointer; Obj: pointer; Param1: pointer): pointer;inline;
  669. {$undef FPC_CallPointerMethod_Implemented}
  670. begin
  671. {$define FPC_CallPointerMethod_Implemented}
  672. CallPointerMethod := PointerMethod(Method)(Obj, Param1)
  673. end;
  674. {$ifndef FPC_CallPointerMethod_Implemented}
  675. {$error CallPointerMethod function not implemented}
  676. {$endif not FPC_CallPointerMethod_Implemented}
  677. function CallVoidLocal(Func: pointer; Frame: Pointer): pointer;inline;
  678. begin
  679. CallVoidLocal := VoidLocal(Func)(Frame)
  680. end;
  681. function CallPointerLocal(Func: pointer; Frame: Pointer; Param1: pointer): pointer;inline;
  682. begin
  683. CallPointerLocal := PointerLocal(Func)(Frame, Param1)
  684. end;
  685. function CallVoidMethodLocal(Func: pointer; Frame: Pointer; Obj: pointer): pointer;inline;
  686. begin
  687. CallVoidMethodLocal := VoidMethodLocal(Func)(Frame)
  688. end;
  689. function CallPointerMethodLocal(Func: pointer; Frame: Pointer; Obj: pointer; Param1: pointer): pointer;inline;
  690. begin
  691. CallPointerMethodLocal := PointerMethodLocal(Func)(Frame, Param1)
  692. end;
  693. {***************************************************************************}
  694. { PRIVATE INITIALIZED VARIABLES }
  695. {***************************************************************************}
  696. {---------------------------------------------------------------------------}
  697. { INITIALIZED DOS/DPMI/WIN/OS2 PRIVATE VARIABLES }
  698. {---------------------------------------------------------------------------}
  699. CONST
  700. StreamTypes: PStreamRec = Nil; { Stream types reg }
  701. {***************************************************************************}
  702. { PRIVATE INTERNAL ROUTINES }
  703. {***************************************************************************}
  704. {---------------------------------------------------------------------------}
  705. { RegisterError -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  706. {---------------------------------------------------------------------------}
  707. PROCEDURE RegisterError;
  708. BEGIN
  709. RunError(212); { Register error }
  710. END;
  711. {***************************************************************************}
  712. { OBJECT METHODS }
  713. {***************************************************************************}
  714. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  715. { TRect OBJECT METHODS }
  716. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  717. PROCEDURE CheckEmpty (Var Rect: TRect);
  718. BEGIN
  719. With Rect Do Begin
  720. If (A.X >= B.X) OR (A.Y >= B.Y) Then Begin { Zero or reversed }
  721. A.X := 0; { Clear a.x }
  722. A.Y := 0; { Clear a.y }
  723. B.X := 0; { Clear b.x }
  724. B.Y := 0; { Clear b.y }
  725. End;
  726. End;
  727. END;
  728. {--TRect--------------------------------------------------------------------}
  729. { Empty -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  730. {---------------------------------------------------------------------------}
  731. FUNCTION TRect.Empty: Boolean;
  732. BEGIN
  733. Empty := (A.X >= B.X) OR (A.Y >= B.Y); { Empty result }
  734. END;
  735. {--TRect--------------------------------------------------------------------}
  736. { Equals -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  737. {---------------------------------------------------------------------------}
  738. FUNCTION TRect.Equals (R: TRect): Boolean;
  739. BEGIN
  740. Equals := (A.X = R.A.X) AND (A.Y = R.A.Y) AND
  741. (B.X = R.B.X) AND (B.Y = R.B.Y); { Equals result }
  742. END;
  743. {--TRect--------------------------------------------------------------------}
  744. { Contains -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  745. {---------------------------------------------------------------------------}
  746. FUNCTION TRect.Contains (P: TPoint): Boolean;
  747. BEGIN
  748. Contains := (P.X >= A.X) AND (P.X < B.X) AND
  749. (P.Y >= A.Y) AND (P.Y < B.Y); { Contains result }
  750. END;
  751. {--TRect--------------------------------------------------------------------}
  752. { Copy -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  753. {---------------------------------------------------------------------------}
  754. PROCEDURE TRect.Copy (R: TRect);
  755. BEGIN
  756. A := R.A; { Copy point a }
  757. B := R.B; { Copy point b }
  758. END;
  759. {--TRect--------------------------------------------------------------------}
  760. { Union -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  761. {---------------------------------------------------------------------------}
  762. PROCEDURE TRect.Union (R: TRect);
  763. BEGIN
  764. If (R.A.X < A.X) Then A.X := R.A.X; { Take if smaller }
  765. If (R.A.Y < A.Y) Then A.Y := R.A.Y; { Take if smaller }
  766. If (R.B.X > B.X) Then B.X := R.B.X; { Take if larger }
  767. If (R.B.Y > B.Y) Then B.Y := R.B.Y; { Take if larger }
  768. END;
  769. {--TRect--------------------------------------------------------------------}
  770. { Intersect -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  771. {---------------------------------------------------------------------------}
  772. PROCEDURE TRect.Intersect (R: TRect);
  773. BEGIN
  774. If (R.A.X > A.X) Then A.X := R.A.X; { Take if larger }
  775. If (R.A.Y > A.Y) Then A.Y := R.A.Y; { Take if larger }
  776. If (R.B.X < B.X) Then B.X := R.B.X; { Take if smaller }
  777. If (R.B.Y < B.Y) Then B.Y := R.B.Y; { Take if smaller }
  778. CheckEmpty(Self); { Check if empty }
  779. END;
  780. {--TRect--------------------------------------------------------------------}
  781. { Move -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  782. {---------------------------------------------------------------------------}
  783. PROCEDURE TRect.Move (ADX, ADY: Sw_Integer);
  784. BEGIN
  785. Inc(A.X, ADX); { Adjust A.X }
  786. Inc(A.Y, ADY); { Adjust A.Y }
  787. Inc(B.X, ADX); { Adjust B.X }
  788. Inc(B.Y, ADY); { Adjust B.Y }
  789. END;
  790. {--TRect--------------------------------------------------------------------}
  791. { Grow -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  792. {---------------------------------------------------------------------------}
  793. PROCEDURE TRect.Grow (ADX, ADY: Sw_Integer);
  794. BEGIN
  795. Dec(A.X, ADX); { Adjust A.X }
  796. Dec(A.Y, ADY); { Adjust A.Y }
  797. Inc(B.X, ADX); { Adjust B.X }
  798. Inc(B.Y, ADY); { Adjust B.Y }
  799. CheckEmpty(Self); { Check if empty }
  800. END;
  801. {--TRect--------------------------------------------------------------------}
  802. { Assign -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  803. {---------------------------------------------------------------------------}
  804. PROCEDURE TRect.Assign (XA, YA, XB, YB: Sw_Integer);
  805. BEGIN
  806. A.X := XA; { Hold A.X value }
  807. A.Y := YA; { Hold A.Y value }
  808. B.X := XB; { Hold B.X value }
  809. B.Y := YB; { Hold B.Y value }
  810. END;
  811. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  812. { TObject OBJECT METHODS }
  813. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  814. TYPE
  815. DummyObject = OBJECT (TObject) { Internal object }
  816. Data: RECORD END; { Helps size VMT link }
  817. END;
  818. { ******************************* REMARK ****************************** }
  819. { I Prefer this code because it self sizes VMT link rather than using a }
  820. { fixed record structure thus it should work on all compilers without a }
  821. { specific record to match each compiler. }
  822. { ****************************** END REMARK *** Leon de Boer, 10May96 * }
  823. {--TObject------------------------------------------------------------------}
  824. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  825. {---------------------------------------------------------------------------}
  826. CONSTRUCTOR TObject.Init;
  827. VAR LinkSize: LongInt; Dummy: DummyObject;
  828. BEGIN
  829. LinkSize := PtrInt(@Dummy.Data)-PtrInt(@Dummy); { Calc VMT link size }
  830. FillChar(Pointer(PtrInt(@Self)+LinkSize)^,
  831. SizeOf(Self)-LinkSize, #0); { Clear data fields }
  832. END;
  833. {--TObject------------------------------------------------------------------}
  834. { Free -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  835. {---------------------------------------------------------------------------}
  836. PROCEDURE TObject.Free;
  837. BEGIN
  838. Dispose(PObject(@Self), Done); { Dispose of self }
  839. END;
  840. {--TObject------------------------------------------------------------------}
  841. { Is_Object -> Platforms DOS/DPMI/WIN/OS2 - Checked 5Mar00 DM }
  842. {---------------------------------------------------------------------------}
  843. FUNCTION TObject.Is_Object(P:Pointer):Boolean;
  844. TYPE
  845. PVMT=^VMT;
  846. PPVMT=^PVMT;
  847. VMT=RECORD
  848. Size,NegSize:Longint;
  849. ParentLink:PVMT;
  850. END;
  851. VAR SP:PPVMT; Q:PVMT;
  852. BEGIN
  853. SP:=PPVMT(@SELF);
  854. Q:=SP^;
  855. Is_Object:=False;
  856. While Q<>Nil Do Begin
  857. IF Q=P THEN Begin
  858. Is_Object:=True;
  859. Break;
  860. End;
  861. Q:=Q^.Parentlink;
  862. End;
  863. END;
  864. {--TObject------------------------------------------------------------------}
  865. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  866. {---------------------------------------------------------------------------}
  867. DESTRUCTOR TObject.Done;
  868. BEGIN { Abstract method }
  869. END;
  870. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  871. { TStream OBJECT METHODS }
  872. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  873. CONSTRUCTOR TStream.Init;
  874. BEGIN
  875. Status := StOK;
  876. ErrorInfo := 0;
  877. StreamSize := 0;
  878. Position := 0;
  879. TPCompatible := DefaultTPCompatible;
  880. END;
  881. {--TStream------------------------------------------------------------------}
  882. { Get -> Platforms DOS/DPMI/WIN/OS2 - Checked 02Sep97 LdB }
  883. {---------------------------------------------------------------------------}
  884. FUNCTION TStream.Get: PObject;
  885. VAR ObjType: Sw_Word; P: PStreamRec; ObjTypeWord: Word;
  886. BEGIN
  887. If TPCompatible Then Begin
  888. { Read 16-bit word for TP compatibility. }
  889. Read(ObjTypeWord, SizeOf(ObjTypeWord));
  890. ObjType := ObjTypeWord
  891. End
  892. else
  893. Read(ObjType, SizeOf(ObjType)); { Read object type }
  894. If (ObjType<>0) Then Begin { Object registered }
  895. P := StreamTypes; { Current reg list }
  896. While (P <> Nil) AND (P^.ObjType <> ObjType) { Find object type OR }
  897. Do P := P^.Next; { Find end of chain }
  898. If (P=Nil) Then Begin { Not registered }
  899. Error(stGetError, ObjType); { Obj not registered }
  900. Get := Nil; { Return nil pointer }
  901. End Else
  902. Get :=PObject(
  903. CallPointerConstructor(P^.Load,Nil,P^.VMTLink, @Self)) { Call constructor }
  904. End Else Get := Nil; { Return nil pointer }
  905. END;
  906. {--TStream------------------------------------------------------------------}
  907. { StrRead -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  908. {---------------------------------------------------------------------------}
  909. FUNCTION TStream.StrRead: PChar;
  910. VAR L: Word; P: PChar;
  911. BEGIN
  912. Read(L, SizeOf(L)); { Read length }
  913. If (L = 0) Then StrRead := Nil Else Begin { Check for empty }
  914. GetMem(P, L + 1); { Allocate memory }
  915. If (P <> Nil) Then Begin { Check allocate okay }
  916. Read(P[0], L); { Read the data }
  917. P[L] := #0; { Terminate with #0 }
  918. End;
  919. StrRead := P; { Return PChar }
  920. End;
  921. END;
  922. {--TStream------------------------------------------------------------------}
  923. { ReadStr -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  924. {---------------------------------------------------------------------------}
  925. FUNCTION TStream.ReadStr: PString;
  926. VAR L: Byte; P: PString;
  927. BEGIN
  928. Read(L, 1); { Read string length }
  929. If (L > 0) Then Begin
  930. GetMem(P, L + 1); { Allocate memory }
  931. If (P <> Nil) Then Begin { Check allocate okay }
  932. P^[0] := Char(L); { Hold length }
  933. Read(P^[1], L); { Read string data }
  934. End;
  935. ReadStr := P; { Return string ptr }
  936. End Else ReadStr := Nil;
  937. END;
  938. {--TStream------------------------------------------------------------------}
  939. { GetPos -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  940. {---------------------------------------------------------------------------}
  941. FUNCTION TStream.GetPos: LongInt;
  942. BEGIN
  943. If (Status=stOk) Then GetPos := Position { Return position }
  944. Else GetPos := -1; { Stream in error }
  945. END;
  946. {--TStream------------------------------------------------------------------}
  947. { GetSize -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  948. {---------------------------------------------------------------------------}
  949. FUNCTION TStream.GetSize: LongInt;
  950. BEGIN
  951. If (Status=stOk) Then GetSize := StreamSize { Return stream size }
  952. Else GetSize := -1; { Stream in error }
  953. END;
  954. {--TStream------------------------------------------------------------------}
  955. { Close -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  956. {---------------------------------------------------------------------------}
  957. PROCEDURE TStream.Close;
  958. BEGIN { Abstract method }
  959. END;
  960. {--TStream------------------------------------------------------------------}
  961. { Reset -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  962. {---------------------------------------------------------------------------}
  963. PROCEDURE TStream.Reset;
  964. BEGIN
  965. Status := stOK; { Clear status }
  966. ErrorInfo := 0; { Clear error info }
  967. END;
  968. {--TStream------------------------------------------------------------------}
  969. { Flush -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  970. {---------------------------------------------------------------------------}
  971. PROCEDURE TStream.Flush;
  972. BEGIN { Abstract method }
  973. END;
  974. {--TStream------------------------------------------------------------------}
  975. { Truncate -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  976. {---------------------------------------------------------------------------}
  977. PROCEDURE TStream.Truncate;
  978. BEGIN
  979. Abstract; { Abstract error }
  980. END;
  981. {--TStream------------------------------------------------------------------}
  982. { Put -> Platforms DOS/DPMI/WIN/OS2 - Checked 02Sep97 LdB }
  983. {---------------------------------------------------------------------------}
  984. PROCEDURE TStream.Put (P: PObject);
  985. VAR ObjType: Sw_Word; Link: pointer; Q: PStreamRec; VmtPtr: ^pointer;
  986. ObjTypeWord: Word;
  987. BEGIN
  988. VmtPtr := Pointer(P); { Xfer object to ptr }
  989. if assigned(vmtptr) then
  990. Link := VmtPtr^ { VMT link }
  991. else
  992. Link:=nil;
  993. ObjType := 0; { Set objtype to zero }
  994. If (P<>Nil) AND (Link<>Nil) Then Begin { We have a VMT link }
  995. Q := StreamTypes; { Current reg list }
  996. While (Q <> Nil) AND (Q^.VMTLink <> Link) { Find link match OR }
  997. Do Q := Q^.Next; { Find end of chain }
  998. If (Q=Nil) Then Begin { End of chain found }
  999. Error(stPutError, 0); { Not registered error }
  1000. Exit; { Now exit }
  1001. End Else ObjType := Q^.ObjType; { Update object type }
  1002. End;
  1003. If TPCompatible Then Begin
  1004. ObjTypeWord := word(ObjType);
  1005. Write(ObjTypeWord, SizeOf(ObjTypeWord))
  1006. end
  1007. else
  1008. Write(ObjType, SizeOf(ObjType)); { Write object type }
  1009. If (ObjType<>0) Then { Registered object }
  1010. CallPointerMethod(Q^.Store, P, @Self);
  1011. END;
  1012. {--TStream------------------------------------------------------------------}
  1013. { Seek -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1014. {---------------------------------------------------------------------------}
  1015. PROCEDURE TStream.Seek (Pos: LongInt);
  1016. BEGIN
  1017. If (Status = stOk) Then Begin { Check status }
  1018. If (Pos < 0) Then Pos := 0; { Remove negatives }
  1019. If (Pos <= StreamSize) Then Position := Pos { If valid set pos }
  1020. Else Error(stSeekError, Pos); { Position error }
  1021. End;
  1022. END;
  1023. {--TStream------------------------------------------------------------------}
  1024. { StrWrite -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1025. {---------------------------------------------------------------------------}
  1026. PROCEDURE TStream.StrWrite (P: PChar);
  1027. VAR L: Word; Q: PByteArray;
  1028. BEGIN
  1029. L := 0; { Preset zero size }
  1030. Q := PByteArray(P); { Transfer type }
  1031. If (Q <> Nil) Then While (Q^[L] <> 0) Do Inc(L); { PChar length }
  1032. Write(L, SizeOf(L)); { Store length }
  1033. If (P <> Nil) Then Write(P[0], L); { Write data }
  1034. END;
  1035. {--TStream------------------------------------------------------------------}
  1036. { WriteStr -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1037. {---------------------------------------------------------------------------}
  1038. PROCEDURE TStream.WriteStr (P: PString);
  1039. CONST Empty: String[1] = '';
  1040. BEGIN
  1041. If (P <> Nil) Then Write(P^, Length(P^) + 1) { Write string }
  1042. Else Write(Empty, 1); { Write empty string }
  1043. END;
  1044. {--TStream------------------------------------------------------------------}
  1045. { Open -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1046. {---------------------------------------------------------------------------}
  1047. PROCEDURE TStream.Open (OpenMode: Word);
  1048. BEGIN { Abstract method }
  1049. END;
  1050. {--TStream------------------------------------------------------------------}
  1051. { Error -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1052. {---------------------------------------------------------------------------}
  1053. PROCEDURE TStream.Error (Code, Info: Integer);
  1054. TYPE TErrorProc = Procedure(Var S: TStream);
  1055. BEGIN
  1056. Status := Code; { Hold error code }
  1057. ErrorInfo := Info; { Hold error info }
  1058. If (StreamError <> Nil) Then
  1059. TErrorProc(StreamError)(Self); { Call error ptr }
  1060. END;
  1061. {--TStream------------------------------------------------------------------}
  1062. { Read -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1063. {---------------------------------------------------------------------------}
  1064. PROCEDURE TStream.Read (Var Buf; Count: Longint);
  1065. BEGIN
  1066. Abstract; { Abstract error }
  1067. END;
  1068. {--TStream------------------------------------------------------------------}
  1069. { Write -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1070. {---------------------------------------------------------------------------}
  1071. PROCEDURE TStream.Write (Var Buf; Count: Longint);
  1072. BEGIN
  1073. Abstract; { Abstract error }
  1074. END;
  1075. {--TStream------------------------------------------------------------------}
  1076. { CopyFrom -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1077. {---------------------------------------------------------------------------}
  1078. PROCEDURE TStream.CopyFrom (Var S: TStream; Count: Longint);
  1079. VAR W: Word; Buffer: Array[0..1023] of Byte;
  1080. BEGIN
  1081. While (Count > 0) Do Begin
  1082. If (Count > SizeOf(Buffer)) Then { To much data }
  1083. W := SizeOf(Buffer) Else W := Count; { Size to transfer }
  1084. S.Read(Buffer, W); { Read from stream }
  1085. Write(Buffer, W); { Write to stream }
  1086. Dec(Count, W); { Dec write count }
  1087. End;
  1088. END;
  1089. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1090. { TDosStream OBJECT METHODS }
  1091. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1092. {$IFOPT I+}
  1093. {$DEFINE IO_CHECK_ON}
  1094. {$I-}
  1095. {$ENDIF}
  1096. {--TDosStream---------------------------------------------------------------}
  1097. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1098. {---------------------------------------------------------------------------}
  1099. CONSTRUCTOR TDosStream.Init (FileName: FNameStr; Mode: Word);
  1100. VAR OldFileMode : Byte;
  1101. DosStreamError : Word;
  1102. BEGIN
  1103. Inherited Init; { Call ancestor }
  1104. FileName := FileName+#0; { Make asciiz }
  1105. Move(FileName[1], FName, Length(FileName)); { Create asciiz name }
  1106. Handle := InvalidHandle;
  1107. Assign(FileInfo,FileName);
  1108. { Handle the mode }
  1109. if Mode =stCreate then
  1110. Begin
  1111. Rewrite(FileInfo,1);
  1112. end
  1113. else
  1114. Begin
  1115. OldFileMode := FileMode;
  1116. { Keep sharing modes! }
  1117. FileMode := Mode and $FF;
  1118. System.Reset(FileInfo,1);
  1119. FileMode := OldFileMode;
  1120. { To use the correct mode we must reclose the file
  1121. and open it again
  1122. }
  1123. end;
  1124. Handle := FileRec(FileInfo).Handle; { Set handle value }
  1125. DosStreamError := IOResult;
  1126. If DosStreamError = 0 then
  1127. Begin
  1128. StreamSize := System.FileSize(FileInfo);
  1129. end;
  1130. If DosStreamError = 0 then
  1131. DosStreamError := IOResult;
  1132. If (DosStreamError <> 0) Then
  1133. Error(stInitError, DosStreamError) { Call stream error }
  1134. else
  1135. Status := StOK;
  1136. END;
  1137. {--TDosStream---------------------------------------------------------------}
  1138. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1139. {---------------------------------------------------------------------------}
  1140. DESTRUCTOR TDosStream.Done;
  1141. var
  1142. DosStreamError : Word;
  1143. BEGIN
  1144. if Handle <> InvalidHandle then
  1145. Begin
  1146. System.Close(FileInfo);
  1147. DosStreamError := IOResult;
  1148. If DosStreamError = 0 then
  1149. Status := stOk
  1150. else
  1151. Error(stError, DosStreamError);
  1152. end;
  1153. Position := 0; { Zero the position }
  1154. Handle := InvalidHandle;
  1155. Inherited Done; { Call ancestor }
  1156. END;
  1157. {--TDosStream---------------------------------------------------------------}
  1158. { Close -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1159. {---------------------------------------------------------------------------}
  1160. PROCEDURE TDosStream.Close;
  1161. var
  1162. DosStreamError : Word;
  1163. BEGIN
  1164. if Handle <> InvalidHandle then { Is file closed ? }
  1165. Begin
  1166. System.Close(FileInfo); { Close file }
  1167. DosStreamError := IOResult; { Check for error }
  1168. If DosStreamError = 0 then
  1169. Status := stOk
  1170. else
  1171. Error(stError, DosStreamError); { Call error routine }
  1172. end;
  1173. Position := 0; { Zero the position }
  1174. Handle := InvalidHandle; { Handle invalid }
  1175. END;
  1176. {--TDosStream---------------------------------------------------------------}
  1177. { Truncate -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1178. {---------------------------------------------------------------------------}
  1179. PROCEDURE TDosStream.Truncate;
  1180. var
  1181. DosStreamError : Word;
  1182. BEGIN
  1183. If Status = stOk then
  1184. Begin
  1185. System.Truncate(FileInfo);
  1186. DosStreamError := IOResult;
  1187. If DosStreamError = 0 then
  1188. { Status is already = stOK }
  1189. StreamSize := Position
  1190. else
  1191. Error(stError, DosStreamError);
  1192. end;
  1193. END;
  1194. {--TDosStream---------------------------------------------------------------}
  1195. { Seek -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1196. {---------------------------------------------------------------------------}
  1197. PROCEDURE TDosStream.Seek (Pos: Longint);
  1198. var
  1199. DosStreamError : Word;
  1200. BEGIN
  1201. If (Status=stOk) Then
  1202. Begin { Check status okay }
  1203. If (Pos < 0) Then
  1204. Pos := 0; { Negatives removed }
  1205. System.Seek(FileInfo, Pos);
  1206. DosStreamError := IOResult;
  1207. if DosStreamError <> 0 then
  1208. Error(stSeekError, DosStreamError){ Specific seek error }
  1209. Else Position := Pos; { Adjust position }
  1210. { Status is already = stOK }
  1211. End;
  1212. END;
  1213. {--TDosStream---------------------------------------------------------------}
  1214. { Open -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1215. {---------------------------------------------------------------------------}
  1216. PROCEDURE TDosStream.Open (OpenMode: Word);
  1217. VAR OldFileMode : Byte;
  1218. DosStreamError : Word;
  1219. BEGIN
  1220. If (Status=stOk) Then
  1221. Begin { Check status okay }
  1222. If (Handle = InvalidHandle) Then
  1223. Begin { File not open }
  1224. Assign(FileInfo,FName);
  1225. { Handle the mode }
  1226. if OpenMode =stCreate then
  1227. Begin
  1228. System.Rewrite(FileInfo,1);
  1229. end
  1230. else
  1231. Begin
  1232. OldFileMode := FileMode;
  1233. FileMode := OpenMode and 3;
  1234. System.Reset(FileInfo,1);
  1235. FileMode := OldFileMode;
  1236. { To use the correct mode we must reclose the file
  1237. and open it again
  1238. }
  1239. end;
  1240. Handle := FileRec(FileInfo).Handle; { Set handle value }
  1241. DosStreamError := IOResult;
  1242. If DosStreamError = 0 then
  1243. StreamSize := System.FileSize(FileInfo);
  1244. If DosStreamError = 0 then
  1245. DosStreamError := IOResult;
  1246. If (DosStreamError <> 0) Then
  1247. Error(stOpenError, DosStreamError) { Call stream error }
  1248. else
  1249. Status := StOK;
  1250. Position := 0;
  1251. end
  1252. Else
  1253. Error(stOpenError, 104); { File already open }
  1254. End;
  1255. END;
  1256. {--TDosStream---------------------------------------------------------------}
  1257. { Read -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1258. {---------------------------------------------------------------------------}
  1259. PROCEDURE TDosStream.Read (Var Buf; Count: Longint);
  1260. VAR BytesMoved: Longint;
  1261. DosStreamError : Word;
  1262. BEGIN
  1263. If Status = StOK then
  1264. Begin
  1265. If (Position + Count > StreamSize) Then { Insufficient data }
  1266. Error(stReadError, 0); { Read beyond end!!! }
  1267. If (Handle = InvalidHandle) Then
  1268. Error(stReadError, 103); { File not open }
  1269. BlockRead(FileInfo, Buf, Count, BytesMoved); { Read from file }
  1270. DosStreamError := IOResult;
  1271. If ((DosStreamError<>0) OR (BytesMoved<>Count)) Then
  1272. Begin { Error was detected }
  1273. BytesMoved := 0; { Clear bytes moved }
  1274. If (DosStreamError <> 0) Then
  1275. Error(stReadError, DosStreamError) { Specific read error }
  1276. Else
  1277. Error(stReadError, 0); { Non specific error }
  1278. End;
  1279. Inc(Position, BytesMoved); { Adjust position }
  1280. End;
  1281. { If there was already an error, or an error was just
  1282. generated, fill the vuffer with NULL
  1283. }
  1284. If Status <> StOK then
  1285. FillChar(Buf, Count, #0); { Error clear buffer }
  1286. END;
  1287. {--TDosStream---------------------------------------------------------------}
  1288. { Write -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1289. {---------------------------------------------------------------------------}
  1290. PROCEDURE TDosStream.Write (Var Buf; Count: Longint);
  1291. VAR BytesMoved: Longint;
  1292. DosStreamError : Word;
  1293. BEGIN
  1294. { If status is not OK, simply exit }
  1295. if Status <> StOK then
  1296. exit;
  1297. If (Handle = InvalidHandle) Then
  1298. Error(stWriteError, 103); { File not open }
  1299. BlockWrite(FileInfo, Buf, Count, BytesMoved); { Write to file }
  1300. DosStreamError := IOResult;
  1301. If ((DosStreamError<>0) OR (BytesMoved<>Count)) Then
  1302. Begin { Error was detected }
  1303. BytesMoved := 0; { Clear bytes moved }
  1304. If (DosStreamError<>0) Then
  1305. Error(stWriteError, DOSStreamError) { Specific write error }
  1306. Else
  1307. Error(stWriteError, 0); { Non specific error }
  1308. End;
  1309. Inc(Position, BytesMoved); { Adjust position }
  1310. If (Position > StreamSize) Then { File expanded }
  1311. StreamSize := Position; { Adjust stream size }
  1312. END;
  1313. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1314. { TBufStream OBJECT METHODS }
  1315. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1316. {--TBufStream---------------------------------------------------------------}
  1317. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1318. {---------------------------------------------------------------------------}
  1319. CONSTRUCTOR TBufStream.Init (FileName: FNameStr; Mode, Size: Word);
  1320. BEGIN
  1321. Inherited Init(FileName, Mode); { Call ancestor }
  1322. BufSize := Size; { Hold buffer size }
  1323. If (Size<>0) Then GetMem(Buffer, Size); { Allocate buffer }
  1324. If (Buffer=Nil) Then Error(stInitError, 0); { Buffer allocate fail }
  1325. END;
  1326. {--TBufStream---------------------------------------------------------------}
  1327. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1328. {---------------------------------------------------------------------------}
  1329. DESTRUCTOR TBufStream.Done;
  1330. BEGIN
  1331. Flush; { Flush the file }
  1332. Inherited Done; { Call ancestor }
  1333. If (Buffer<>Nil) Then FreeMem(Buffer, BufSize); { Release buffer }
  1334. END;
  1335. {--TBufStream---------------------------------------------------------------}
  1336. { Close -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1337. {---------------------------------------------------------------------------}
  1338. PROCEDURE TBufStream.Close;
  1339. BEGIN
  1340. Flush; { Flush the buffer }
  1341. Inherited Close; { Call ancestor }
  1342. END;
  1343. {--TBufStream---------------------------------------------------------------}
  1344. { Flush -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1345. {---------------------------------------------------------------------------}
  1346. PROCEDURE TBufStream.Flush;
  1347. VAR W: Longint;
  1348. DosStreamError : Word;
  1349. BEGIN
  1350. If Status <> StOK then
  1351. exit;
  1352. If (LastMode=2) AND (BufPtr<>0) Then Begin { Must update file }
  1353. If (Handle = InvalidHandle) Then DosStreamError := 103 { File is not open }
  1354. Else
  1355. Begin
  1356. BlockWrite(FileInfo, Buffer^,BufPtr, W); { Write to file }
  1357. DosStreamError := IOResult;
  1358. End;
  1359. If (DosStreamError<>0) OR (W<>BufPtr) Then { We have an error }
  1360. If (DosStreamError=0) Then Error(stWriteError, 0){ Unknown write error }
  1361. Else Error(stError, DosStreamError); { Specific write error }
  1362. End;
  1363. BufPtr := 0; { Reset buffer ptr }
  1364. BufEnd := 0; { Reset buffer end }
  1365. END;
  1366. {--TBufStream---------------------------------------------------------------}
  1367. { Truncate -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1368. {---------------------------------------------------------------------------}
  1369. PROCEDURE TBufStream.Truncate;
  1370. BEGIN
  1371. Flush; { Flush buffer }
  1372. Inherited Truncate; { Truncate file }
  1373. END;
  1374. {--TBufStream---------------------------------------------------------------}
  1375. { Seek -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1376. {---------------------------------------------------------------------------}
  1377. PROCEDURE TBufStream.Seek (Pos: LongInt);
  1378. BEGIN
  1379. If (Status=stOk) Then Begin { Check status okay }
  1380. If (Position<>Pos) Then Begin { Move required }
  1381. Flush; { Flush the buffer }
  1382. Inherited Seek(Pos); { Call ancestor }
  1383. End;
  1384. End;
  1385. END;
  1386. {--TBufStream---------------------------------------------------------------}
  1387. { Open -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1388. {---------------------------------------------------------------------------}
  1389. PROCEDURE TBufStream.Open (OpenMode: Word);
  1390. BEGIN
  1391. If (Status=stOk) Then Begin { Check status okay }
  1392. BufPtr := 0; { Clear buffer start }
  1393. BufEnd := 0; { Clear buffer end }
  1394. Inherited Open(OpenMode); { Call ancestor }
  1395. End;
  1396. END;
  1397. {--TBufStream---------------------------------------------------------------}
  1398. { Read -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1399. {---------------------------------------------------------------------------}
  1400. PROCEDURE TBufStream.Read (Var Buf; Count: Longint);
  1401. VAR W, Bw: Longint; P: PByte;
  1402. DosStreamError : Word;
  1403. BEGIN
  1404. If Status <> StOk then
  1405. begin
  1406. FillChar(Buf, Count, #0); { Error clear buffer }
  1407. exit;
  1408. end;
  1409. If (Position + Count > StreamSize) Then { Read pas stream end }
  1410. Error(stReadError, 0); { Call stream error }
  1411. If (Handle = InvalidHandle) Then Error(stReadError, 103); { File not open }
  1412. P := @Buf; { Transfer address }
  1413. If (LastMode=2) Then Flush; { Flush write buffer }
  1414. LastMode := 1; { Now set read mode }
  1415. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1416. If (BufPtr=BufEnd) Then Begin { Buffer is empty }
  1417. If (Position + BufSize > StreamSize) Then
  1418. Bw := StreamSize - Position { Amount of file left }
  1419. Else Bw := BufSize; { Full buffer size }
  1420. BlockRead(FileInfo, Buffer^, Bw, W);
  1421. DosStreamError := IOResult; { Read from file }
  1422. If ((DosStreamError<>0) OR (Bw<>W)) Then Begin { Error was detected }
  1423. If (DosStreamError<>0) Then
  1424. Error(stReadError, DosStreamError) { Specific read error }
  1425. Else Error(stReadError, 0); { Non specific error }
  1426. End Else Begin
  1427. BufPtr := 0; { Reset BufPtr }
  1428. BufEnd := W; { End of buffer }
  1429. End;
  1430. End;
  1431. If (Status=stOk) Then Begin { Status still okay }
  1432. W := BufEnd - BufPtr; { Space in buffer }
  1433. If (Count < W) Then W := Count; { Set transfer size }
  1434. Move(Buffer^[BufPtr], P^, W); { Data from buffer }
  1435. Dec(Count, W); { Reduce count }
  1436. Inc(BufPtr, W); { Advance buffer ptr }
  1437. Inc(P, W); { Transfer address }
  1438. Inc(Position, W); { Advance position }
  1439. End;
  1440. End;
  1441. If (Status<>stOk) AND (Count>0) Then
  1442. FillChar(P^, Count, #0); { Error clear buffer }
  1443. END;
  1444. {--TBufStream---------------------------------------------------------------}
  1445. { Write -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1446. {---------------------------------------------------------------------------}
  1447. PROCEDURE TBufStream.Write (Var Buf; Count: Longint);
  1448. VAR W: Longint;
  1449. P: PByte;
  1450. DosStreamError : Word;
  1451. BEGIN
  1452. if Status <> StOK then exit; { Exit if error }
  1453. If (Handle = InvalidHandle) Then Error(stWriteError, 103); { File not open }
  1454. If (LastMode=1) Then Flush; { Flush read buffer }
  1455. LastMode := 2; { Now set write mode }
  1456. P := @Buf; { Transfer address }
  1457. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1458. If (BufPtr=BufSize) Then Begin { Buffer is full }
  1459. BlockWrite(FileInfo, Buffer^, BufSize,W); { Write to file }
  1460. DosStreamError := IOResult;
  1461. If (DosStreamError<>0) OR (W<>BufSize) Then { We have an error }
  1462. If (DosStreamError=0) Then Error(stWriteError, 0) { Unknown write error }
  1463. Else Error(stError, DosStreamError); { Specific write error }
  1464. BufPtr := 0; { Reset BufPtr }
  1465. End;
  1466. If (Status=stOk) Then Begin { Status still okay }
  1467. W := BufSize - BufPtr; { Space in buffer }
  1468. If (Count < W) Then W := Count; { Transfer size }
  1469. Move(P^, Buffer^[BufPtr], W); { Data to buffer }
  1470. Dec(Count, W); { Reduce count }
  1471. Inc(BufPtr, W); { Advance buffer ptr }
  1472. Inc(P,W); { Transfer address }
  1473. Inc(Position, W); { Advance position }
  1474. If (Position > StreamSize) Then { File has expanded }
  1475. StreamSize := Position; { Update new size }
  1476. End;
  1477. End;
  1478. END;
  1479. {$IFDEF IO_CHECK_ON}
  1480. {$UNDEF IO_CHECK_ON}
  1481. {$I+}
  1482. {$ENDIF}
  1483. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1484. { TMemoryStream OBJECT METHODS }
  1485. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1486. {--TMemoryStream------------------------------------------------------------}
  1487. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1488. {---------------------------------------------------------------------------}
  1489. CONSTRUCTOR TMemoryStream.Init (ALimit: LongInt; ABlockSize: Word);
  1490. VAR W: Word;
  1491. BEGIN
  1492. Inherited Init; { Call ancestor }
  1493. If (ABlockSize=0) Then BlkSize := 8192 Else { Default blocksize }
  1494. BlkSize := ABlockSize; { Set blocksize }
  1495. If (ALimit = 0) Then W := 1 Else { At least 1 block }
  1496. W := (ALimit + BlkSize - 1) DIV BlkSize; { Blocks needed }
  1497. If NOT ChangeListSize(W) Then { Try allocate blocks }
  1498. Error(stInitError, 0); { Initialize error }
  1499. END;
  1500. {--TMemoryStream------------------------------------------------------------}
  1501. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1502. {---------------------------------------------------------------------------}
  1503. DESTRUCTOR TMemoryStream.Done;
  1504. BEGIN
  1505. ChangeListSize(0); { Release all memory }
  1506. Inherited Done; { Call ancestor }
  1507. END;
  1508. {--TMemoryStream------------------------------------------------------------}
  1509. { Truncate -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1510. {---------------------------------------------------------------------------}
  1511. PROCEDURE TMemoryStream.Truncate;
  1512. VAR W: Word;
  1513. BEGIN
  1514. If (Status=stOk) Then Begin { Check status okay }
  1515. If (Position = 0) Then W := 1 Else { At least one block }
  1516. W := (Position + BlkSize - 1) DIV BlkSize; { Blocks needed }
  1517. If ChangeListSize(W) Then StreamSize := Position { Set stream size }
  1518. Else Error(stError, 0); { Error truncating }
  1519. End;
  1520. END;
  1521. {--TMemoryStream------------------------------------------------------------}
  1522. { Read -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1523. {---------------------------------------------------------------------------}
  1524. PROCEDURE TMemoryStream.Read (Var Buf; Count: Longint);
  1525. VAR W, CurBlock, BlockPos: Word; Li: LongInt; P, Q: PByte;
  1526. BEGIN
  1527. If (Position + Count > StreamSize) Then { Insufficient data }
  1528. Error(stReadError, 0); { Read beyond end!!! }
  1529. P := @Buf; { Transfer address }
  1530. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1531. CurBlock := Position DIV BlkSize; { Current block }
  1532. { * REMARK * - Do not shorten this, result can be > 64K }
  1533. Li := CurBlock; { Transfer current block }
  1534. Li := Li * BlkSize; { Current position }
  1535. { * REMARK END * - Leon de Boer }
  1536. BlockPos := Position - Li; { Current position }
  1537. W := BlkSize - BlockPos; { Current block space }
  1538. If (W > Count) Then W := Count; { Adjust read size }
  1539. Q := BlkList^[CurBlock] + BlockPos; { Calc pointer }
  1540. Move(Q^, P^, W); { Move data to buffer }
  1541. Inc(Position, W); { Adjust position }
  1542. Inc(P, W);
  1543. Dec(Count, W); { Adjust count left }
  1544. End;
  1545. If (Count<>0) Then FillChar(P^, Count, #0); { Error clear buffer }
  1546. END;
  1547. {--TMemoryStream------------------------------------------------------------}
  1548. { Write -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1549. {---------------------------------------------------------------------------}
  1550. PROCEDURE TMemoryStream.Write (Var Buf; Count: Longint);
  1551. VAR
  1552. W, CurBlock, BlockPos: Word;
  1553. Li: LongInt;
  1554. P, Q: PByte;
  1555. BEGIN
  1556. If (Position + Count > MemSize) Then Begin { Expansion needed }
  1557. If (Position + Count = 0) Then W := 1 Else { At least 1 block }
  1558. W := (Position+Count+BlkSize-1) DIV BlkSize; { Blocks needed }
  1559. If NOT ChangeListSize(W) Then
  1560. Error(stWriteError, 0); { Expansion failed!!! }
  1561. End;
  1562. P := @Buf; { Transfer address }
  1563. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1564. CurBlock := Position DIV BlkSize; { Current segment }
  1565. { * REMARK * - Do not shorten this, result can be > 64K }
  1566. Li := CurBlock; { Transfer current block }
  1567. Li := Li * BlkSize; { Current position }
  1568. { * REMARK END * - Leon de Boer }
  1569. BlockPos := Position - Li; { Current position }
  1570. W := BlkSize - BlockPos; { Current block space }
  1571. If (W > Count) Then W := Count; { Adjust write size }
  1572. Q := BlkList^[CurBlock] + BlockPos; { Calc pointer }
  1573. Move(P^, Q^, W); { Transfer data }
  1574. Inc(Position, W); { Adjust position }
  1575. Inc(P, W);
  1576. Dec(Count, W); { Adjust count left }
  1577. If (Position > StreamSize) Then { File expanded }
  1578. StreamSize := Position; { Adjust stream size }
  1579. End;
  1580. END;
  1581. {***************************************************************************}
  1582. { TMemoryStream PRIVATE METHODS }
  1583. {***************************************************************************}
  1584. {--TMemoryStream------------------------------------------------------------}
  1585. { ChangeListSize -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1586. {---------------------------------------------------------------------------}
  1587. FUNCTION TMemoryStream.ChangeListSize (ALimit: Longint): Boolean;
  1588. VAR
  1589. W: Longint;
  1590. Li: LongInt;
  1591. P: PPointerArray;
  1592. BEGIN
  1593. If (ALimit <> BlkCount) Then Begin { Change is needed }
  1594. ChangeListSize := False; { Preset failure }
  1595. If (ALimit > MaxPtrs) Then Exit; { To many blocks req }
  1596. If (ALimit <> 0) Then Begin { Create segment list }
  1597. Li := ALimit * SizeOf(Pointer); { Block array size }
  1598. GetMem(P, Li); { Allocate memory }
  1599. FillChar(P^, Li, #0); { Clear the memory }
  1600. If (BlkCount <> 0) AND (BlkList <> Nil) Then { Current list valid }
  1601. If (BlkCount <= ALimit) Then Move(BlkList^,
  1602. P^, BlkCount * SizeOf(Pointer)) Else { Move whole old list }
  1603. Move(BlkList^, P^, Li); { Move partial list }
  1604. End Else P := Nil; { No new block list }
  1605. If (ALimit < BlkCount) Then { Shrink stream size }
  1606. For W := BlkCount-1 DownTo ALimit Do
  1607. FreeMem(BlkList^[W], BlkSize); { Release memory block }
  1608. If (P <> Nil) AND (ALimit > BlkCount) Then Begin { Expand stream size }
  1609. For W := BlkCount To ALimit-1 Do Begin
  1610. GetMem(P^[W], BlkSize); { Allocate memory }
  1611. End;
  1612. End;
  1613. If (BlkCount <> 0) AND (BlkList<>Nil) Then
  1614. FreeMem(BlkList, BlkCount * SizeOf(Pointer)); { Release old list }
  1615. BlkList := P; { Hold new block list }
  1616. BlkCount := ALimit; { Hold new count }
  1617. { * REMARK * - Do not shorten this, result can be > 64K }
  1618. MemSize := BlkCount; { Block count }
  1619. MemSize := MemSize * BlkSize; { Current position }
  1620. { * REMARK END * - Leon de Boer }
  1621. End;
  1622. ChangeListSize := True; { Successful }
  1623. END;
  1624. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1625. { TCollection OBJECT METHODS }
  1626. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1627. {--TCollection--------------------------------------------------------------}
  1628. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1629. {---------------------------------------------------------------------------}
  1630. CONSTRUCTOR TCollection.Init (ALimit, ADelta: Sw_Integer);
  1631. BEGIN
  1632. Inherited Init; { Call ancestor }
  1633. Delta := ADelta; { Set increment }
  1634. SetLimit(ALimit); { Set limit }
  1635. END;
  1636. {--TCollection--------------------------------------------------------------}
  1637. { Load -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1638. {---------------------------------------------------------------------------}
  1639. CONSTRUCTOR TCollection.Load (Var S: TStream);
  1640. VAR C, I: Sw_Integer;
  1641. BEGIN
  1642. If S.TPCompatible Then Begin
  1643. { I ignore endianness issues here. If endianness is different,
  1644. you can't expect binary compatible resources anyway. }
  1645. Count := 0; S.Read(Count, Sizeof(Word));
  1646. Limit := 0; S.Read(Limit, Sizeof(Word));
  1647. Delta := 0; S.Read(Delta, Sizeof(Word))
  1648. End
  1649. Else Begin
  1650. S.Read(Count, Sizeof(Count)); { Read count }
  1651. S.Read(Limit, Sizeof(Limit)); { Read limit }
  1652. S.Read(Delta, Sizeof(Delta)); { Read delta }
  1653. End;
  1654. Items := Nil; { Clear item pointer }
  1655. C := Count; { Hold count }
  1656. I := Limit; { Hold limit }
  1657. Count := 0; { Clear count }
  1658. Limit := 0; { Clear limit }
  1659. SetLimit(I); { Set requested limit }
  1660. Count := C; { Set count }
  1661. For I := 0 To C-1 Do AtPut(I, GetItem(S)); { Get each item }
  1662. END;
  1663. {--TCollection--------------------------------------------------------------}
  1664. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1665. {---------------------------------------------------------------------------}
  1666. DESTRUCTOR TCollection.Done;
  1667. BEGIN
  1668. FreeAll; { Free all items }
  1669. SetLimit(0); { Release all memory }
  1670. END;
  1671. {--TCollection--------------------------------------------------------------}
  1672. { At -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1673. {---------------------------------------------------------------------------}
  1674. FUNCTION TCollection.At (Index: Sw_Integer): Pointer;
  1675. BEGIN
  1676. If (Index < 0) OR (Index >= Count) Then Begin { Invalid index }
  1677. Error(coIndexError, Index); { Call error }
  1678. At := Nil; { Return nil }
  1679. End Else At := Items^[Index]; { Return item }
  1680. END;
  1681. {--TCollection--------------------------------------------------------------}
  1682. { IndexOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1683. {---------------------------------------------------------------------------}
  1684. FUNCTION TCollection.IndexOf (Item: Pointer): Sw_Integer;
  1685. VAR I: Sw_Integer;
  1686. BEGIN
  1687. If (Count>0) Then Begin { Count is positive }
  1688. For I := 0 To Count-1 Do { For each item }
  1689. If (Items^[I]=Item) Then Begin { Look for match }
  1690. IndexOf := I; { Return index }
  1691. Exit; { Now exit }
  1692. End;
  1693. End;
  1694. IndexOf := -1; { Return index }
  1695. END;
  1696. {--TCollection--------------------------------------------------------------}
  1697. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1698. {---------------------------------------------------------------------------}
  1699. FUNCTION TCollection.GetItem (Var S: TStream): Pointer;
  1700. BEGIN
  1701. GetItem := S.Get; { Item off stream }
  1702. END;
  1703. {--TCollection--------------------------------------------------------------}
  1704. { LastThat -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1705. {---------------------------------------------------------------------------}
  1706. {$IFOPT W-}
  1707. {$DEFINE STACKFRAME_OFF}
  1708. {$W+}
  1709. {$ENDIF}
  1710. FUNCTION TCollection.LastThat (Test: Pointer): Pointer;
  1711. VAR I: LongInt;
  1712. BEGIN
  1713. For I := Count DownTo 1 Do
  1714. Begin { Down from last item }
  1715. IF Boolean(Byte(ptrint(CallPointerLocal(Test,get_caller_frame(get_frame),Items^[I-1])))) THEN
  1716. Begin { Test each item }
  1717. LastThat := Items^[I-1]; { Return item }
  1718. Exit; { Now exit }
  1719. End;
  1720. End;
  1721. LastThat := Nil; { None passed test }
  1722. END;
  1723. {--TCollection--------------------------------------------------------------}
  1724. { FirstThat -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1725. {---------------------------------------------------------------------------}
  1726. FUNCTION TCollection.FirstThat (Test: Pointer): Pointer;
  1727. VAR I: LongInt;
  1728. BEGIN
  1729. For I := 1 To Count Do Begin { Up from first item }
  1730. IF Boolean(Byte(ptrint(CallPointerLocal(Test,get_caller_frame(get_frame),Items^[I-1])))) THEN
  1731. Begin { Test each item }
  1732. FirstThat := Items^[I-1]; { Return item }
  1733. Exit; { Now exit }
  1734. End;
  1735. End;
  1736. FirstThat := Nil; { None passed test }
  1737. END;
  1738. {$IFDEF STACKFRAME_OFF}
  1739. {$UNDEF STACKFRAME_OFF}
  1740. {$W-}
  1741. {$ENDIF}
  1742. {--TCollection--------------------------------------------------------------}
  1743. { Pack -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1744. {---------------------------------------------------------------------------}
  1745. PROCEDURE TCollection.Pack;
  1746. VAR I, J: Sw_Integer;
  1747. BEGIN
  1748. I := 0; { Initialize dest }
  1749. J := 0; { Intialize test }
  1750. While (I<Count) AND (J<Limit) Do Begin { Check fully packed }
  1751. If (Items^[J]<>Nil) Then Begin { Found a valid item }
  1752. If (I<>J) Then Begin
  1753. Items^[I] := Items^[J]; { Transfer item }
  1754. Items^[J] := Nil; { Now clear old item }
  1755. End;
  1756. Inc(I); { One item packed }
  1757. End;
  1758. Inc(J); { Next item to test }
  1759. End;
  1760. If (I<Count) Then Count := I; { New packed count }
  1761. END;
  1762. {--TCollection--------------------------------------------------------------}
  1763. { FreeAll -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1764. {---------------------------------------------------------------------------}
  1765. PROCEDURE TCollection.FreeAll;
  1766. VAR I: Sw_Integer;
  1767. BEGIN
  1768. for I := Count-1 downto 0 do
  1769. FreeItem(At(I));
  1770. Count := 0; { Clear item count }
  1771. END;
  1772. {--TCollection--------------------------------------------------------------}
  1773. { DeleteAll -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1774. {---------------------------------------------------------------------------}
  1775. PROCEDURE TCollection.DeleteAll;
  1776. BEGIN
  1777. Count := 0; { Clear item count }
  1778. END;
  1779. {--TCollection--------------------------------------------------------------}
  1780. { Free -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1781. {---------------------------------------------------------------------------}
  1782. PROCEDURE TCollection.Free (Item: Pointer);
  1783. BEGIN
  1784. Delete(Item); { Delete from list }
  1785. FreeItem(Item); { Free the item }
  1786. END;
  1787. {--TCollection--------------------------------------------------------------}
  1788. { Insert -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1789. {---------------------------------------------------------------------------}
  1790. PROCEDURE TCollection.Insert (Item: Pointer);
  1791. BEGIN
  1792. AtInsert(Count, Item); { Insert item }
  1793. END;
  1794. {--TCollection--------------------------------------------------------------}
  1795. { Delete -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1796. {---------------------------------------------------------------------------}
  1797. PROCEDURE TCollection.Delete (Item: Pointer);
  1798. BEGIN
  1799. AtDelete(IndexOf(Item)); { Delete from list }
  1800. END;
  1801. {--TCollection--------------------------------------------------------------}
  1802. { AtFree -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1803. {---------------------------------------------------------------------------}
  1804. PROCEDURE TCollection.AtFree (Index: Sw_Integer);
  1805. VAR Item: Pointer;
  1806. BEGIN
  1807. Item := At(Index); { Retreive item ptr }
  1808. AtDelete(Index); { Delete item }
  1809. FreeItem(Item); { Free the item }
  1810. END;
  1811. {--TCollection--------------------------------------------------------------}
  1812. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1813. {---------------------------------------------------------------------------}
  1814. PROCEDURE TCollection.FreeItem (Item: Pointer);
  1815. VAR P: PObject;
  1816. BEGIN
  1817. P := PObject(Item); { Convert pointer }
  1818. If (P<>Nil) Then Dispose(P, Done); { Dispose of object }
  1819. END;
  1820. {--TCollection--------------------------------------------------------------}
  1821. { AtDelete -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1822. {---------------------------------------------------------------------------}
  1823. PROCEDURE TCollection.AtDelete (Index: Sw_Integer);
  1824. BEGIN
  1825. If (Index >= 0) AND (Index < Count) Then Begin { Valid index }
  1826. Dec(Count); { One less item }
  1827. If (Count>Index) Then Move(Items^[Index+1],
  1828. Items^[Index], (Count-Index)*Sizeof(Pointer)); { Shuffle items down }
  1829. End Else Error(coIndexError, Index); { Index error }
  1830. END;
  1831. {--TCollection--------------------------------------------------------------}
  1832. { ForEach -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1833. {---------------------------------------------------------------------------}
  1834. {$IFOPT W-}
  1835. {$DEFINE STACKFRAME_OFF}
  1836. {$W+}
  1837. {$ENDIF}
  1838. PROCEDURE TCollection.ForEach (Action: Pointer);
  1839. VAR I: LongInt;
  1840. BEGIN
  1841. For I := 1 To Count Do { Up from first item }
  1842. CallPointerLocal(Action,get_caller_frame(get_frame),Items^[I-1]); { Call with each item }
  1843. END;
  1844. {$IFDEF STACKFRAME_OFF}
  1845. {$UNDEF STACKFRAME_OFF}
  1846. {$W-}
  1847. {$ENDIF}
  1848. {--TCollection--------------------------------------------------------------}
  1849. { SetLimit -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1850. {---------------------------------------------------------------------------}
  1851. PROCEDURE TCollection.SetLimit (ALimit: Sw_Integer);
  1852. VAR
  1853. AItems: PItemList;
  1854. BEGIN
  1855. If (ALimit < Count) Then
  1856. ALimit := Count;
  1857. If (ALimit > MaxCollectionSize) Then
  1858. ALimit := MaxCollectionSize;
  1859. If (ALimit <> Limit) Then
  1860. Begin
  1861. If (ALimit = 0) Then
  1862. AItems := Nil
  1863. Else
  1864. Begin
  1865. GetMem(AItems, ALimit * SizeOf(Pointer));
  1866. If (AItems<>Nil) Then
  1867. FillChar(AItems^,ALimit * SizeOf(Pointer), #0);
  1868. End;
  1869. If (AItems<>Nil) OR (ALimit=0) Then
  1870. Begin
  1871. If (AItems <>Nil) AND (Items <> Nil) Then
  1872. Move(Items^, AItems^, Count*SizeOf(Pointer));
  1873. If (Limit <> 0) AND (Items <> Nil) Then
  1874. FreeMem(Items, Limit * SizeOf(Pointer));
  1875. end;
  1876. Items := AItems;
  1877. Limit := ALimit;
  1878. End;
  1879. END;
  1880. {--TCollection--------------------------------------------------------------}
  1881. { Error -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1882. {---------------------------------------------------------------------------}
  1883. PROCEDURE TCollection.Error (Code, Info: Integer);
  1884. BEGIN
  1885. RunError(212 - Code); { Run error }
  1886. END;
  1887. {--TCollection--------------------------------------------------------------}
  1888. { AtPut -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1889. {---------------------------------------------------------------------------}
  1890. PROCEDURE TCollection.AtPut (Index: Sw_Integer; Item: Pointer);
  1891. BEGIN
  1892. If (Index >= 0) AND (Index < Count) Then { Index valid }
  1893. Items^[Index] := Item { Put item in index }
  1894. Else Error(coIndexError, Index); { Index error }
  1895. END;
  1896. {--TCollection--------------------------------------------------------------}
  1897. { AtInsert -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1898. {---------------------------------------------------------------------------}
  1899. PROCEDURE TCollection.AtInsert (Index: Sw_Integer; Item: Pointer);
  1900. VAR I: Sw_Integer;
  1901. BEGIN
  1902. If (Index >= 0) AND (Index <= Count) Then Begin { Valid index }
  1903. If (Count=Limit) Then SetLimit(Limit+Delta); { Expand size if able }
  1904. If (Limit>Count) Then Begin
  1905. If (Index < Count) Then Begin { Not last item }
  1906. For I := Count-1 DownTo Index Do { Start from back }
  1907. Items^[I+1] := Items^[I]; { Move each item }
  1908. End;
  1909. Items^[Index] := Item; { Put item in list }
  1910. Inc(Count); { Inc count }
  1911. End Else Error(coOverflow, Index); { Expand failed }
  1912. End Else Error(coIndexError, Index); { Index error }
  1913. END;
  1914. {--TCollection--------------------------------------------------------------}
  1915. { Store -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1916. {---------------------------------------------------------------------------}
  1917. PROCEDURE TCollection.Store (Var S: TStream);
  1918. var
  1919. LimitWord, DeltaWord: Word;
  1920. PROCEDURE DoPutItem (P: Pointer);{$IFNDEF FPC}FAR;{$ENDIF}
  1921. BEGIN
  1922. PutItem(S, P); { Put item on stream }
  1923. END;
  1924. BEGIN
  1925. If S.TPCompatible Then Begin
  1926. { Check if it is safe to write in TP-compatible stream.
  1927. If Count is too big, signal an error.
  1928. If Limit or Delta are too big, write smaller values. }
  1929. If (Count > MaxTPCompatibleCollectionSize)
  1930. Then S.Error(stWriteError, 0)
  1931. Else Begin
  1932. S.Write(Count, Sizeof(Word));
  1933. if Limit > MaxTPCompatibleCollectionSize
  1934. then LimitWord := MaxTPCompatibleCollectionSize
  1935. else LimitWord := Limit;
  1936. S.Write(LimitWord, Sizeof(Word));
  1937. if Delta > MaxTPCompatibleCollectionSize
  1938. then DeltaWord := MaxTPCompatibleCollectionSize
  1939. else DeltaWord := Delta;
  1940. S.Write(DeltaWord, Sizeof(Word));
  1941. End
  1942. End
  1943. Else Begin
  1944. S.Write(Count, Sizeof(Count)); { Write count }
  1945. S.Write(Limit, Sizeof(Limit)); { Write limit }
  1946. S.Write(Delta, Sizeof(Delta)); { Write delta }
  1947. End;
  1948. ForEach(@DoPutItem); { Each item to stream }
  1949. END;
  1950. {--TCollection--------------------------------------------------------------}
  1951. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1952. {---------------------------------------------------------------------------}
  1953. PROCEDURE TCollection.PutItem (Var S: TStream; Item: Pointer);
  1954. BEGIN
  1955. S.Put(Item); { Put item on stream }
  1956. END;
  1957. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1958. { TSortedCollection OBJECT METHODS }
  1959. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1960. {--TSortedCollection--------------------------------------------------------}
  1961. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1962. {---------------------------------------------------------------------------}
  1963. CONSTRUCTOR TSortedCollection.Init (ALimit, ADelta: Sw_Integer);
  1964. BEGIN
  1965. Inherited Init(ALimit, ADelta); { Call ancestor }
  1966. Duplicates := False; { Clear flag }
  1967. END;
  1968. {--TSortedCollection--------------------------------------------------------}
  1969. { Load -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1970. {---------------------------------------------------------------------------}
  1971. CONSTRUCTOR TSortedCollection.Load (Var S: TStream);
  1972. BEGIN
  1973. Inherited Load(S); { Call ancestor }
  1974. S.Read(Duplicates, SizeOf(Duplicates)); { Read duplicate flag }
  1975. END;
  1976. {--TSortedCollection--------------------------------------------------------}
  1977. { KeyOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1978. {---------------------------------------------------------------------------}
  1979. FUNCTION TSortedCollection.KeyOf (Item: Pointer): Pointer;
  1980. BEGIN
  1981. KeyOf := Item; { Return item as key }
  1982. END;
  1983. {--TSortedCollection--------------------------------------------------------}
  1984. { IndexOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1985. {---------------------------------------------------------------------------}
  1986. FUNCTION TSortedCollection.IndexOf (Item: Pointer): Sw_Integer;
  1987. VAR I, J: Sw_Integer;
  1988. BEGIN
  1989. J := -1; { Preset result }
  1990. If Search(KeyOf(Item), I) Then Begin { Search for item }
  1991. If Duplicates Then { Duplicates allowed }
  1992. While (I < Count) AND (Item <> Items^[I]) Do
  1993. Inc(I); { Count duplicates }
  1994. If (I < Count) Then J := I; { Index result }
  1995. End;
  1996. IndexOf := J; { Return result }
  1997. END;
  1998. {--TSortedCollection--------------------------------------------------------}
  1999. { Compare -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2000. {---------------------------------------------------------------------------}
  2001. FUNCTION TSortedCollection.Compare (Key1, Key2: Pointer): Sw_Integer;
  2002. BEGIN
  2003. Abstract; { Abstract method }
  2004. Compare:=0;
  2005. END;
  2006. {--TSortedCollection--------------------------------------------------------}
  2007. { Search -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2008. {---------------------------------------------------------------------------}
  2009. FUNCTION TSortedCollection.Search (Key: Pointer; Var Index: Sw_Integer): Boolean;
  2010. VAR L, H, I, C: Sw_Integer;
  2011. BEGIN
  2012. Search := False; { Preset failure }
  2013. L := 0; { Start count }
  2014. H := Count - 1; { End count }
  2015. Index := 0;
  2016. if Count=0 then
  2017. exit;
  2018. While (L <= H) Do Begin
  2019. I := (L + H) SHR 1; { Mid point }
  2020. C := Compare(KeyOf(Items^[I]), Key); { Compare with key }
  2021. If (C < 0) Then L := I + 1 Else Begin { Item to left }
  2022. H := I - 1; { Item to right }
  2023. If C = 0 Then Begin { Item match found }
  2024. Search := True; { Result true }
  2025. If NOT Duplicates Then L := I; { Force kick out }
  2026. End;
  2027. End;
  2028. End;
  2029. Index := L; { Return result }
  2030. END;
  2031. {--TSortedCollection--------------------------------------------------------}
  2032. { Insert -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2033. {---------------------------------------------------------------------------}
  2034. PROCEDURE TSortedCollection.Insert (Item: Pointer);
  2035. VAR I: Sw_Integer;
  2036. BEGIN
  2037. If NOT Search(KeyOf(Item), I) OR Duplicates Then { Item valid }
  2038. AtInsert(I, Item); { Insert the item }
  2039. END;
  2040. {--TSortedCollection--------------------------------------------------------}
  2041. { Store -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2042. {---------------------------------------------------------------------------}
  2043. PROCEDURE TSortedCollection.Store (Var S: TStream);
  2044. BEGIN
  2045. TCollection.Store(S); { Call ancestor }
  2046. S.Write(Duplicates, SizeOf(Duplicates)); { Write duplicate flag }
  2047. END;
  2048. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2049. { TStringCollection OBJECT METHODS }
  2050. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2051. {--TStringCollection--------------------------------------------------------}
  2052. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2053. {---------------------------------------------------------------------------}
  2054. FUNCTION TStringCollection.GetItem (Var S: TStream): Pointer;
  2055. BEGIN
  2056. GetItem := S.ReadStr; { Get new item }
  2057. END;
  2058. {--TStringCollection--------------------------------------------------------}
  2059. { Compare -> Platforms DOS/DPMI/WIN/OS2 - Checked 21Aug97 LdB }
  2060. {---------------------------------------------------------------------------}
  2061. FUNCTION TStringCollection.Compare (Key1, Key2: Pointer): Sw_Integer;
  2062. VAR I, J: Sw_Integer; P1, P2: PString;
  2063. BEGIN
  2064. P1 := PString(Key1); { String 1 pointer }
  2065. P2 := PString(Key2); { String 2 pointer }
  2066. If (Length(P1^)<Length(P2^)) Then J := Length(P1^)
  2067. Else J := Length(P2^); { Shortest length }
  2068. I := 1; { First character }
  2069. While (I<J) AND (P1^[I]=P2^[I]) Do Inc(I); { Scan till fail }
  2070. If (I=J) Then Begin { Possible match }
  2071. { * REMARK * - Bug fix 21 August 1997 }
  2072. If (P1^[I]<P2^[I]) Then Compare := -1 Else { String1 < String2 }
  2073. If (P1^[I]>P2^[I]) Then Compare := 1 Else { String1 > String2 }
  2074. If (Length(P1^)>Length(P2^)) Then Compare := 1 { String1 > String2 }
  2075. Else If (Length(P1^)<Length(P2^)) Then { String1 < String2 }
  2076. Compare := -1 Else Compare := 0; { String1 = String2 }
  2077. { * REMARK END * - Leon de Boer }
  2078. End Else If (P1^[I]<P2^[I]) Then Compare := -1 { String1 < String2 }
  2079. Else Compare := 1; { String1 > String2 }
  2080. END;
  2081. {--TStringCollection--------------------------------------------------------}
  2082. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2083. {---------------------------------------------------------------------------}
  2084. PROCEDURE TStringCollection.FreeItem (Item: Pointer);
  2085. BEGIN
  2086. DisposeStr(Item); { Dispose item }
  2087. END;
  2088. {--TStringCollection--------------------------------------------------------}
  2089. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2090. {---------------------------------------------------------------------------}
  2091. PROCEDURE TStringCollection.PutItem (Var S: TStream; Item: Pointer);
  2092. BEGIN
  2093. S.WriteStr(Item); { Write string }
  2094. END;
  2095. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2096. { TStrCollection OBJECT METHODS }
  2097. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2098. {--TStrCollection-----------------------------------------------------------}
  2099. { Compare -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2100. {---------------------------------------------------------------------------}
  2101. FUNCTION TStrCollection.Compare (Key1, Key2: Pointer): Sw_Integer;
  2102. VAR I, J: Sw_Integer; P1, P2: PByteArray;
  2103. BEGIN
  2104. P1 := PByteArray(Key1); { PChar 1 pointer }
  2105. P2 := PByteArray(Key2); { PChar 2 pointer }
  2106. I := 0; { Preset no size }
  2107. If (P1<>Nil) Then While (P1^[I]<>0) Do Inc(I); { PChar 1 length }
  2108. J := 0; { Preset no size }
  2109. If (P2<>Nil) Then While (P2^[J]<>0) Do Inc(J); { PChar 2 length }
  2110. If (I < J) Then J := I; { Shortest length }
  2111. I := 0; { First character }
  2112. While (I<J) AND (P1^[I]=P2^[I]) Do Inc(I); { Scan till fail }
  2113. If (P1^[I]=P2^[I]) Then Compare := 0 Else { Strings matched }
  2114. If (P1^[I]<P2^[I]) Then Compare := -1 Else { String1 < String2 }
  2115. Compare := 1; { String1 > String2 }
  2116. END;
  2117. {--TStrCollection-----------------------------------------------------------}
  2118. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2119. {---------------------------------------------------------------------------}
  2120. FUNCTION TStrCollection.GetItem (Var S: TStream): Pointer;
  2121. BEGIN
  2122. GetItem := S.StrRead; { Get string item }
  2123. END;
  2124. {--TStrCollection-----------------------------------------------------------}
  2125. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2126. {---------------------------------------------------------------------------}
  2127. PROCEDURE TStrCollection.FreeItem (Item: Pointer);
  2128. VAR I: Sw_Integer; P: PByteArray;
  2129. BEGIN
  2130. If (Item<>Nil) Then Begin { Item is valid }
  2131. P := PByteArray(Item); { Create byte pointer }
  2132. I := 0; { Preset no size }
  2133. While (P^[I]<>0) Do Inc(I); { Find PChar end }
  2134. FreeMem(Item, I+1); { Release memory }
  2135. End;
  2136. END;
  2137. {--TStrCollection-----------------------------------------------------------}
  2138. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2139. {---------------------------------------------------------------------------}
  2140. PROCEDURE TStrCollection.PutItem (Var S: TStream; Item: Pointer);
  2141. BEGIN
  2142. S.StrWrite(Item); { Write the string }
  2143. END;
  2144. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2145. { TUnSortedStrCollection OBJECT METHODS }
  2146. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2147. {--TUnSortedCollection------------------------------------------------------}
  2148. { Insert -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2149. {---------------------------------------------------------------------------}
  2150. PROCEDURE TUnSortedStrCollection.Insert (Item: Pointer);
  2151. BEGIN
  2152. AtInsert(Count, Item); { Insert - NO sorting }
  2153. END;
  2154. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2155. { TResourceItem RECORD }
  2156. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2157. TYPE
  2158. TResourceItem = packed RECORD
  2159. Posn: LongInt; { Resource position }
  2160. Size: LongInt; { Resource size }
  2161. Key : String; { Resource key }
  2162. End;
  2163. PResourceItem = ^TResourceItem;
  2164. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2165. { TResourceCollection OBJECT METHODS }
  2166. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2167. {--TResourceCollection------------------------------------------------------}
  2168. { KeyOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2169. {---------------------------------------------------------------------------}
  2170. FUNCTION TResourceCollection.KeyOf (Item: Pointer): Pointer;
  2171. BEGIN
  2172. KeyOf := @PResourceItem(Item)^.Key; { Pointer to key }
  2173. END;
  2174. {--TResourceCollection------------------------------------------------------}
  2175. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2176. {---------------------------------------------------------------------------}
  2177. FUNCTION TResourceCollection.GetItem (Var S: TStream): Pointer;
  2178. VAR B: Byte; Pos: Longint; Size: Longint; Ts: String; P: PResourceItem;
  2179. BEGIN
  2180. S.Read(Pos, SizeOf(Pos)); { Read position }
  2181. S.Read(Size, SizeOf(Size)); { Read size }
  2182. S.Read(B, 1); { Read key length }
  2183. GetMem(P, B + (SizeOf(TResourceItem) -
  2184. SizeOf(Ts) + 1)); { Allocate min memory }
  2185. If (P<>Nil) Then Begin { If allocate works }
  2186. P^.Posn := Pos; { Xfer position }
  2187. P^.Size := Size; { Xfer size }
  2188. P^.Key[0] := Char(B); { Xfer string length }
  2189. S.Read(P^.Key[1], B); { Xfer string data }
  2190. End;
  2191. GetItem := P; { Return pointer }
  2192. END;
  2193. {--TResourceCollection------------------------------------------------------}
  2194. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2195. {---------------------------------------------------------------------------}
  2196. PROCEDURE TResourceCollection.FreeItem (Item: Pointer);
  2197. VAR Ts: String;
  2198. BEGIN
  2199. If (Item<>Nil) Then FreeMem(Item,
  2200. SizeOf(TResourceItem) - SizeOf(Ts) +
  2201. Length(PResourceItem(Item)^.Key) + 1); { Release memory }
  2202. END;
  2203. {--TResourceCollection------------------------------------------------------}
  2204. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2205. {---------------------------------------------------------------------------}
  2206. PROCEDURE TResourceCollection.PutItem (Var S: TStream; Item: Pointer);
  2207. VAR Ts: String;
  2208. BEGIN
  2209. If (Item<>Nil) Then S.Write(PResourceItem(Item)^,
  2210. SizeOf(TResourceItem) - SizeOf(Ts) +
  2211. Length(PResourceItem(Item)^.Key) + 1); { Write to stream }
  2212. END;
  2213. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2214. { PRIVATE RESOURCE MANAGER CONSTANTS }
  2215. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2216. CONST
  2217. RStreamMagic: LongInt = $52504246; { 'FBPR' }
  2218. RStreamBackLink: LongInt = $4C424246; { 'FBBL' }
  2219. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2220. { PRIVATE RESOURCE MANAGER TYPES }
  2221. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2222. TYPE
  2223. {$IFDEF NewExeFormat} { New EXE format }
  2224. TExeHeader = packed RECORD
  2225. eHdrSize: Word;
  2226. eMinAbove: Word;
  2227. eMaxAbove: Word;
  2228. eInitSS: Word;
  2229. eInitSP: Word;
  2230. eCheckSum: Word;
  2231. eInitPC: Word;
  2232. eInitCS: Word;
  2233. eRelocOfs: Word;
  2234. eOvlyNum: Word;
  2235. eRelocTab: Word;
  2236. eSpace: Array[1..30] of Byte;
  2237. eNewHeader: Word;
  2238. END;
  2239. {$ENDIF}
  2240. THeader = packed RECORD
  2241. Signature: Word;
  2242. Case Integer Of
  2243. 0: (
  2244. LastCount: Word;
  2245. PageCount: Word;
  2246. ReloCount: Word);
  2247. 1: (
  2248. InfoType: Word;
  2249. InfoSize: Longint);
  2250. End;
  2251. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2252. { TResourceFile OBJECT METHODS }
  2253. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2254. {--TResourceFile------------------------------------------------------------}
  2255. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2256. {---------------------------------------------------------------------------}
  2257. CONSTRUCTOR TResourceFile.Init(AStream: PStream);
  2258. VAR Found, Stop: Boolean; Header: THeader;
  2259. {$IFDEF NewExeFormat} ExeHeader: TExeHeader; {$ENDIF}
  2260. BEGIN
  2261. TObject.Init; { Initialize object }
  2262. Found := False; { Preset false }
  2263. If (AStream<>Nil) Then Begin
  2264. Stream := AStream; { Hold stream }
  2265. BasePos := Stream^.GetPos; { Get position }
  2266. Repeat
  2267. Stop := True; { Preset stop }
  2268. If (BasePos <= Stream^.GetSize-SizeOf(THeader))
  2269. Then Begin { Valid file header }
  2270. Stream^.Seek(BasePos); { Seek to position }
  2271. Stream^.Read(Header, SizeOf(THeader)); { Read header }
  2272. Case Header.Signature Of
  2273. {$IFDEF NewExeFormat} { New format file }
  2274. $5A4D: Begin
  2275. Stream^.Read(ExeHeader, SizeOf(TExeHeader));
  2276. BasePos := ExeHeader.eNewHeader; { Hold position }
  2277. Stop := False; { Clear stop flag }
  2278. End;
  2279. $454E: Begin
  2280. BasePos := Stream^.GetSize - 8; { Hold position }
  2281. Stop := False; { Clear stop flag }
  2282. End;
  2283. $4246: Begin
  2284. Stop := False; { Clear stop flag }
  2285. Case Header.Infotype Of
  2286. $5250: Begin { Found Resource }
  2287. Found := True; { Found flag is true }
  2288. Stop := True; { Set stop flag }
  2289. End;
  2290. $4C42: Dec(BasePos, Header.InfoSize-8);{ Found BackLink }
  2291. $4648: Dec(BasePos, SizeOf(THeader)*2);{ Found HelpFile }
  2292. Else Stop := True; { Set stop flag }
  2293. End;
  2294. End;
  2295. $424E: If Header.InfoType = $3230 { Found Debug Info }
  2296. Then Begin
  2297. Dec(BasePos, Header.InfoSize); { Adjust position }
  2298. Stop := False; { Clear stop flag }
  2299. End;
  2300. {$ELSE}
  2301. $5A4D: Begin
  2302. Inc(BasePos, LongInt(Header.PageCount)*512
  2303. - (-Header.LastCount AND 511)); { Calc position }
  2304. Stop := False; { Clear stop flag }
  2305. End;
  2306. $4246: If Header.InfoType = $5250 Then { Header was found }
  2307. Found := True Else Begin
  2308. Inc(BasePos, Header.InfoSize + 8); { Adjust position }
  2309. Stop := False; { Clear stop flag }
  2310. End;
  2311. {$ENDIF}
  2312. End;
  2313. End;
  2314. Until Stop; { Until flag is set }
  2315. End;
  2316. If Found Then Begin { Resource was found }
  2317. Stream^.Seek(BasePos + SizeOf(LongInt) * 2); { Seek to position }
  2318. Stream^.Read(IndexPos, SizeOf(LongInt)); { Read index position }
  2319. Stream^.Seek(BasePos + IndexPos); { Seek to resource }
  2320. Index.Load(Stream^); { Load resource }
  2321. End Else Begin
  2322. IndexPos := SizeOf(LongInt) * 3; { Set index position }
  2323. Index.Init(0, 8); { Set index }
  2324. End;
  2325. END;
  2326. {--TResourceFile------------------------------------------------------------}
  2327. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2328. {---------------------------------------------------------------------------}
  2329. DESTRUCTOR TResourceFile.Done;
  2330. BEGIN
  2331. Flush; { Flush the file }
  2332. Index.Done; { Dispose of index }
  2333. If (Stream<>Nil) Then Dispose(Stream, Done); { Dispose of stream }
  2334. END;
  2335. {--TResourceFile------------------------------------------------------------}
  2336. { Count -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2337. {---------------------------------------------------------------------------}
  2338. FUNCTION TResourceFile.Count: Sw_Integer;
  2339. BEGIN
  2340. Count := Index.Count; { Return index count }
  2341. END;
  2342. {--TResourceFile------------------------------------------------------------}
  2343. { KeyAt -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2344. {---------------------------------------------------------------------------}
  2345. FUNCTION TResourceFile.KeyAt (I: Sw_Integer): String;
  2346. BEGIN
  2347. KeyAt := PResourceItem(Index.At(I))^.Key; { Return key }
  2348. END;
  2349. {--TResourceFile------------------------------------------------------------}
  2350. { Get -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2351. {---------------------------------------------------------------------------}
  2352. FUNCTION TResourceFile.Get (Key: String): PObject;
  2353. VAR I: Sw_Integer;
  2354. BEGIN
  2355. If (Stream = Nil) OR (NOT Index.Search(@Key, I)) { No match on key }
  2356. Then Get := Nil Else Begin
  2357. Stream^.Seek(BasePos +
  2358. PResourceItem(Index.At(I))^.Posn); { Seek to position }
  2359. Get := Stream^.Get; { Get item }
  2360. End;
  2361. END;
  2362. {--TResourceFile------------------------------------------------------------}
  2363. { SwitchTo -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2364. {---------------------------------------------------------------------------}
  2365. FUNCTION TResourceFile.SwitchTo (AStream: PStream; Pack: Boolean): PStream;
  2366. VAR NewBasePos: LongInt;
  2367. PROCEDURE DoCopyResource (Item: PResourceItem);{$IFNDEF FPC}FAR;{$ENDIF}
  2368. BEGIN
  2369. Stream^.Seek(BasePos + Item^.Posn); { Move stream position }
  2370. Item^.Posn := AStream^.GetPos - NewBasePos; { Hold new position }
  2371. AStream^.CopyFrom(Stream^, Item^.Size); { Copy the item }
  2372. END;
  2373. BEGIN
  2374. SwitchTo := Stream; { Preset return }
  2375. If (AStream<>Nil) AND (Stream<>Nil) Then Begin { Both streams valid }
  2376. NewBasePos := AStream^.GetPos; { Get position }
  2377. If Pack Then Begin
  2378. AStream^.Seek(NewBasePos + SizeOf(LongInt)*3); { Seek to position }
  2379. Index.ForEach(@DoCopyResource); { Copy each resource }
  2380. IndexPos := AStream^.GetPos - NewBasePos; { Hold index position }
  2381. End Else Begin
  2382. Stream^.Seek(BasePos); { Seek to position }
  2383. AStream^.CopyFrom(Stream^, IndexPos); { Copy the resource }
  2384. End;
  2385. Stream := AStream; { Hold new stream }
  2386. BasePos := NewBasePos; { New base position }
  2387. Modified := True; { Set modified flag }
  2388. End;
  2389. END;
  2390. {--TResourceFile------------------------------------------------------------}
  2391. { Flush -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2392. {---------------------------------------------------------------------------}
  2393. PROCEDURE TResourceFile.Flush;
  2394. VAR ResSize: LongInt; LinkSize: LongInt;
  2395. BEGIN
  2396. If (Modified) AND (Stream<>Nil) Then Begin { We have modification }
  2397. Stream^.Seek(BasePos + IndexPos); { Seek to position }
  2398. Index.Store(Stream^); { Store the item }
  2399. ResSize := Stream^.GetPos - BasePos; { Hold position }
  2400. LinkSize := ResSize + SizeOf(LongInt) * 2; { Hold link size }
  2401. Stream^.Write(RStreamBackLink, SizeOf(LongInt)); { Write link back }
  2402. Stream^.Write(LinkSize, SizeOf(LongInt)); { Write link size }
  2403. Stream^.Seek(BasePos); { Move stream position }
  2404. Stream^.Write(RStreamMagic, SizeOf(LongInt)); { Write number }
  2405. Stream^.Write(ResSize, SizeOf(LongInt)); { Write record size }
  2406. Stream^.Write(IndexPos, SizeOf(LongInt)); { Write index position }
  2407. Stream^.Flush; { Flush the stream }
  2408. End;
  2409. Modified := False; { Clear modified flag }
  2410. END;
  2411. {--TResourceFile------------------------------------------------------------}
  2412. { Delete -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2413. {---------------------------------------------------------------------------}
  2414. PROCEDURE TResourceFile.Delete (Key: String);
  2415. VAR I: Sw_Integer;
  2416. BEGIN
  2417. If Index.Search(@Key, I) Then Begin { Search for key }
  2418. Index.Free(Index.At(I)); { Delete from index }
  2419. Modified := True; { Set modified flag }
  2420. End;
  2421. END;
  2422. {--TResourceFile------------------------------------------------------------}
  2423. { Put -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2424. {---------------------------------------------------------------------------}
  2425. PROCEDURE TResourceFile.Put (Item: PObject; Key: String);
  2426. VAR I: Sw_Integer; Ts: String; P: PResourceItem;
  2427. BEGIN
  2428. If (Stream=Nil) Then Exit; { Stream not valid }
  2429. If Index.Search(@Key, I) Then P := Index.At(I) { Search for item }
  2430. Else Begin
  2431. GetMem(P, Length(Key) + (SizeOf(TResourceItem) -
  2432. SizeOf(Ts) + 1)); { Allocate memory }
  2433. If (P<>Nil) Then Begin
  2434. P^.Key := Key; { Store key }
  2435. Index.AtInsert(I, P); { Insert item }
  2436. End;
  2437. End;
  2438. If (P<>Nil) Then Begin
  2439. P^.Posn := IndexPos; { Set index position }
  2440. Stream^.Seek(BasePos + IndexPos); { Seek file position }
  2441. Stream^.Put(Item); { Put item on stream }
  2442. IndexPos := Stream^.GetPos - BasePos; { Hold index position }
  2443. P^.Size := IndexPos - P^.Posn; { Calc size }
  2444. Modified := True; { Set modified flag }
  2445. End;
  2446. END;
  2447. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2448. { TStringList OBJECT METHODS }
  2449. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2450. {--TStringList--------------------------------------------------------------}
  2451. { Load -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2452. {---------------------------------------------------------------------------}
  2453. CONSTRUCTOR TStringList.Load (Var S: TStream);
  2454. VAR Size: Word;
  2455. BEGIN
  2456. Stream := @S; { Hold stream pointer }
  2457. S.Read(Size, SizeOf(Word)); { Read size }
  2458. BasePos := S.GetPos; { Hold position }
  2459. S.Seek(BasePos + Size); { Seek to position }
  2460. S.Read(IndexSize, SizeOf(Integer)); { Read index size }
  2461. GetMem(Index, IndexSize * SizeOf(TStrIndexRec)); { Allocate memory }
  2462. S.Read(Index^, IndexSize * SizeOf(TStrIndexRec)); { Read indexes }
  2463. END;
  2464. {--TStringList--------------------------------------------------------------}
  2465. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2466. {---------------------------------------------------------------------------}
  2467. DESTRUCTOR TStringList.Done;
  2468. BEGIN
  2469. FreeMem(Index, IndexSize * SizeOf(TStrIndexRec)); { Release memory }
  2470. END;
  2471. {--TStringList--------------------------------------------------------------}
  2472. { Get -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2473. {---------------------------------------------------------------------------}
  2474. FUNCTION TStringList.Get (Key: Sw_Word): String;
  2475. VAR I: Word; S: String;
  2476. BEGIN
  2477. S := ''; { Preset empty string }
  2478. If (IndexSize>0) Then Begin { We must have strings }
  2479. I := 0; { First entry }
  2480. While (I<IndexSize) AND (S='') Do Begin
  2481. If ((Key - Index^[I].Key)<Index^[I].Count) { Diff less than count }
  2482. Then ReadStr(S, Index^[I].Offset,
  2483. Key-Index^[I].Key); { Read the string }
  2484. Inc(I); { Next entry }
  2485. End;
  2486. End;
  2487. Get := S; { Return empty string }
  2488. END;
  2489. {***************************************************************************}
  2490. { TStringList PRIVATE METHODS }
  2491. {***************************************************************************}
  2492. {--TStringLis---------------------------------------------------------------}
  2493. { ReadStr -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2494. {---------------------------------------------------------------------------}
  2495. PROCEDURE TStringList.ReadStr (Var S: String; Offset, Skip: Longint);
  2496. BEGIN
  2497. Stream^.Seek(BasePos + Offset); { Seek to position }
  2498. Inc(Skip); { Adjust skip }
  2499. Repeat
  2500. Stream^.Read(S[0], 1); { Read string size }
  2501. Stream^.Read(S[1], Ord(S[0])); { Read string data }
  2502. Dec(Skip); { One string read }
  2503. Until (Skip = 0);
  2504. END;
  2505. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2506. { TStrListMaker OBJECT METHODS }
  2507. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2508. {--TStrListMaker------------------------------------------------------------}
  2509. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2510. {---------------------------------------------------------------------------}
  2511. CONSTRUCTOR TStrListMaker.Init (AStrSize, AIndexSize: Sw_Word);
  2512. BEGIN
  2513. Inherited Init; { Call ancestor }
  2514. StrSize := AStrSize; { Hold size }
  2515. IndexSize := AIndexSize; { Hold index size }
  2516. GetMem(Strings, AStrSize); { Allocate memory }
  2517. GetMem(Index, AIndexSize * SizeOf(TStrIndexRec)); { Allocate memory }
  2518. END;
  2519. {--TStrListMaker------------------------------------------------------------}
  2520. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2521. {---------------------------------------------------------------------------}
  2522. DESTRUCTOR TStrListMaker.Done;
  2523. BEGIN
  2524. FreeMem(Index, IndexSize * SizeOf(TStrIndexRec)); { Free index memory }
  2525. FreeMem(Strings, StrSize); { Free data memory }
  2526. END;
  2527. {--TStrListMaker------------------------------------------------------------}
  2528. { Put -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2529. {---------------------------------------------------------------------------}
  2530. PROCEDURE TStrListMaker.Put (Key: Sw_Word; S: String);
  2531. BEGIN
  2532. If (Cur.Count = 16) OR (Key <> Cur.Key + Cur.Count)
  2533. Then CloseCurrent; { Close current }
  2534. If (Cur.Count = 0) Then Begin
  2535. Cur.Key := Key; { Set key }
  2536. Cur.Offset := StrPos; { Set offset }
  2537. End;
  2538. Inc(Cur.Count); { Inc count }
  2539. Move(S, Strings^[StrPos], Length(S) + 1); { Move string data }
  2540. Inc(StrPos, Length(S) + 1); { Adjust position }
  2541. END;
  2542. {--TStrListMaker------------------------------------------------------------}
  2543. { Store -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2544. {---------------------------------------------------------------------------}
  2545. PROCEDURE TStrListMaker.Store (Var S: TStream);
  2546. BEGIN
  2547. CloseCurrent; { Close all current }
  2548. S.Write(StrPos, SizeOf(Word)); { Write position }
  2549. S.Write(Strings^, StrPos); { Write string data }
  2550. S.Write(IndexPos, SizeOf(Word)); { Write index position }
  2551. S.Write(Index^, IndexPos * SizeOf(TStrIndexRec)); { Write indexes }
  2552. END;
  2553. {***************************************************************************}
  2554. { TStrListMaker PRIVATE METHODS }
  2555. {***************************************************************************}
  2556. {--TStrListMaker------------------------------------------------------------}
  2557. { CloseCurrent -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2558. {---------------------------------------------------------------------------}
  2559. PROCEDURE TStrListMaker.CloseCurrent;
  2560. BEGIN
  2561. If (Cur.Count <> 0) Then Begin
  2562. Index^[IndexPos] := Cur; { Hold index position }
  2563. Inc(IndexPos); { Next index }
  2564. Cur.Count := 0; { Adjust count }
  2565. End;
  2566. END;
  2567. {***************************************************************************}
  2568. { INTERFACE ROUTINES }
  2569. {***************************************************************************}
  2570. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2571. { DYNAMIC STRING INTERFACE ROUTINES }
  2572. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2573. {---------------------------------------------------------------------------}
  2574. { NewStr -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  2575. {---------------------------------------------------------------------------}
  2576. FUNCTION NewStr (Const S: String): PString;
  2577. VAR P: PString;
  2578. BEGIN
  2579. If (S = '') Then P := Nil Else Begin { Return nil }
  2580. GetMem(P, Length(S) + 1); { Allocate memory }
  2581. If (P<>Nil) Then P^ := S; { Hold string }
  2582. End;
  2583. NewStr := P; { Return result }
  2584. END;
  2585. {---------------------------------------------------------------------------}
  2586. { DisposeStr -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  2587. {---------------------------------------------------------------------------}
  2588. PROCEDURE DisposeStr (P: PString);
  2589. BEGIN
  2590. If (P <> Nil) Then FreeMem(P, Length(P^) + 1); { Release memory }
  2591. END;
  2592. PROCEDURE SetStr(VAR p:pString; CONST s:STRING);
  2593. BEGIN
  2594. IF p<>NIL THEN
  2595. FreeMem(P, Length(P^) + 1);
  2596. GetMem(p,LENGTH(s)+1);
  2597. pSTRING(p)^ := s
  2598. END;
  2599. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2600. { STREAM INTERFACE ROUTINES }
  2601. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2602. {---------------------------------------------------------------------------}
  2603. { Abstract -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  2604. {---------------------------------------------------------------------------}
  2605. PROCEDURE Abstract;
  2606. BEGIN
  2607. RunError(211); { Abstract error }
  2608. END;
  2609. {---------------------------------------------------------------------------}
  2610. { RegisterObjects -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 02Sep97 LdB }
  2611. {---------------------------------------------------------------------------}
  2612. PROCEDURE RegisterObjects;
  2613. BEGIN
  2614. RegisterType(RCollection); { Register object }
  2615. RegisterType(RStringCollection); { Register object }
  2616. RegisterType(RStrCollection); { Register object }
  2617. END;
  2618. {---------------------------------------------------------------------------}
  2619. { RegisterType -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 02Sep97 LdB }
  2620. {---------------------------------------------------------------------------}
  2621. PROCEDURE RegisterType (Var S: TStreamRec);
  2622. VAR P: PStreamRec;
  2623. BEGIN
  2624. P := StreamTypes; { Current reg list }
  2625. While (P <> Nil) AND (P^.ObjType <> S.ObjType)
  2626. Do P := P^.Next; { Find end of chain }
  2627. If (P = Nil) AND (S.ObjType <> 0) Then Begin { Valid end found }
  2628. S.Next := StreamTypes; { Chain the list }
  2629. StreamTypes := @S; { We are now first }
  2630. End Else RegisterError; { Register the error }
  2631. END;
  2632. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2633. { GENERAL FUNCTION INTERFACE ROUTINES }
  2634. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2635. {---------------------------------------------------------------------------}
  2636. { LongMul -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 04Sep97 LdB }
  2637. {---------------------------------------------------------------------------}
  2638. FUNCTION LongMul (X, Y: Integer): LongInt;
  2639. BEGIN
  2640. LongMul:=Longint(X*Y);
  2641. END;
  2642. {---------------------------------------------------------------------------}
  2643. { LongDiv -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 04Sep97 LdB }
  2644. {---------------------------------------------------------------------------}
  2645. FUNCTION LongDiv (X: LongInt; Y: Integer): Integer;
  2646. BEGIN
  2647. LongDiv := Integer(X DIV Y);
  2648. END;
  2649. BEGIN
  2650. invalidhandle:=UnusedHandle;
  2651. END.