objects.pp 135 KB

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