objects.pp 136 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by the Free Pascal development team.
  5. Objects.pas clone for Free Pascal
  6. See the file COPYING.FPC, included in this distribution,
  7. for details about the copyright.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. **********************************************************************}
  12. {************[ SOURCE FILE OF FREE VISION ]****************}
  13. { }
  14. { System independent clone of objects.pas }
  15. { }
  16. { Interface Copyright (c) 1992 Borland International }
  17. { }
  18. { Parts Copyright (c) 1999-2000 by Florian Klaempfl }
  19. { [email protected] }
  20. { }
  21. { Parts Copyright (c) 1999-2000 by Frank ZAGO }
  22. { [email protected] }
  23. { }
  24. { Parts Copyright (c) 1999-2000 by MH Spiegel }
  25. { }
  26. { Parts Copyright (c) 1996, 1999-2000 by Leon de Boer }
  27. { [email protected] }
  28. { }
  29. { Free Vision project coordinator Balazs Scheidler }
  30. { [email protected] }
  31. { }
  32. UNIT Objects;
  33. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  34. INTERFACE
  35. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  36. {==== Select assembler ==============================================}
  37. {$IFDEF CPU86}
  38. {$ASMMODE ATT}
  39. {$ENDIF}
  40. {==== Compiler directives ===========================================}
  41. {$H-} { No ansistrings }
  42. {$E+} { Emulation is on }
  43. {$X+} { Extended syntax is ok }
  44. {$R-} { Disable range checking }
  45. {$ifndef Unix}
  46. {$S-} { Disable Stack Checking }
  47. {$endif}
  48. {$I-} { Disable IO Checking }
  49. {$Q-} { Disable Overflow Checking }
  50. {$V-} { Turn off strict VAR strings }
  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. { DYNAMIC STRING INTERFACE ROUTINES }
  510. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  511. {-NewStr-------------------------------------------------------------
  512. Allocates a dynamic string into memory. If S is nil, NewStr returns
  513. a nil pointer, otherwise NewStr allocates Length(S)+1 bytes of memory
  514. containing a copy of S, and returns a pointer to the string.
  515. 12Jun96 LdB
  516. ---------------------------------------------------------------------}
  517. FUNCTION NewStr (Const S: String): PString;
  518. {-DisposeStr---------------------------------------------------------
  519. Disposes of a PString allocated by the function NewStr.
  520. 12Jun96 LdB
  521. ---------------------------------------------------------------------}
  522. PROCEDURE DisposeStr (P: PString);
  523. PROCEDURE SetStr(VAR p:pString; CONST s:STRING);
  524. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  525. { STREAM INTERFACE ROUTINES }
  526. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  527. {-Abstract-----------------------------------------------------------
  528. Terminates program with a run-time error 211. When implementing
  529. an abstract object type, call Abstract in those virtual methods that
  530. must be overridden in descendant types. This ensures that any
  531. attempt to use instances of the abstract object type will fail.
  532. 12Jun96 LdB
  533. ---------------------------------------------------------------------}
  534. PROCEDURE Abstract;
  535. {-RegisterObjects----------------------------------------------------
  536. Registers the three standard objects TCollection, TStringCollection
  537. and TStrCollection.
  538. 02Sep97 LdB
  539. ---------------------------------------------------------------------}
  540. PROCEDURE RegisterObjects;
  541. {-RegisterType-------------------------------------------------------
  542. Registers the given object type with Free Vision's streams, creating
  543. a list of known objects. Streams can only store and return these known
  544. object types. Each registered object needs a unique stream registration
  545. record, of type TStreamRec.
  546. 02Sep97 LdB
  547. ---------------------------------------------------------------------}
  548. PROCEDURE RegisterType (Var S: TStreamRec);
  549. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  550. { GENERAL FUNCTION INTERFACE ROUTINES }
  551. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  552. {-LongMul------------------------------------------------------------
  553. Returns the long integer value of X * Y integer values.
  554. 04Sep97 LdB
  555. ---------------------------------------------------------------------}
  556. FUNCTION LongMul (X, Y: Integer): LongInt;
  557. {-LongDiv------------------------------------------------------------
  558. Returns the integer value of long integer X divided by integer Y.
  559. 04Sep97 LdB
  560. ---------------------------------------------------------------------}
  561. FUNCTION LongDiv (X: Longint; Y: Integer): Integer;
  562. {***************************************************************************}
  563. { PUBLIC INITIALIZED VARIABLES }
  564. {***************************************************************************}
  565. CONST
  566. {---------------------------------------------------------------------------}
  567. { INITIALIZED DOS/DPMI/WIN/OS2 PUBLIC VARIABLES }
  568. {---------------------------------------------------------------------------}
  569. StreamError: Pointer = Nil; { Stream error ptr }
  570. DefaultTPCompatible: Boolean = false;
  571. {---------------------------------------------------------------------------}
  572. { STREAM REGISTRATION RECORDS }
  573. {---------------------------------------------------------------------------}
  574. CONST
  575. RCollection: TStreamRec = (
  576. ObjType: 50;
  577. VmtLink: Ofs(TypeOf(TCollection)^);
  578. Load: @TCollection.Load;
  579. Store: @TCollection.Store;
  580. Next: Nil);
  581. RStringCollection: TStreamRec = (
  582. ObjType: 51;
  583. VmtLink: Ofs(TypeOf(TStringCollection)^);
  584. Load: @TStringCollection.Load;
  585. Store: @TStringCollection.Store;
  586. Next: Nil);
  587. RStrCollection: TStreamRec = (
  588. ObjType: 69;
  589. VmtLink: Ofs(TypeOf(TStrCollection)^);
  590. Load: @TStrCollection.Load;
  591. Store: @TStrCollection.Store;
  592. Next: Nil);
  593. RStringList: TStreamRec = (
  594. ObjType: 52;
  595. VmtLink: Ofs(TypeOf(TStringList)^);
  596. Load: @TStringList.Load;
  597. Store: Nil;
  598. Next: Nil);
  599. RStrListMaker: TStreamRec = (
  600. ObjType: 52;
  601. VmtLink: Ofs(TypeOf(TStrListMaker)^);
  602. Load: Nil;
  603. Store: @TStrListMaker.Store;
  604. Next: Nil);
  605. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  606. IMPLEMENTATION
  607. {<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>}
  608. Uses dos;
  609. {***************************************************************************}
  610. { HELPER ROUTINES FOR CALLING }
  611. {***************************************************************************}
  612. type
  613. FramePointer = pointer;
  614. PointerLocal = function(_EBP: FramePointer; Param1: pointer): pointer;
  615. PointerConstructor = function(VMT: pointer; Obj: pointer; Param1: pointer): pointer;
  616. PointerMethod = function(Obj: pointer; Param1: pointer): pointer;
  617. function PreviousFramePointer: FramePointer;assembler;
  618. {$undef FPC_PreviousFramePointer_Implemented}
  619. asm
  620. {$ifdef cpui386}
  621. {$define FPC_PreviousFramePointer_Implemented}
  622. movl (%ebp), %eax
  623. end ['EAX'];
  624. {$endif}
  625. {$ifdef cpum68k}
  626. {$define FPC_PreviousFramePointer_Implemented}
  627. move.l (a6),d0
  628. end ['D0'];
  629. {$endif}
  630. {$ifdef cpusparc}
  631. {$define FPC_PreviousFramePointer_Implemented}
  632. { we have first our own frame }
  633. ld [%fp],%i0
  634. ld [%i0],%i0
  635. end;
  636. {$endif}
  637. {$ifdef cpupowerpc}
  638. {$define FPC_PreviousFramePointer_Implemented}
  639. {$warning FIX ME !!!! }
  640. { getting the previous stack frame is quite hard for the standard powerpc calling conventions
  641. because we don't know the size of the locals, it seems that we need some compiler magic for this
  642. }
  643. end;
  644. {$endif}
  645. {$ifndef FPC_PreviousFramePointer_Implemented}
  646. {$error PreviousFramePointer function not implemented}
  647. {$endif not FPC_PreviousFramePointer_Implemented}
  648. function CallPointerConstructor(Ctor: pointer; Obj: pointer; VMT: pointer; Param1: pointer): pointer;
  649. {$undef FPC_CallPointerConstructor_Implemented}
  650. begin
  651. {$ifdef VER1_0}
  652. asm
  653. {$ifdef cpui386}
  654. {$define FPC_CallPointerConstructor_Implemented}
  655. movl Obj, %esi
  656. {$endif}
  657. {$ifdef cpum68k}
  658. {$define FPC_CallPointerConstructor_Implemented}
  659. move.l Obj, a5
  660. {$endif}
  661. end;
  662. {$else}
  663. { 1.1 does not esi to be loaded }
  664. {$define FPC_CallPointerConstructor_Implemented}
  665. {$endif}
  666. CallPointerConstructor := PointerConstructor(Ctor)(VMT, Obj, Param1)
  667. end;
  668. {$ifdef cpupowerpc}
  669. {$define FPC_CallPointerConstructor_Implemented}
  670. { for the powerpc, we don't need to load self, because we use standard calling conventions
  671. so self should be in a register anyways }
  672. {$endif}
  673. {$ifndef FPC_CallPointerConstructor_Implemented}
  674. {$error CallPointerConstructor function not implemented}
  675. {$endif not FPC_CallPointerConstructor_Implemented}
  676. function CallPointerMethod(Method: pointer; Obj: pointer; Param1: pointer): pointer;
  677. {$undef FPC_CallPointerMethod_Implemented}
  678. begin
  679. {$ifdef VER1_0}
  680. asm
  681. {$ifdef cpui386}
  682. {$define FPC_CallPointerMethod_Implemented}
  683. movl Obj, %esi
  684. {$endif}
  685. {$ifdef cpum68k}
  686. {$define FPC_CallPointerMethod_Implemented}
  687. move.l Obj, a5
  688. {$endif}
  689. {$ifdef cpupowerpc}
  690. {$define FPC_CallPointerMethod_Implemented}
  691. { for the powerpc, we don't need to load self, because we use standard calling conventions
  692. so self should be in a register anyways }
  693. {$endif}
  694. end;
  695. {$else}
  696. { 1.1 does not esi to be loaded }
  697. {$define FPC_CallPointerMethod_Implemented}
  698. {$endif}
  699. CallPointerMethod := PointerMethod(Method)(Obj, Param1)
  700. end;
  701. {$ifndef FPC_CallPointerMethod_Implemented}
  702. {$error CallPointerMethod function not implemented}
  703. {$endif not FPC_CallPointerMethod_Implemented}
  704. function CallPointerLocal(Func: pointer; Frame: FramePointer; Param1: pointer): pointer;
  705. begin
  706. CallPointerLocal := PointerLocal(Func)(Frame, Param1)
  707. end;
  708. {***************************************************************************}
  709. { PRIVATE INITIALIZED VARIABLES }
  710. {***************************************************************************}
  711. {---------------------------------------------------------------------------}
  712. { INITIALIZED DOS/DPMI/WIN/OS2 PRIVATE VARIABLES }
  713. {---------------------------------------------------------------------------}
  714. CONST
  715. StreamTypes: PStreamRec = Nil; { Stream types reg }
  716. {***************************************************************************}
  717. { PRIVATE INTERNAL ROUTINES }
  718. {***************************************************************************}
  719. {---------------------------------------------------------------------------}
  720. { RegisterError -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  721. {---------------------------------------------------------------------------}
  722. PROCEDURE RegisterError;
  723. BEGIN
  724. RunError(212); { Register error }
  725. END;
  726. {***************************************************************************}
  727. { OBJECT METHODS }
  728. {***************************************************************************}
  729. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  730. { TRect OBJECT METHODS }
  731. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  732. PROCEDURE CheckEmpty (Var Rect: TRect);
  733. BEGIN
  734. With Rect Do Begin
  735. If (A.X >= B.X) OR (A.Y >= B.Y) Then Begin { Zero or reversed }
  736. A.X := 0; { Clear a.x }
  737. A.Y := 0; { Clear a.y }
  738. B.X := 0; { Clear b.x }
  739. B.Y := 0; { Clear b.y }
  740. End;
  741. End;
  742. END;
  743. {--TRect--------------------------------------------------------------------}
  744. { Empty -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  745. {---------------------------------------------------------------------------}
  746. FUNCTION TRect.Empty: Boolean;
  747. BEGIN
  748. Empty := (A.X >= B.X) OR (A.Y >= B.Y); { Empty result }
  749. END;
  750. {--TRect--------------------------------------------------------------------}
  751. { Equals -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  752. {---------------------------------------------------------------------------}
  753. FUNCTION TRect.Equals (R: TRect): Boolean;
  754. BEGIN
  755. Equals := (A.X = R.A.X) AND (A.Y = R.A.Y) AND
  756. (B.X = R.B.X) AND (B.Y = R.B.Y); { Equals result }
  757. END;
  758. {--TRect--------------------------------------------------------------------}
  759. { Contains -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  760. {---------------------------------------------------------------------------}
  761. FUNCTION TRect.Contains (P: TPoint): Boolean;
  762. BEGIN
  763. Contains := (P.X >= A.X) AND (P.X < B.X) AND
  764. (P.Y >= A.Y) AND (P.Y < B.Y); { Contains result }
  765. END;
  766. {--TRect--------------------------------------------------------------------}
  767. { Copy -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  768. {---------------------------------------------------------------------------}
  769. PROCEDURE TRect.Copy (R: TRect);
  770. BEGIN
  771. A := R.A; { Copy point a }
  772. B := R.B; { Copy point b }
  773. END;
  774. {--TRect--------------------------------------------------------------------}
  775. { Union -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  776. {---------------------------------------------------------------------------}
  777. PROCEDURE TRect.Union (R: TRect);
  778. BEGIN
  779. If (R.A.X < A.X) Then A.X := R.A.X; { Take if smaller }
  780. If (R.A.Y < A.Y) Then A.Y := R.A.Y; { Take if smaller }
  781. If (R.B.X > B.X) Then B.X := R.B.X; { Take if larger }
  782. If (R.B.Y > B.Y) Then B.Y := R.B.Y; { Take if larger }
  783. END;
  784. {--TRect--------------------------------------------------------------------}
  785. { Intersect -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  786. {---------------------------------------------------------------------------}
  787. PROCEDURE TRect.Intersect (R: TRect);
  788. BEGIN
  789. If (R.A.X > A.X) Then A.X := R.A.X; { Take if larger }
  790. If (R.A.Y > A.Y) Then A.Y := R.A.Y; { Take if larger }
  791. If (R.B.X < B.X) Then B.X := R.B.X; { Take if smaller }
  792. If (R.B.Y < B.Y) Then B.Y := R.B.Y; { Take if smaller }
  793. CheckEmpty(Self); { Check if empty }
  794. END;
  795. {--TRect--------------------------------------------------------------------}
  796. { Move -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  797. {---------------------------------------------------------------------------}
  798. PROCEDURE TRect.Move (ADX, ADY: Sw_Integer);
  799. BEGIN
  800. Inc(A.X, ADX); { Adjust A.X }
  801. Inc(A.Y, ADY); { Adjust A.Y }
  802. Inc(B.X, ADX); { Adjust B.X }
  803. Inc(B.Y, ADY); { Adjust B.Y }
  804. END;
  805. {--TRect--------------------------------------------------------------------}
  806. { Grow -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  807. {---------------------------------------------------------------------------}
  808. PROCEDURE TRect.Grow (ADX, ADY: Sw_Integer);
  809. BEGIN
  810. Dec(A.X, ADX); { Adjust A.X }
  811. Dec(A.Y, ADY); { Adjust A.Y }
  812. Inc(B.X, ADX); { Adjust B.X }
  813. Inc(B.Y, ADY); { Adjust B.Y }
  814. CheckEmpty(Self); { Check if empty }
  815. END;
  816. {--TRect--------------------------------------------------------------------}
  817. { Assign -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  818. {---------------------------------------------------------------------------}
  819. PROCEDURE TRect.Assign (XA, YA, XB, YB: Sw_Integer);
  820. BEGIN
  821. A.X := XA; { Hold A.X value }
  822. A.Y := YA; { Hold A.Y value }
  823. B.X := XB; { Hold B.X value }
  824. B.Y := YB; { Hold B.Y value }
  825. END;
  826. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  827. { TObject OBJECT METHODS }
  828. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  829. TYPE
  830. DummyObject = OBJECT (TObject) { Internal object }
  831. Data: RECORD END; { Helps size VMT link }
  832. END;
  833. { ******************************* REMARK ****************************** }
  834. { I Prefer this code because it self sizes VMT link rather than using a }
  835. { fixed record structure thus it should work on all compilers without a }
  836. { specific record to match each compiler. }
  837. { ****************************** END REMARK *** Leon de Boer, 10May96 * }
  838. {--TObject------------------------------------------------------------------}
  839. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  840. {---------------------------------------------------------------------------}
  841. CONSTRUCTOR TObject.Init;
  842. VAR LinkSize: LongInt; Dummy: DummyObject;
  843. BEGIN
  844. LinkSize := LongInt(@Dummy.Data)-LongInt(@Dummy); { Calc VMT link size }
  845. FillChar(Pointer(LongInt(@Self)+LinkSize)^,
  846. SizeOf(Self)-LinkSize, #0); { Clear data fields }
  847. END;
  848. {--TObject------------------------------------------------------------------}
  849. { Free -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  850. {---------------------------------------------------------------------------}
  851. PROCEDURE TObject.Free;
  852. BEGIN
  853. Dispose(PObject(@Self), Done); { Dispose of self }
  854. END;
  855. {--TObject------------------------------------------------------------------}
  856. { Is_Object -> Platforms DOS/DPMI/WIN/OS2 - Checked 5Mar00 DM }
  857. {---------------------------------------------------------------------------}
  858. FUNCTION TObject.Is_Object(P:Pointer):Boolean;
  859. TYPE
  860. PVMT=^VMT;
  861. VMT=RECORD
  862. Size,NegSize:Longint;
  863. ParentLink:PVMT;
  864. END;
  865. VAR SP:^PVMT; Q:PVMT;
  866. BEGIN
  867. SP:=@SELF;
  868. Q:=SP^;
  869. Is_Object:=False;
  870. While Q<>Nil Do Begin
  871. IF Q=P THEN Begin
  872. Is_Object:=True;
  873. Break;
  874. End;
  875. Q:=Q^.Parentlink;
  876. End;
  877. END;
  878. {--TObject------------------------------------------------------------------}
  879. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  880. {---------------------------------------------------------------------------}
  881. DESTRUCTOR TObject.Done;
  882. BEGIN { Abstract method }
  883. END;
  884. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  885. { TStream OBJECT METHODS }
  886. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  887. CONSTRUCTOR TStream.Init;
  888. BEGIN
  889. Status := StOK;
  890. ErrorInfo := 0;
  891. StreamSize := 0;
  892. Position := 0;
  893. TPCompatible := DefaultTPCompatible;
  894. END;
  895. {--TStream------------------------------------------------------------------}
  896. { Get -> Platforms DOS/DPMI/WIN/OS2 - Checked 02Sep97 LdB }
  897. {---------------------------------------------------------------------------}
  898. FUNCTION TStream.Get: PObject;
  899. VAR ObjType: Sw_Word; P: PStreamRec; ObjTypeWord: Word;
  900. BEGIN
  901. If TPCompatible Then Begin
  902. { Read 16-bit word for TP compatibility. }
  903. Read(ObjTypeWord, SizeOf(ObjTypeWord));
  904. ObjType := ObjTypeWord
  905. End
  906. else
  907. Read(ObjType, SizeOf(ObjType)); { Read object type }
  908. If (ObjType<>0) Then Begin { Object registered }
  909. P := StreamTypes; { Current reg list }
  910. While (P <> Nil) AND (P^.ObjType <> ObjType) { Find object type OR }
  911. Do P := P^.Next; { Find end of chain }
  912. If (P=Nil) Then Begin { Not registered }
  913. Error(stGetError, ObjType); { Obj not registered }
  914. Get := Nil; { Return nil pointer }
  915. End Else
  916. Get :=PObject(
  917. CallPointerConstructor(P^.Load,Nil,P^.VMTLink, @Self)) { Call constructor }
  918. End Else Get := Nil; { Return nil pointer }
  919. END;
  920. {--TStream------------------------------------------------------------------}
  921. { StrRead -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  922. {---------------------------------------------------------------------------}
  923. FUNCTION TStream.StrRead: PChar;
  924. VAR L: Word; P: PChar;
  925. BEGIN
  926. Read(L, SizeOf(L)); { Read length }
  927. If (L = 0) Then StrRead := Nil Else Begin { Check for empty }
  928. GetMem(P, L + 1); { Allocate memory }
  929. If (P <> Nil) Then Begin { Check allocate okay }
  930. Read(P[0], L); { Read the data }
  931. P[L] := #0; { Terminate with #0 }
  932. End;
  933. StrRead := P; { Return PChar }
  934. End;
  935. END;
  936. {--TStream------------------------------------------------------------------}
  937. { ReadStr -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  938. {---------------------------------------------------------------------------}
  939. FUNCTION TStream.ReadStr: PString;
  940. VAR L: Byte; P: PString;
  941. BEGIN
  942. Read(L, 1); { Read string length }
  943. If (L > 0) Then Begin
  944. GetMem(P, L + 1); { Allocate memory }
  945. If (P <> Nil) Then Begin { Check allocate okay }
  946. P^[0] := Char(L); { Hold length }
  947. Read(P^[1], L); { Read string data }
  948. End;
  949. ReadStr := P; { Return string ptr }
  950. End Else ReadStr := Nil;
  951. END;
  952. {--TStream------------------------------------------------------------------}
  953. { GetPos -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  954. {---------------------------------------------------------------------------}
  955. FUNCTION TStream.GetPos: LongInt;
  956. BEGIN
  957. If (Status=stOk) Then GetPos := Position { Return position }
  958. Else GetPos := -1; { Stream in error }
  959. END;
  960. {--TStream------------------------------------------------------------------}
  961. { GetSize -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  962. {---------------------------------------------------------------------------}
  963. FUNCTION TStream.GetSize: LongInt;
  964. BEGIN
  965. If (Status=stOk) Then GetSize := StreamSize { Return stream size }
  966. Else GetSize := -1; { Stream in error }
  967. END;
  968. {--TStream------------------------------------------------------------------}
  969. { Close -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  970. {---------------------------------------------------------------------------}
  971. PROCEDURE TStream.Close;
  972. BEGIN { Abstract method }
  973. END;
  974. {--TStream------------------------------------------------------------------}
  975. { Reset -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  976. {---------------------------------------------------------------------------}
  977. PROCEDURE TStream.Reset;
  978. BEGIN
  979. Status := stOK; { Clear status }
  980. ErrorInfo := 0; { Clear error info }
  981. END;
  982. {--TStream------------------------------------------------------------------}
  983. { Flush -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  984. {---------------------------------------------------------------------------}
  985. PROCEDURE TStream.Flush;
  986. BEGIN { Abstract method }
  987. END;
  988. {--TStream------------------------------------------------------------------}
  989. { Truncate -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  990. {---------------------------------------------------------------------------}
  991. PROCEDURE TStream.Truncate;
  992. BEGIN
  993. Abstract; { Abstract error }
  994. END;
  995. {--TStream------------------------------------------------------------------}
  996. { Put -> Platforms DOS/DPMI/WIN/OS2 - Checked 02Sep97 LdB }
  997. {---------------------------------------------------------------------------}
  998. PROCEDURE TStream.Put (P: PObject);
  999. VAR ObjType: Sw_Word; Link: pointer; Q: PStreamRec; VmtPtr: ^pointer;
  1000. ObjTypeWord: Word;
  1001. BEGIN
  1002. VmtPtr := Pointer(P); { Xfer object to ptr }
  1003. if assigned(vmtptr) then
  1004. Link := VmtPtr^ { VMT link }
  1005. else
  1006. Link:=nil;
  1007. ObjType := 0; { Set objtype to zero }
  1008. If (P<>Nil) AND (Link<>Nil) Then Begin { We have a VMT link }
  1009. Q := StreamTypes; { Current reg list }
  1010. While (Q <> Nil) AND (Q^.VMTLink <> Link) { Find link match OR }
  1011. Do Q := Q^.Next; { Find end of chain }
  1012. If (Q=Nil) Then Begin { End of chain found }
  1013. Error(stPutError, 0); { Not registered error }
  1014. Exit; { Now exit }
  1015. End Else ObjType := Q^.ObjType; { Update object type }
  1016. End;
  1017. If TPCompatible Then Begin
  1018. ObjTypeWord := word(ObjType);
  1019. Write(ObjTypeWord, SizeOf(ObjTypeWord))
  1020. end
  1021. else
  1022. Write(ObjType, SizeOf(ObjType)); { Write object type }
  1023. If (ObjType<>0) Then { Registered object }
  1024. CallPointerMethod(Q^.Store, P, @Self);
  1025. END;
  1026. {--TStream------------------------------------------------------------------}
  1027. { Seek -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1028. {---------------------------------------------------------------------------}
  1029. PROCEDURE TStream.Seek (Pos: LongInt);
  1030. BEGIN
  1031. If (Status = stOk) Then Begin { Check status }
  1032. If (Pos < 0) Then Pos := 0; { Remove negatives }
  1033. If (Pos <= StreamSize) Then Position := Pos { If valid set pos }
  1034. Else Error(stSeekError, Pos); { Position error }
  1035. End;
  1036. END;
  1037. {--TStream------------------------------------------------------------------}
  1038. { StrWrite -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1039. {---------------------------------------------------------------------------}
  1040. PROCEDURE TStream.StrWrite (P: PChar);
  1041. VAR L: Word; Q: PByteArray;
  1042. BEGIN
  1043. L := 0; { Preset zero size }
  1044. Q := PByteArray(P); { Transfer type }
  1045. If (Q <> Nil) Then While (Q^[L] <> 0) Do Inc(L); { PChar length }
  1046. Write(L, SizeOf(L)); { Store length }
  1047. If (P <> Nil) Then Write(P[0], L); { Write data }
  1048. END;
  1049. {--TStream------------------------------------------------------------------}
  1050. { WriteStr -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1051. {---------------------------------------------------------------------------}
  1052. PROCEDURE TStream.WriteStr (P: PString);
  1053. CONST Empty: String[1] = '';
  1054. BEGIN
  1055. If (P <> Nil) Then Write(P^, Length(P^) + 1) { Write string }
  1056. Else Write(Empty, 1); { Write empty string }
  1057. END;
  1058. {--TStream------------------------------------------------------------------}
  1059. { Open -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1060. {---------------------------------------------------------------------------}
  1061. PROCEDURE TStream.Open (OpenMode: Word);
  1062. BEGIN { Abstract method }
  1063. END;
  1064. {--TStream------------------------------------------------------------------}
  1065. { Error -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1066. {---------------------------------------------------------------------------}
  1067. PROCEDURE TStream.Error (Code, Info: Integer);
  1068. TYPE TErrorProc = Procedure(Var S: TStream);
  1069. BEGIN
  1070. Status := Code; { Hold error code }
  1071. ErrorInfo := Info; { Hold error info }
  1072. If (StreamError <> Nil) Then
  1073. TErrorProc(StreamError)(Self); { Call error ptr }
  1074. END;
  1075. {--TStream------------------------------------------------------------------}
  1076. { Read -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1077. {---------------------------------------------------------------------------}
  1078. PROCEDURE TStream.Read (Var Buf; Count: Longint);
  1079. BEGIN
  1080. Abstract; { Abstract error }
  1081. END;
  1082. {--TStream------------------------------------------------------------------}
  1083. { Write -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1084. {---------------------------------------------------------------------------}
  1085. PROCEDURE TStream.Write (Var Buf; Count: Longint);
  1086. BEGIN
  1087. Abstract; { Abstract error }
  1088. END;
  1089. {--TStream------------------------------------------------------------------}
  1090. { CopyFrom -> Platforms DOS/DPMI/WIN/OS2 - Checked 10May96 LdB }
  1091. {---------------------------------------------------------------------------}
  1092. PROCEDURE TStream.CopyFrom (Var S: TStream; Count: Longint);
  1093. VAR W: Word; Buffer: Array[0..1023] of Byte;
  1094. BEGIN
  1095. While (Count > 0) Do Begin
  1096. If (Count > SizeOf(Buffer)) Then { To much data }
  1097. W := SizeOf(Buffer) Else W := Count; { Size to transfer }
  1098. S.Read(Buffer, W); { Read from stream }
  1099. Write(Buffer, W); { Write to stream }
  1100. Dec(Count, W); { Dec write count }
  1101. End;
  1102. END;
  1103. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1104. { TDosStream OBJECT METHODS }
  1105. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1106. {$IFOPT I+}
  1107. {$DEFINE IO_CHECK_ON}
  1108. {$I-}
  1109. {$ENDIF}
  1110. {--TDosStream---------------------------------------------------------------}
  1111. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1112. {---------------------------------------------------------------------------}
  1113. CONSTRUCTOR TDosStream.Init (FileName: FNameStr; Mode: Word);
  1114. VAR OldFileMode : Byte;
  1115. DosStreamError : Word;
  1116. BEGIN
  1117. Inherited Init; { Call ancestor }
  1118. FileName := FileName+#0; { Make asciiz }
  1119. Move(FileName[1], FName, Length(FileName)); { Create asciiz name }
  1120. Handle := InvalidHandle;
  1121. Assign(FileInfo,FileName);
  1122. { Handle the mode }
  1123. if Mode =stCreate then
  1124. Begin
  1125. Rewrite(FileInfo,1);
  1126. end
  1127. else
  1128. Begin
  1129. OldFileMode := FileMode;
  1130. FileMode := Mode and 3;
  1131. System.Reset(FileInfo,1);
  1132. FileMode := OldFileMode;
  1133. { To use the correct mode we must reclose the file
  1134. and open it again
  1135. }
  1136. end;
  1137. Handle := FileRec(FileInfo).Handle; { Set handle value }
  1138. DosStreamError := IOResult;
  1139. If DosStreamError = 0 then
  1140. Begin
  1141. StreamSize := System.FileSize(FileInfo);
  1142. end;
  1143. If DosStreamError = 0 then
  1144. DosStreamError := IOResult;
  1145. If (DosStreamError <> 0) Then
  1146. Error(stInitError, DosStreamError) { Call stream error }
  1147. else
  1148. Status := StOK;
  1149. END;
  1150. {--TDosStream---------------------------------------------------------------}
  1151. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1152. {---------------------------------------------------------------------------}
  1153. DESTRUCTOR TDosStream.Done;
  1154. var
  1155. DosStreamError : Word;
  1156. BEGIN
  1157. if Handle <> InvalidHandle then
  1158. Begin
  1159. System.Close(FileInfo);
  1160. DosStreamError := IOResult;
  1161. If DosStreamError = 0 then
  1162. Status := stOk
  1163. else
  1164. Error(stError, DosStreamError);
  1165. end;
  1166. Position := 0; { Zero the position }
  1167. Handle := InvalidHandle;
  1168. Inherited Done; { Call ancestor }
  1169. END;
  1170. {--TDosStream---------------------------------------------------------------}
  1171. { Close -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1172. {---------------------------------------------------------------------------}
  1173. PROCEDURE TDosStream.Close;
  1174. var
  1175. DosStreamError : Word;
  1176. BEGIN
  1177. if Handle <> InvalidHandle then { Is file closed ? }
  1178. Begin
  1179. System.Close(FileInfo); { Close file }
  1180. DosStreamError := IOResult; { Check for error }
  1181. If DosStreamError = 0 then
  1182. Status := stOk
  1183. else
  1184. Error(stError, DosStreamError); { Call error routine }
  1185. end;
  1186. Position := 0; { Zero the position }
  1187. Handle := InvalidHandle; { Handle invalid }
  1188. END;
  1189. {--TDosStream---------------------------------------------------------------}
  1190. { Truncate -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1191. {---------------------------------------------------------------------------}
  1192. PROCEDURE TDosStream.Truncate;
  1193. var
  1194. DosStreamError : Word;
  1195. BEGIN
  1196. If Status = stOk then
  1197. Begin
  1198. System.Truncate(FileInfo);
  1199. DosStreamError := IOResult;
  1200. If DosStreamError = 0 then
  1201. { Status is already = stOK }
  1202. StreamSize := Position
  1203. else
  1204. Error(stError, DosStreamError);
  1205. end;
  1206. END;
  1207. {--TDosStream---------------------------------------------------------------}
  1208. { Seek -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1209. {---------------------------------------------------------------------------}
  1210. PROCEDURE TDosStream.Seek (Pos: Longint);
  1211. var
  1212. DosStreamError : Word;
  1213. BEGIN
  1214. If (Status=stOk) Then
  1215. Begin { Check status okay }
  1216. If (Pos < 0) Then
  1217. Pos := 0; { Negatives removed }
  1218. System.Seek(FileInfo, Pos);
  1219. DosStreamError := IOResult;
  1220. if DosStreamError <> 0 then
  1221. Error(stSeekError, DosStreamError){ Specific seek error }
  1222. Else Position := Pos; { Adjust position }
  1223. { Status is already = stOK }
  1224. End;
  1225. END;
  1226. {--TDosStream---------------------------------------------------------------}
  1227. { Open -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1228. {---------------------------------------------------------------------------}
  1229. PROCEDURE TDosStream.Open (OpenMode: Word);
  1230. VAR OldFileMode : Byte;
  1231. DosStreamError : Word;
  1232. BEGIN
  1233. If (Status=stOk) Then
  1234. Begin { Check status okay }
  1235. If (Handle = InvalidHandle) Then
  1236. Begin { File not open }
  1237. Assign(FileInfo,FName);
  1238. { Handle the mode }
  1239. if OpenMode =stCreate then
  1240. Begin
  1241. System.Rewrite(FileInfo,1);
  1242. end
  1243. else
  1244. Begin
  1245. OldFileMode := FileMode;
  1246. FileMode := OpenMode and 3;
  1247. System.Reset(FileInfo,1);
  1248. FileMode := OldFileMode;
  1249. { To use the correct mode we must reclose the file
  1250. and open it again
  1251. }
  1252. end;
  1253. Handle := FileRec(FileInfo).Handle; { Set handle value }
  1254. DosStreamError := IOResult;
  1255. If DosStreamError = 0 then
  1256. StreamSize := System.FileSize(FileInfo);
  1257. If DosStreamError = 0 then
  1258. DosStreamError := IOResult;
  1259. If (DosStreamError <> 0) Then
  1260. Error(stOpenError, DosStreamError) { Call stream error }
  1261. else
  1262. Status := StOK;
  1263. Position := 0;
  1264. end
  1265. Else
  1266. Error(stOpenError, 104); { File already open }
  1267. End;
  1268. END;
  1269. {--TDosStream---------------------------------------------------------------}
  1270. { Read -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1271. {---------------------------------------------------------------------------}
  1272. PROCEDURE TDosStream.Read (Var Buf; Count: Longint);
  1273. VAR BytesMoved: Longint;
  1274. DosStreamError : Word;
  1275. BEGIN
  1276. If Status = StOK then
  1277. Begin
  1278. If (Position + Count > StreamSize) Then { Insufficient data }
  1279. Error(stReadError, 0); { Read beyond end!!! }
  1280. If (Handle = InvalidHandle) Then
  1281. Error(stReadError, 103); { File not open }
  1282. BlockRead(FileInfo, Buf, Count, BytesMoved); { Read from file }
  1283. DosStreamError := IOResult;
  1284. If ((DosStreamError<>0) OR (BytesMoved<>Count)) Then
  1285. Begin { Error was detected }
  1286. BytesMoved := 0; { Clear bytes moved }
  1287. If (DosStreamError <> 0) Then
  1288. Error(stReadError, DosStreamError) { Specific read error }
  1289. Else
  1290. Error(stReadError, 0); { Non specific error }
  1291. End;
  1292. Inc(Position, BytesMoved); { Adjust position }
  1293. End;
  1294. { If there was already an error, or an error was just
  1295. generated, fill the vuffer with NULL
  1296. }
  1297. If Status <> StOK then
  1298. FillChar(Buf, Count, #0); { Error clear buffer }
  1299. END;
  1300. {--TDosStream---------------------------------------------------------------}
  1301. { Write -> Platforms DOS/DPMI/WIN/OS2 - Checked 16May96 LdB }
  1302. {---------------------------------------------------------------------------}
  1303. PROCEDURE TDosStream.Write (Var Buf; Count: Longint);
  1304. VAR BytesMoved: Longint;
  1305. DosStreamError : Word;
  1306. BEGIN
  1307. { If status is not OK, simply exit }
  1308. if Status <> StOK then
  1309. exit;
  1310. If (Handle = InvalidHandle) Then
  1311. Error(stWriteError, 103); { File not open }
  1312. BlockWrite(FileInfo, Buf, Count, BytesMoved); { Write to file }
  1313. DosStreamError := IOResult;
  1314. If ((DosStreamError<>0) OR (BytesMoved<>Count)) Then
  1315. Begin { Error was detected }
  1316. BytesMoved := 0; { Clear bytes moved }
  1317. If (DosStreamError<>0) Then
  1318. Error(stWriteError, DOSStreamError) { Specific write error }
  1319. Else
  1320. Error(stWriteError, 0); { Non specific error }
  1321. End;
  1322. Inc(Position, BytesMoved); { Adjust position }
  1323. If (Position > StreamSize) Then { File expanded }
  1324. StreamSize := Position; { Adjust stream size }
  1325. END;
  1326. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1327. { TBufStream OBJECT METHODS }
  1328. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1329. {--TBufStream---------------------------------------------------------------}
  1330. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1331. {---------------------------------------------------------------------------}
  1332. CONSTRUCTOR TBufStream.Init (FileName: FNameStr; Mode, Size: Word);
  1333. BEGIN
  1334. Inherited Init(FileName, Mode); { Call ancestor }
  1335. BufSize := Size; { Hold buffer size }
  1336. If (Size<>0) Then GetMem(Buffer, Size); { Allocate buffer }
  1337. If (Buffer=Nil) Then Error(stInitError, 0); { Buffer allocate fail }
  1338. END;
  1339. {--TBufStream---------------------------------------------------------------}
  1340. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1341. {---------------------------------------------------------------------------}
  1342. DESTRUCTOR TBufStream.Done;
  1343. BEGIN
  1344. Flush; { Flush the file }
  1345. Inherited Done; { Call ancestor }
  1346. If (Buffer<>Nil) Then FreeMem(Buffer, BufSize); { Release buffer }
  1347. END;
  1348. {--TBufStream---------------------------------------------------------------}
  1349. { Close -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1350. {---------------------------------------------------------------------------}
  1351. PROCEDURE TBufStream.Close;
  1352. BEGIN
  1353. Flush; { Flush the buffer }
  1354. Inherited Close; { Call ancestor }
  1355. END;
  1356. {--TBufStream---------------------------------------------------------------}
  1357. { Flush -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1358. {---------------------------------------------------------------------------}
  1359. PROCEDURE TBufStream.Flush;
  1360. VAR W: Longint;
  1361. DosStreamError : Word;
  1362. BEGIN
  1363. If Status <> StOK then
  1364. exit;
  1365. If (LastMode=2) AND (BufPtr<>0) Then Begin { Must update file }
  1366. If (Handle = InvalidHandle) Then DosStreamError := 103 { File is not open }
  1367. Else
  1368. Begin
  1369. BlockWrite(FileInfo, Buffer^,BufPtr, W); { Write to file }
  1370. DosStreamError := IOResult;
  1371. End;
  1372. If (DosStreamError<>0) OR (W<>BufPtr) Then { We have an error }
  1373. If (DosStreamError=0) Then Error(stWriteError, 0){ Unknown write error }
  1374. Else Error(stError, DosStreamError); { Specific write error }
  1375. End;
  1376. BufPtr := 0; { Reset buffer ptr }
  1377. BufEnd := 0; { Reset buffer end }
  1378. END;
  1379. {--TBufStream---------------------------------------------------------------}
  1380. { Truncate -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1381. {---------------------------------------------------------------------------}
  1382. PROCEDURE TBufStream.Truncate;
  1383. BEGIN
  1384. Flush; { Flush buffer }
  1385. Inherited Truncate; { Truncate file }
  1386. END;
  1387. {--TBufStream---------------------------------------------------------------}
  1388. { Seek -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1389. {---------------------------------------------------------------------------}
  1390. PROCEDURE TBufStream.Seek (Pos: LongInt);
  1391. BEGIN
  1392. If (Status=stOk) Then Begin { Check status okay }
  1393. If (Position<>Pos) Then Begin { Move required }
  1394. Flush; { Flush the buffer }
  1395. Inherited Seek(Pos); { Call ancestor }
  1396. End;
  1397. End;
  1398. END;
  1399. {--TBufStream---------------------------------------------------------------}
  1400. { Open -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1401. {---------------------------------------------------------------------------}
  1402. PROCEDURE TBufStream.Open (OpenMode: Word);
  1403. BEGIN
  1404. If (Status=stOk) Then Begin { Check status okay }
  1405. BufPtr := 0; { Clear buffer start }
  1406. BufEnd := 0; { Clear buffer end }
  1407. Inherited Open(OpenMode); { Call ancestor }
  1408. End;
  1409. END;
  1410. {--TBufStream---------------------------------------------------------------}
  1411. { Read -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1412. {---------------------------------------------------------------------------}
  1413. PROCEDURE TBufStream.Read (Var Buf; Count: Longint);
  1414. VAR Success: Integer; W, Bw: Longint; P: PByteArray;
  1415. DosStreamError : Word;
  1416. BEGIN
  1417. If Status <> StOk then
  1418. begin
  1419. FillChar(Buf, Count, #0); { Error clear buffer }
  1420. exit;
  1421. end;
  1422. If (Position + Count > StreamSize) Then { Read pas stream end }
  1423. Error(stReadError, 0); { Call stream error }
  1424. If (Handle = InvalidHandle) Then Error(stReadError, 103); { File not open }
  1425. P := @Buf; { Transfer address }
  1426. If (LastMode=2) Then Flush; { Flush write buffer }
  1427. LastMode := 1; { Now set read mode }
  1428. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1429. If (BufPtr=BufEnd) Then Begin { Buffer is empty }
  1430. If (Position + BufSize > StreamSize) Then
  1431. Bw := StreamSize - Position { Amount of file left }
  1432. Else Bw := BufSize; { Full buffer size }
  1433. BlockRead(FileInfo, Buffer^, Bw, W);
  1434. DosStreamError := IOResult; { Read from file }
  1435. If ((DosStreamError<>0) OR (Bw<>W)) Then Begin { Error was detected }
  1436. If (DosStreamError<>0) Then
  1437. Error(stReadError, DosStreamError) { Specific read error }
  1438. Else Error(stReadError, 0); { Non specific error }
  1439. End Else Begin
  1440. BufPtr := 0; { Reset BufPtr }
  1441. BufEnd := W; { End of buffer }
  1442. End;
  1443. End;
  1444. If (Status=stOk) Then Begin { Status still okay }
  1445. W := BufEnd - BufPtr; { Space in buffer }
  1446. If (Count < W) Then W := Count; { Set transfer size }
  1447. Move(Buffer^[BufPtr], P^, W); { Data from buffer }
  1448. Dec(Count, W); { Reduce count }
  1449. Inc(BufPtr, W); { Advance buffer ptr }
  1450. Inc(P, W); { Transfer address }
  1451. Inc(Position, W); { Advance position }
  1452. End;
  1453. End;
  1454. If (Status<>stOk) AND (Count>0) Then
  1455. FillChar(P^, Count, #0); { Error clear buffer }
  1456. END;
  1457. {--TBufStream---------------------------------------------------------------}
  1458. { Write -> Platforms DOS/DPMI/WIN/OS2 - Checked 17May96 LdB }
  1459. {---------------------------------------------------------------------------}
  1460. PROCEDURE TBufStream.Write (Var Buf; Count: Longint);
  1461. VAR Success: Integer;
  1462. W: Longint;
  1463. P: PByteArray;
  1464. DosStreamError : Word;
  1465. BEGIN
  1466. if Status <> StOK then exit; { Exit if error }
  1467. If (Handle = InvalidHandle) Then Error(stWriteError, 103); { File not open }
  1468. If (LastMode=1) Then Flush; { Flush read buffer }
  1469. LastMode := 2; { Now set write mode }
  1470. P := @Buf; { Transfer address }
  1471. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1472. If (BufPtr=BufSize) Then Begin { Buffer is full }
  1473. BlockWrite(FileInfo, Buffer^, BufSize,W); { Write to file }
  1474. DosStreamError := IOResult;
  1475. If (DosStreamError<>0) OR (W<>BufSize) Then { We have an error }
  1476. If (DosStreamError=0) Then Error(stWriteError, 0) { Unknown write error }
  1477. Else Error(stError, DosStreamError); { Specific write error }
  1478. BufPtr := 0; { Reset BufPtr }
  1479. End;
  1480. If (Status=stOk) Then Begin { Status still okay }
  1481. W := BufSize - BufPtr; { Space in buffer }
  1482. If (Count < W) Then W := Count; { Transfer size }
  1483. Move(P^, Buffer^[BufPtr], W); { Data to buffer }
  1484. Dec(Count, W); { Reduce count }
  1485. Inc(BufPtr, W); { Advance buffer ptr }
  1486. Inc(P,W); { Transfer address }
  1487. Inc(Position, W); { Advance position }
  1488. If (Position > StreamSize) Then { File has expanded }
  1489. StreamSize := Position; { Update new size }
  1490. End;
  1491. End;
  1492. END;
  1493. {$IFDEF IO_CHECK_ON}
  1494. {$UNDEF IO_CHECK_ON}
  1495. {$I+}
  1496. {$ENDIF}
  1497. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1498. { TMemoryStream OBJECT METHODS }
  1499. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1500. {--TMemoryStream------------------------------------------------------------}
  1501. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1502. {---------------------------------------------------------------------------}
  1503. CONSTRUCTOR TMemoryStream.Init (ALimit: LongInt; ABlockSize: Word);
  1504. VAR W: Word;
  1505. BEGIN
  1506. Inherited Init; { Call ancestor }
  1507. If (ABlockSize=0) Then BlkSize := 8192 Else { Default blocksize }
  1508. BlkSize := ABlockSize; { Set blocksize }
  1509. If (ALimit = 0) Then W := 1 Else { At least 1 block }
  1510. W := (ALimit + BlkSize - 1) DIV BlkSize; { Blocks needed }
  1511. If NOT ChangeListSize(W) Then { Try allocate blocks }
  1512. Error(stInitError, 0); { Initialize error }
  1513. END;
  1514. {--TMemoryStream------------------------------------------------------------}
  1515. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1516. {---------------------------------------------------------------------------}
  1517. DESTRUCTOR TMemoryStream.Done;
  1518. BEGIN
  1519. ChangeListSize(0); { Release all memory }
  1520. Inherited Done; { Call ancestor }
  1521. END;
  1522. {--TMemoryStream------------------------------------------------------------}
  1523. { Truncate -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1524. {---------------------------------------------------------------------------}
  1525. PROCEDURE TMemoryStream.Truncate;
  1526. VAR W: Word;
  1527. BEGIN
  1528. If (Status=stOk) Then Begin { Check status okay }
  1529. If (Position = 0) Then W := 1 Else { At least one block }
  1530. W := (Position + BlkSize - 1) DIV BlkSize; { Blocks needed }
  1531. If ChangeListSize(W) Then StreamSize := Position { Set stream size }
  1532. Else Error(stError, 0); { Error truncating }
  1533. End;
  1534. END;
  1535. {--TMemoryStream------------------------------------------------------------}
  1536. { Read -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1537. {---------------------------------------------------------------------------}
  1538. PROCEDURE TMemoryStream.Read (Var Buf; Count: Longint);
  1539. VAR W, CurBlock, BlockPos: Word; Li: LongInt; P, Q: PByteArray;
  1540. BEGIN
  1541. If (Position + Count > StreamSize) Then { Insufficient data }
  1542. Error(stReadError, 0); { Read beyond end!!! }
  1543. P := @Buf; { Transfer address }
  1544. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1545. CurBlock := Position DIV BlkSize; { Current block }
  1546. { * REMARK * - Do not shorten this, result can be > 64K }
  1547. Li := CurBlock; { Transfer current block }
  1548. Li := Li * BlkSize; { Current position }
  1549. { * REMARK END * - Leon de Boer }
  1550. BlockPos := Position - Li; { Current position }
  1551. W := BlkSize - BlockPos; { Current block space }
  1552. If (W > Count) Then W := Count; { Adjust read size }
  1553. Q := Pointer(LongInt(BlkList^[CurBlock]) +
  1554. BlockPos); { Calc pointer }
  1555. Move(Q^, P^, W); { Move data to buffer }
  1556. Inc(Position, W); { Adjust position }
  1557. P := Pointer(LongInt(P) + W); { Transfer address }
  1558. Dec(Count, W); { Adjust count left }
  1559. End;
  1560. If (Count<>0) Then FillChar(P^, Count, #0); { Error clear buffer }
  1561. END;
  1562. {--TMemoryStream------------------------------------------------------------}
  1563. { Write -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1564. {---------------------------------------------------------------------------}
  1565. PROCEDURE TMemoryStream.Write (Var Buf; Count: Longint);
  1566. VAR
  1567. W, CurBlock, BlockPos: Word;
  1568. Li: LongInt;
  1569. P, Q: PByteArray;
  1570. BEGIN
  1571. If (Position + Count > MemSize) Then Begin { Expansion needed }
  1572. If (Position + Count = 0) Then W := 1 Else { At least 1 block }
  1573. W := (Position+Count+BlkSize-1) DIV BlkSize; { Blocks needed }
  1574. If NOT ChangeListSize(W) Then
  1575. Error(stWriteError, 0); { Expansion failed!!! }
  1576. End;
  1577. P := @Buf; { Transfer address }
  1578. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1579. CurBlock := Position DIV BlkSize; { Current segment }
  1580. { * REMARK * - Do not shorten this, result can be > 64K }
  1581. Li := CurBlock; { Transfer current block }
  1582. Li := Li * BlkSize; { Current position }
  1583. { * REMARK END * - Leon de Boer }
  1584. BlockPos := Position - Li; { Current position }
  1585. W := BlkSize - BlockPos; { Current block space }
  1586. If (W > Count) Then W := Count; { Adjust write size }
  1587. Q := Pointer(LongInt(BlkList^[CurBlock]) +
  1588. BlockPos); { Calc pointer }
  1589. Move(P^, Q^, W); { Transfer data }
  1590. Inc(Position, W); { Adjust position }
  1591. P := Pointer(LongInt(P) + W); { Transfer address }
  1592. Dec(Count, W); { Adjust count left }
  1593. If (Position > StreamSize) Then { File expanded }
  1594. StreamSize := Position; { Adjust stream size }
  1595. End;
  1596. END;
  1597. {***************************************************************************}
  1598. { TMemoryStream PRIVATE METHODS }
  1599. {***************************************************************************}
  1600. {--TMemoryStream------------------------------------------------------------}
  1601. { ChangeListSize -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1602. {---------------------------------------------------------------------------}
  1603. FUNCTION TMemoryStream.ChangeListSize (ALimit: Longint): Boolean;
  1604. VAR
  1605. I, W: Longint;
  1606. Li: LongInt;
  1607. P: PPointerArray;
  1608. OldVal : Boolean;
  1609. BEGIN
  1610. If (ALimit <> BlkCount) Then Begin { Change is needed }
  1611. ChangeListSize := False; { Preset failure }
  1612. If (ALimit > MaxPtrs) Then Exit; { To many blocks req }
  1613. If (ALimit <> 0) Then Begin { Create segment list }
  1614. Li := ALimit * SizeOf(Pointer); { Block array size }
  1615. If (MaxAvail > Li) Then Begin
  1616. GetMem(P, Li); { Allocate memory }
  1617. FillChar(P^, Li, #0); { Clear the memory }
  1618. End Else Begin
  1619. OldVal:=ReturnNilIfGrowHeapFails;
  1620. ReturnNilIfGrowHeapFails:=true;
  1621. GetMem(P,Li);
  1622. ReturnNilIfGrowHeapFails:=OldVal;
  1623. If P = Nil Then Exit;
  1624. FillChar(P^, Li, #0); { Clear the memory }
  1625. End; { Insufficient memory }
  1626. If (BlkCount <> 0) AND (BlkList <> Nil) Then { Current list valid }
  1627. If (BlkCount <= ALimit) Then Move(BlkList^,
  1628. P^, BlkCount * SizeOf(Pointer)) Else { Move whole old list }
  1629. Move(BlkList^, P^, Li); { Move partial list }
  1630. End Else P := Nil; { No new block list }
  1631. If (ALimit < BlkCount) Then { Shrink stream size }
  1632. For W := BlkCount-1 DownTo ALimit Do
  1633. FreeMem(BlkList^[W], BlkSize); { Release memory block }
  1634. If (P <> Nil) AND (ALimit > BlkCount) Then Begin { Expand stream size }
  1635. For W := BlkCount To ALimit-1 Do Begin
  1636. If (MaxAvail < BlkSize) Then Begin { Check enough memory }
  1637. OldVal:=ReturnNilIfGrowHeapFails;
  1638. ReturnNilIfGrowHeapFails:=true;
  1639. GetMem(P^[W],BlkSize);
  1640. ReturnNilIfGrowHeapFails:=OldVal;
  1641. If P = Nil Then Begin
  1642. For I := BlkCount To W-1 Do
  1643. FreeMem(P^[I], BlkSize); { Free mem allocated }
  1644. FreeMem(P, Li); { Release memory }
  1645. Exit;
  1646. End { Now exit }
  1647. End Else GetMem(P^[W], BlkSize); { Allocate memory }
  1648. End;
  1649. End;
  1650. If (BlkCount <> 0) AND (BlkList<>Nil) Then
  1651. FreeMem(BlkList, BlkCount * SizeOf(Pointer)); { Release old list }
  1652. BlkList := P; { Hold new block list }
  1653. BlkCount := ALimit; { Hold new count }
  1654. { * REMARK * - Do not shorten this, result can be > 64K }
  1655. MemSize := BlkCount; { Block count }
  1656. MemSize := MemSize * BlkSize; { Current position }
  1657. { * REMARK END * - Leon de Boer }
  1658. End;
  1659. ChangeListSize := True; { Successful }
  1660. END;
  1661. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1662. { TCollection OBJECT METHODS }
  1663. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1664. {--TCollection--------------------------------------------------------------}
  1665. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1666. {---------------------------------------------------------------------------}
  1667. CONSTRUCTOR TCollection.Init (ALimit, ADelta: Sw_Integer);
  1668. BEGIN
  1669. Inherited Init; { Call ancestor }
  1670. Delta := ADelta; { Set increment }
  1671. SetLimit(ALimit); { Set limit }
  1672. END;
  1673. {--TCollection--------------------------------------------------------------}
  1674. { Load -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1675. {---------------------------------------------------------------------------}
  1676. CONSTRUCTOR TCollection.Load (Var S: TStream);
  1677. VAR C, I: Sw_Integer;
  1678. BEGIN
  1679. If S.TPCompatible Then Begin
  1680. { I ignore endianness issues here. If endianness is different,
  1681. you can't expect binary compatible resources anyway. }
  1682. Count := 0; S.Read(Count, Sizeof(Word));
  1683. Limit := 0; S.Read(Limit, Sizeof(Word));
  1684. Delta := 0; S.Read(Delta, Sizeof(Word))
  1685. End
  1686. Else Begin
  1687. S.Read(Count, Sizeof(Count)); { Read count }
  1688. S.Read(Limit, Sizeof(Limit)); { Read limit }
  1689. S.Read(Delta, Sizeof(Delta)); { Read delta }
  1690. End;
  1691. Items := Nil; { Clear item pointer }
  1692. C := Count; { Hold count }
  1693. I := Limit; { Hold limit }
  1694. Count := 0; { Clear count }
  1695. Limit := 0; { Clear limit }
  1696. SetLimit(I); { Set requested limit }
  1697. Count := C; { Set count }
  1698. For I := 0 To C-1 Do AtPut(I, GetItem(S)); { Get each item }
  1699. END;
  1700. {--TCollection--------------------------------------------------------------}
  1701. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1702. {---------------------------------------------------------------------------}
  1703. DESTRUCTOR TCollection.Done;
  1704. BEGIN
  1705. FreeAll; { Free all items }
  1706. SetLimit(0); { Release all memory }
  1707. END;
  1708. {--TCollection--------------------------------------------------------------}
  1709. { At -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1710. {---------------------------------------------------------------------------}
  1711. FUNCTION TCollection.At (Index: Sw_Integer): Pointer;
  1712. BEGIN
  1713. If (Index < 0) OR (Index >= Count) Then Begin { Invalid index }
  1714. Error(coIndexError, Index); { Call error }
  1715. At := Nil; { Return nil }
  1716. End Else At := Items^[Index]; { Return item }
  1717. END;
  1718. {--TCollection--------------------------------------------------------------}
  1719. { IndexOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1720. {---------------------------------------------------------------------------}
  1721. FUNCTION TCollection.IndexOf (Item: Pointer): Sw_Integer;
  1722. VAR I: Sw_Integer;
  1723. BEGIN
  1724. If (Count>0) Then Begin { Count is positive }
  1725. For I := 0 To Count-1 Do { For each item }
  1726. If (Items^[I]=Item) Then Begin { Look for match }
  1727. IndexOf := I; { Return index }
  1728. Exit; { Now exit }
  1729. End;
  1730. End;
  1731. IndexOf := -1; { Return index }
  1732. END;
  1733. {--TCollection--------------------------------------------------------------}
  1734. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1735. {---------------------------------------------------------------------------}
  1736. FUNCTION TCollection.GetItem (Var S: TStream): Pointer;
  1737. BEGIN
  1738. GetItem := S.Get; { Item off stream }
  1739. END;
  1740. {--TCollection--------------------------------------------------------------}
  1741. { LastThat -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1742. {---------------------------------------------------------------------------}
  1743. FUNCTION TCollection.LastThat (Test: Pointer): Pointer;
  1744. VAR I: LongInt;
  1745. BEGIN
  1746. For I := Count DownTo 1 Do
  1747. Begin { Down from last item }
  1748. IF Boolean(Byte(Longint(CallPointerLocal(Test,PreviousFramePointer,Items^[I-1])))) THEN
  1749. Begin { Test each item }
  1750. LastThat := Items^[I-1]; { Return item }
  1751. Exit; { Now exit }
  1752. End;
  1753. End;
  1754. LastThat := Nil; { None passed test }
  1755. END;
  1756. {--TCollection--------------------------------------------------------------}
  1757. { FirstThat -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1758. {---------------------------------------------------------------------------}
  1759. FUNCTION TCollection.FirstThat (Test: Pointer): Pointer;
  1760. VAR I: LongInt;
  1761. BEGIN
  1762. For I := 1 To Count Do Begin { Up from first item }
  1763. IF Boolean(Byte(Longint(CallPointerLocal(Test,PreviousFramePointer,Items^[I-1])))) THEN
  1764. Begin { Test each item }
  1765. FirstThat := Items^[I-1]; { Return item }
  1766. Exit; { Now exit }
  1767. End;
  1768. End;
  1769. FirstThat := Nil; { None passed test }
  1770. END;
  1771. {--TCollection--------------------------------------------------------------}
  1772. { Pack -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1773. {---------------------------------------------------------------------------}
  1774. PROCEDURE TCollection.Pack;
  1775. VAR I, J: Sw_Integer;
  1776. BEGIN
  1777. I := 0; { Initialize dest }
  1778. J := 0; { Intialize test }
  1779. While (I<Count) AND (J<Limit) Do Begin { Check fully packed }
  1780. If (Items^[J]<>Nil) Then Begin { Found a valid item }
  1781. If (I<>J) Then Begin
  1782. Items^[I] := Items^[J]; { Transfer item }
  1783. Items^[J] := Nil; { Now clear old item }
  1784. End;
  1785. Inc(I); { One item packed }
  1786. End;
  1787. Inc(J); { Next item to test }
  1788. End;
  1789. If (I<Count) Then Count := I; { New packed count }
  1790. END;
  1791. {--TCollection--------------------------------------------------------------}
  1792. { FreeAll -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1793. {---------------------------------------------------------------------------}
  1794. PROCEDURE TCollection.FreeAll;
  1795. VAR I: Sw_Integer;
  1796. BEGIN
  1797. for I := Count-1 downto 0 do
  1798. FreeItem(At(I));
  1799. Count := 0; { Clear item count }
  1800. END;
  1801. {--TCollection--------------------------------------------------------------}
  1802. { DeleteAll -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1803. {---------------------------------------------------------------------------}
  1804. PROCEDURE TCollection.DeleteAll;
  1805. BEGIN
  1806. Count := 0; { Clear item count }
  1807. END;
  1808. {--TCollection--------------------------------------------------------------}
  1809. { Free -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1810. {---------------------------------------------------------------------------}
  1811. PROCEDURE TCollection.Free (Item: Pointer);
  1812. BEGIN
  1813. Delete(Item); { Delete from list }
  1814. FreeItem(Item); { Free the item }
  1815. END;
  1816. {--TCollection--------------------------------------------------------------}
  1817. { Insert -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1818. {---------------------------------------------------------------------------}
  1819. PROCEDURE TCollection.Insert (Item: Pointer);
  1820. BEGIN
  1821. AtInsert(Count, Item); { Insert item }
  1822. END;
  1823. {--TCollection--------------------------------------------------------------}
  1824. { Delete -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1825. {---------------------------------------------------------------------------}
  1826. PROCEDURE TCollection.Delete (Item: Pointer);
  1827. BEGIN
  1828. AtDelete(IndexOf(Item)); { Delete from list }
  1829. END;
  1830. {--TCollection--------------------------------------------------------------}
  1831. { AtFree -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1832. {---------------------------------------------------------------------------}
  1833. PROCEDURE TCollection.AtFree (Index: Sw_Integer);
  1834. VAR Item: Pointer;
  1835. BEGIN
  1836. Item := At(Index); { Retreive item ptr }
  1837. AtDelete(Index); { Delete item }
  1838. FreeItem(Item); { Free the item }
  1839. END;
  1840. {--TCollection--------------------------------------------------------------}
  1841. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1842. {---------------------------------------------------------------------------}
  1843. PROCEDURE TCollection.FreeItem (Item: Pointer);
  1844. VAR P: PObject;
  1845. BEGIN
  1846. P := PObject(Item); { Convert pointer }
  1847. If (P<>Nil) Then Dispose(P, Done); { Dispose of object }
  1848. END;
  1849. {--TCollection--------------------------------------------------------------}
  1850. { AtDelete -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1851. {---------------------------------------------------------------------------}
  1852. PROCEDURE TCollection.AtDelete (Index: Sw_Integer);
  1853. BEGIN
  1854. If (Index >= 0) AND (Index < Count) Then Begin { Valid index }
  1855. Dec(Count); { One less item }
  1856. If (Count>Index) Then Move(Items^[Index+1],
  1857. Items^[Index], (Count-Index)*Sizeof(Pointer)); { Shuffle items down }
  1858. End Else Error(coIndexError, Index); { Index error }
  1859. END;
  1860. {--TCollection--------------------------------------------------------------}
  1861. { ForEach -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1862. {---------------------------------------------------------------------------}
  1863. PROCEDURE TCollection.ForEach (Action: Pointer);
  1864. VAR I: LongInt;
  1865. BEGIN
  1866. For I := 1 To Count Do { Up from first item }
  1867. CallPointerLocal(Action,PreviousFramePointer,Items^[I-1]); { Call with each item }
  1868. END;
  1869. {--TCollection--------------------------------------------------------------}
  1870. { SetLimit -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1871. {---------------------------------------------------------------------------}
  1872. PROCEDURE TCollection.SetLimit (ALimit: Sw_Integer);
  1873. VAR
  1874. AItems: PItemList;
  1875. BEGIN
  1876. If (ALimit < Count) Then
  1877. ALimit := Count;
  1878. If (ALimit > MaxCollectionSize) Then
  1879. ALimit := MaxCollectionSize;
  1880. If (ALimit <> Limit) Then
  1881. Begin
  1882. If (ALimit = 0) Then
  1883. AItems := Nil
  1884. Else
  1885. Begin
  1886. GetMem(AItems, ALimit * SizeOf(Pointer));
  1887. If (AItems<>Nil) Then
  1888. FillChar(AItems^,ALimit * SizeOf(Pointer), #0);
  1889. End;
  1890. If (AItems<>Nil) OR (ALimit=0) Then
  1891. Begin
  1892. If (AItems <>Nil) AND (Items <> Nil) Then
  1893. Move(Items^, AItems^, Count*SizeOf(Pointer));
  1894. If (Limit <> 0) AND (Items <> Nil) Then
  1895. FreeMem(Items, Limit * SizeOf(Pointer));
  1896. end;
  1897. Items := AItems;
  1898. Limit := ALimit;
  1899. End;
  1900. END;
  1901. {--TCollection--------------------------------------------------------------}
  1902. { Error -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1903. {---------------------------------------------------------------------------}
  1904. PROCEDURE TCollection.Error (Code, Info: Integer);
  1905. BEGIN
  1906. RunError(212 - Code); { Run error }
  1907. END;
  1908. {--TCollection--------------------------------------------------------------}
  1909. { AtPut -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1910. {---------------------------------------------------------------------------}
  1911. PROCEDURE TCollection.AtPut (Index: Sw_Integer; Item: Pointer);
  1912. BEGIN
  1913. If (Index >= 0) AND (Index < Count) Then { Index valid }
  1914. Items^[Index] := Item { Put item in index }
  1915. Else Error(coIndexError, Index); { Index error }
  1916. END;
  1917. {--TCollection--------------------------------------------------------------}
  1918. { AtInsert -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1919. {---------------------------------------------------------------------------}
  1920. PROCEDURE TCollection.AtInsert (Index: Sw_Integer; Item: Pointer);
  1921. VAR I: Sw_Integer;
  1922. BEGIN
  1923. If (Index >= 0) AND (Index <= Count) Then Begin { Valid index }
  1924. If (Count=Limit) Then SetLimit(Limit+Delta); { Expand size if able }
  1925. If (Limit>Count) Then Begin
  1926. If (Index < Count) Then Begin { Not last item }
  1927. For I := Count-1 DownTo Index Do { Start from back }
  1928. Items^[I+1] := Items^[I]; { Move each item }
  1929. End;
  1930. Items^[Index] := Item; { Put item in list }
  1931. Inc(Count); { Inc count }
  1932. End Else Error(coOverflow, Index); { Expand failed }
  1933. End Else Error(coIndexError, Index); { Index error }
  1934. END;
  1935. {--TCollection--------------------------------------------------------------}
  1936. { Store -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1937. {---------------------------------------------------------------------------}
  1938. PROCEDURE TCollection.Store (Var S: TStream);
  1939. var
  1940. LimitWord, DeltaWord: Word;
  1941. PROCEDURE DoPutItem (P: Pointer);{$IFNDEF FPC}FAR;{$ENDIF}
  1942. BEGIN
  1943. PutItem(S, P); { Put item on stream }
  1944. END;
  1945. BEGIN
  1946. If S.TPCompatible Then Begin
  1947. { Check if it is safe to write in TP-compatible stream.
  1948. If Count is too big, signal an error.
  1949. If Limit or Delta are too big, write smaller values. }
  1950. If (Count > MaxTPCompatibleCollectionSize)
  1951. Then S.Error(stWriteError, 0)
  1952. Else Begin
  1953. S.Write(Count, Sizeof(Word));
  1954. if Limit > MaxTPCompatibleCollectionSize
  1955. then LimitWord := MaxTPCompatibleCollectionSize
  1956. else LimitWord := Limit;
  1957. S.Write(LimitWord, Sizeof(Word));
  1958. if Delta > MaxTPCompatibleCollectionSize
  1959. then DeltaWord := MaxTPCompatibleCollectionSize
  1960. else DeltaWord := Delta;
  1961. S.Write(DeltaWord, Sizeof(Word));
  1962. End
  1963. End
  1964. Else Begin
  1965. S.Write(Count, Sizeof(Count)); { Write count }
  1966. S.Write(Limit, Sizeof(Limit)); { Write limit }
  1967. S.Write(Delta, Sizeof(Delta)); { Write delta }
  1968. End;
  1969. ForEach(@DoPutItem); { Each item to stream }
  1970. END;
  1971. {--TCollection--------------------------------------------------------------}
  1972. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1973. {---------------------------------------------------------------------------}
  1974. PROCEDURE TCollection.PutItem (Var S: TStream; Item: Pointer);
  1975. BEGIN
  1976. S.Put(Item); { Put item on stream }
  1977. END;
  1978. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1979. { TSortedCollection OBJECT METHODS }
  1980. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1981. {--TSortedCollection--------------------------------------------------------}
  1982. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1983. {---------------------------------------------------------------------------}
  1984. CONSTRUCTOR TSortedCollection.Init (ALimit, ADelta: Sw_Integer);
  1985. BEGIN
  1986. Inherited Init(ALimit, ADelta); { Call ancestor }
  1987. Duplicates := False; { Clear flag }
  1988. END;
  1989. {--TSortedCollection--------------------------------------------------------}
  1990. { Load -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1991. {---------------------------------------------------------------------------}
  1992. CONSTRUCTOR TSortedCollection.Load (Var S: TStream);
  1993. BEGIN
  1994. Inherited Load(S); { Call ancestor }
  1995. S.Read(Duplicates, SizeOf(Duplicates)); { Read duplicate flag }
  1996. END;
  1997. {--TSortedCollection--------------------------------------------------------}
  1998. { KeyOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1999. {---------------------------------------------------------------------------}
  2000. FUNCTION TSortedCollection.KeyOf (Item: Pointer): Pointer;
  2001. BEGIN
  2002. KeyOf := Item; { Return item as key }
  2003. END;
  2004. {--TSortedCollection--------------------------------------------------------}
  2005. { IndexOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2006. {---------------------------------------------------------------------------}
  2007. FUNCTION TSortedCollection.IndexOf (Item: Pointer): Sw_Integer;
  2008. VAR I, J: Sw_Integer;
  2009. BEGIN
  2010. J := -1; { Preset result }
  2011. If Search(KeyOf(Item), I) Then Begin { Search for item }
  2012. If Duplicates Then { Duplicates allowed }
  2013. While (I < Count) AND (Item <> Items^[I]) Do
  2014. Inc(I); { Count duplicates }
  2015. If (I < Count) Then J := I; { Index result }
  2016. End;
  2017. IndexOf := J; { Return result }
  2018. END;
  2019. {--TSortedCollection--------------------------------------------------------}
  2020. { Compare -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2021. {---------------------------------------------------------------------------}
  2022. FUNCTION TSortedCollection.Compare (Key1, Key2: Pointer): Sw_Integer;
  2023. BEGIN
  2024. Abstract; { Abstract method }
  2025. Compare:=0;
  2026. END;
  2027. {--TSortedCollection--------------------------------------------------------}
  2028. { Search -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2029. {---------------------------------------------------------------------------}
  2030. FUNCTION TSortedCollection.Search (Key: Pointer; Var Index: Sw_Integer): Boolean;
  2031. VAR L, H, I, C: Sw_Integer;
  2032. BEGIN
  2033. Search := False; { Preset failure }
  2034. L := 0; { Start count }
  2035. H := Count - 1; { End count }
  2036. While (L <= H) Do Begin
  2037. I := (L + H) SHR 1; { Mid point }
  2038. C := Compare(KeyOf(Items^[I]), Key); { Compare with key }
  2039. If (C < 0) Then L := I + 1 Else Begin { Item to left }
  2040. H := I - 1; { Item to right }
  2041. If C = 0 Then Begin { Item match found }
  2042. Search := True; { Result true }
  2043. If NOT Duplicates Then L := I; { Force kick out }
  2044. End;
  2045. End;
  2046. End;
  2047. Index := L; { Return result }
  2048. END;
  2049. {--TSortedCollection--------------------------------------------------------}
  2050. { Insert -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2051. {---------------------------------------------------------------------------}
  2052. PROCEDURE TSortedCollection.Insert (Item: Pointer);
  2053. VAR I: Sw_Integer;
  2054. BEGIN
  2055. If NOT Search(KeyOf(Item), I) OR Duplicates Then { Item valid }
  2056. AtInsert(I, Item); { Insert the item }
  2057. END;
  2058. {--TSortedCollection--------------------------------------------------------}
  2059. { Store -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2060. {---------------------------------------------------------------------------}
  2061. PROCEDURE TSortedCollection.Store (Var S: TStream);
  2062. BEGIN
  2063. TCollection.Store(S); { Call ancestor }
  2064. S.Write(Duplicates, SizeOf(Duplicates)); { Write duplicate flag }
  2065. END;
  2066. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2067. { TStringCollection OBJECT METHODS }
  2068. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2069. {--TStringCollection--------------------------------------------------------}
  2070. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2071. {---------------------------------------------------------------------------}
  2072. FUNCTION TStringCollection.GetItem (Var S: TStream): Pointer;
  2073. BEGIN
  2074. GetItem := S.ReadStr; { Get new item }
  2075. END;
  2076. {--TStringCollection--------------------------------------------------------}
  2077. { Compare -> Platforms DOS/DPMI/WIN/OS2 - Checked 21Aug97 LdB }
  2078. {---------------------------------------------------------------------------}
  2079. FUNCTION TStringCollection.Compare (Key1, Key2: Pointer): Sw_Integer;
  2080. VAR I, J: Sw_Integer; P1, P2: PString;
  2081. BEGIN
  2082. P1 := PString(Key1); { String 1 pointer }
  2083. P2 := PString(Key2); { String 2 pointer }
  2084. If (Length(P1^)<Length(P2^)) Then J := Length(P1^)
  2085. Else J := Length(P2^); { Shortest length }
  2086. I := 1; { First character }
  2087. While (I<J) AND (P1^[I]=P2^[I]) Do Inc(I); { Scan till fail }
  2088. If (I=J) Then Begin { Possible match }
  2089. { * REMARK * - Bug fix 21 August 1997 }
  2090. If (P1^[I]<P2^[I]) Then Compare := -1 Else { String1 < String2 }
  2091. If (P1^[I]>P2^[I]) Then Compare := 1 Else { String1 > String2 }
  2092. If (Length(P1^)>Length(P2^)) Then Compare := 1 { String1 > String2 }
  2093. Else If (Length(P1^)<Length(P2^)) Then { String1 < String2 }
  2094. Compare := -1 Else Compare := 0; { String1 = String2 }
  2095. { * REMARK END * - Leon de Boer }
  2096. End Else If (P1^[I]<P2^[I]) Then Compare := -1 { String1 < String2 }
  2097. Else Compare := 1; { String1 > String2 }
  2098. END;
  2099. {--TStringCollection--------------------------------------------------------}
  2100. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2101. {---------------------------------------------------------------------------}
  2102. PROCEDURE TStringCollection.FreeItem (Item: Pointer);
  2103. BEGIN
  2104. DisposeStr(Item); { Dispose item }
  2105. END;
  2106. {--TStringCollection--------------------------------------------------------}
  2107. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2108. {---------------------------------------------------------------------------}
  2109. PROCEDURE TStringCollection.PutItem (Var S: TStream; Item: Pointer);
  2110. BEGIN
  2111. S.WriteStr(Item); { Write string }
  2112. END;
  2113. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2114. { TStrCollection OBJECT METHODS }
  2115. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2116. {--TStrCollection-----------------------------------------------------------}
  2117. { Compare -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2118. {---------------------------------------------------------------------------}
  2119. FUNCTION TStrCollection.Compare (Key1, Key2: Pointer): Sw_Integer;
  2120. VAR I, J: Sw_Integer; P1, P2: PByteArray;
  2121. BEGIN
  2122. P1 := PByteArray(Key1); { PChar 1 pointer }
  2123. P2 := PByteArray(Key2); { PChar 2 pointer }
  2124. I := 0; { Preset no size }
  2125. If (P1<>Nil) Then While (P1^[I]<>0) Do Inc(I); { PChar 1 length }
  2126. J := 0; { Preset no size }
  2127. If (P2<>Nil) Then While (P2^[J]<>0) Do Inc(J); { PChar 2 length }
  2128. If (I < J) Then J := I; { Shortest length }
  2129. I := 0; { First character }
  2130. While (I<J) AND (P1^[I]=P2^[I]) Do Inc(I); { Scan till fail }
  2131. If (P1^[I]=P2^[I]) Then Compare := 0 Else { Strings matched }
  2132. If (P1^[I]<P2^[I]) Then Compare := -1 Else { String1 < String2 }
  2133. Compare := 1; { String1 > String2 }
  2134. END;
  2135. {--TStrCollection-----------------------------------------------------------}
  2136. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2137. {---------------------------------------------------------------------------}
  2138. FUNCTION TStrCollection.GetItem (Var S: TStream): Pointer;
  2139. BEGIN
  2140. GetItem := S.StrRead; { Get string item }
  2141. END;
  2142. {--TStrCollection-----------------------------------------------------------}
  2143. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2144. {---------------------------------------------------------------------------}
  2145. PROCEDURE TStrCollection.FreeItem (Item: Pointer);
  2146. VAR I: Sw_Integer; P: PByteArray;
  2147. BEGIN
  2148. If (Item<>Nil) Then Begin { Item is valid }
  2149. P := PByteArray(Item); { Create byte pointer }
  2150. I := 0; { Preset no size }
  2151. While (P^[I]<>0) Do Inc(I); { Find PChar end }
  2152. FreeMem(Item, I+1); { Release memory }
  2153. End;
  2154. END;
  2155. {--TStrCollection-----------------------------------------------------------}
  2156. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2157. {---------------------------------------------------------------------------}
  2158. PROCEDURE TStrCollection.PutItem (Var S: TStream; Item: Pointer);
  2159. BEGIN
  2160. S.StrWrite(Item); { Write the string }
  2161. END;
  2162. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2163. { TUnSortedStrCollection OBJECT METHODS }
  2164. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2165. {--TUnSortedCollection------------------------------------------------------}
  2166. { Insert -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2167. {---------------------------------------------------------------------------}
  2168. PROCEDURE TUnSortedStrCollection.Insert (Item: Pointer);
  2169. BEGIN
  2170. AtInsert(Count, Item); { Insert - NO sorting }
  2171. END;
  2172. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2173. { TResourceItem RECORD }
  2174. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2175. TYPE
  2176. TResourceItem = packed RECORD
  2177. Posn: LongInt; { Resource position }
  2178. Size: LongInt; { Resource size }
  2179. Key : String; { Resource key }
  2180. End;
  2181. PResourceItem = ^TResourceItem;
  2182. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2183. { TResourceCollection OBJECT METHODS }
  2184. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2185. {--TResourceCollection------------------------------------------------------}
  2186. { KeyOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2187. {---------------------------------------------------------------------------}
  2188. FUNCTION TResourceCollection.KeyOf (Item: Pointer): Pointer;
  2189. BEGIN
  2190. KeyOf := @PResourceItem(Item)^.Key; { Pointer to key }
  2191. END;
  2192. {--TResourceCollection------------------------------------------------------}
  2193. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2194. {---------------------------------------------------------------------------}
  2195. FUNCTION TResourceCollection.GetItem (Var S: TStream): Pointer;
  2196. VAR B: Byte; Pos: Longint; Size: Longint; Ts: String; P: PResourceItem;
  2197. BEGIN
  2198. S.Read(Pos, SizeOf(Pos)); { Read position }
  2199. S.Read(Size, SizeOf(Size)); { Read size }
  2200. S.Read(B, 1); { Read key length }
  2201. GetMem(P, B + (SizeOf(TResourceItem) -
  2202. SizeOf(Ts) + 1)); { Allocate min memory }
  2203. If (P<>Nil) Then Begin { If allocate works }
  2204. P^.Posn := Pos; { Xfer position }
  2205. P^.Size := Size; { Xfer size }
  2206. P^.Key[0] := Char(B); { Xfer string length }
  2207. S.Read(P^.Key[1], B); { Xfer string data }
  2208. End;
  2209. GetItem := P; { Return pointer }
  2210. END;
  2211. {--TResourceCollection------------------------------------------------------}
  2212. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2213. {---------------------------------------------------------------------------}
  2214. PROCEDURE TResourceCollection.FreeItem (Item: Pointer);
  2215. VAR Ts: String;
  2216. BEGIN
  2217. If (Item<>Nil) Then FreeMem(Item,
  2218. SizeOf(TResourceItem) - SizeOf(Ts) +
  2219. Length(PResourceItem(Item)^.Key) + 1); { Release memory }
  2220. END;
  2221. {--TResourceCollection------------------------------------------------------}
  2222. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2223. {---------------------------------------------------------------------------}
  2224. PROCEDURE TResourceCollection.PutItem (Var S: TStream; Item: Pointer);
  2225. VAR Ts: String;
  2226. BEGIN
  2227. If (Item<>Nil) Then S.Write(PResourceItem(Item)^,
  2228. SizeOf(TResourceItem) - SizeOf(Ts) +
  2229. Length(PResourceItem(Item)^.Key) + 1); { Write to stream }
  2230. END;
  2231. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2232. { PRIVATE RESOURCE MANAGER CONSTANTS }
  2233. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2234. CONST
  2235. RStreamMagic: LongInt = $52504246; { 'FBPR' }
  2236. RStreamBackLink: LongInt = $4C424246; { 'FBBL' }
  2237. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2238. { PRIVATE RESOURCE MANAGER TYPES }
  2239. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2240. TYPE
  2241. {$IFDEF NewExeFormat} { New EXE format }
  2242. TExeHeader = packed RECORD
  2243. eHdrSize: Word;
  2244. eMinAbove: Word;
  2245. eMaxAbove: Word;
  2246. eInitSS: Word;
  2247. eInitSP: Word;
  2248. eCheckSum: Word;
  2249. eInitPC: Word;
  2250. eInitCS: Word;
  2251. eRelocOfs: Word;
  2252. eOvlyNum: Word;
  2253. eRelocTab: Word;
  2254. eSpace: Array[1..30] of Byte;
  2255. eNewHeader: Word;
  2256. END;
  2257. {$ENDIF}
  2258. THeader = packed RECORD
  2259. Signature: Word;
  2260. Case Integer Of
  2261. 0: (
  2262. LastCount: Word;
  2263. PageCount: Word;
  2264. ReloCount: Word);
  2265. 1: (
  2266. InfoType: Word;
  2267. InfoSize: Longint);
  2268. End;
  2269. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2270. { TResourceFile OBJECT METHODS }
  2271. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2272. {--TResourceFile------------------------------------------------------------}
  2273. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2274. {---------------------------------------------------------------------------}
  2275. CONSTRUCTOR TResourceFile.Init(AStream: PStream);
  2276. VAR Found, Stop: Boolean; Header: THeader;
  2277. {$IFDEF NewExeFormat} ExeHeader: TExeHeader; {$ENDIF}
  2278. BEGIN
  2279. TObject.Init; { Initialize object }
  2280. Found := False; { Preset false }
  2281. If (AStream<>Nil) Then Begin
  2282. Stream := AStream; { Hold stream }
  2283. BasePos := Stream^.GetPos; { Get position }
  2284. Repeat
  2285. Stop := True; { Preset stop }
  2286. If (BasePos <= Stream^.GetSize-SizeOf(THeader))
  2287. Then Begin { Valid file header }
  2288. Stream^.Seek(BasePos); { Seek to position }
  2289. Stream^.Read(Header, SizeOf(THeader)); { Read header }
  2290. Case Header.Signature Of
  2291. {$IFDEF NewExeFormat} { New format file }
  2292. $5A4D: Begin
  2293. Stream^.Read(ExeHeader, SizeOf(TExeHeader));
  2294. BasePos := ExeHeader.eNewHeader; { Hold position }
  2295. Stop := False; { Clear stop flag }
  2296. End;
  2297. $454E: Begin
  2298. BasePos := Stream^.GetSize - 8; { Hold position }
  2299. Stop := False; { Clear stop flag }
  2300. End;
  2301. $4246: Begin
  2302. Stop := False; { Clear stop flag }
  2303. Case Header.Infotype Of
  2304. $5250: Begin { Found Resource }
  2305. Found := True; { Found flag is true }
  2306. Stop := True; { Set stop flag }
  2307. End;
  2308. $4C42: Dec(BasePos, Header.InfoSize-8);{ Found BackLink }
  2309. $4648: Dec(BasePos, SizeOf(THeader)*2);{ Found HelpFile }
  2310. Else Stop := True; { Set stop flag }
  2311. End;
  2312. End;
  2313. $424E: If Header.InfoType = $3230 { Found Debug Info }
  2314. Then Begin
  2315. Dec(BasePos, Header.InfoSize); { Adjust position }
  2316. Stop := False; { Clear stop flag }
  2317. End;
  2318. {$ELSE}
  2319. $5A4D: Begin
  2320. Inc(BasePos, LongInt(Header.PageCount)*512
  2321. - (-Header.LastCount AND 511)); { Calc position }
  2322. Stop := False; { Clear stop flag }
  2323. End;
  2324. $4246: If Header.InfoType = $5250 Then { Header was found }
  2325. Found := True Else Begin
  2326. Inc(BasePos, Header.InfoSize + 8); { Adjust position }
  2327. Stop := False; { Clear stop flag }
  2328. End;
  2329. {$ENDIF}
  2330. End;
  2331. End;
  2332. Until Stop; { Until flag is set }
  2333. End;
  2334. If Found Then Begin { Resource was found }
  2335. Stream^.Seek(BasePos + SizeOf(LongInt) * 2); { Seek to position }
  2336. Stream^.Read(IndexPos, SizeOf(LongInt)); { Read index position }
  2337. Stream^.Seek(BasePos + IndexPos); { Seek to resource }
  2338. Index.Load(Stream^); { Load resource }
  2339. End Else Begin
  2340. IndexPos := SizeOf(LongInt) * 3; { Set index position }
  2341. Index.Init(0, 8); { Set index }
  2342. End;
  2343. END;
  2344. {--TResourceFile------------------------------------------------------------}
  2345. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2346. {---------------------------------------------------------------------------}
  2347. DESTRUCTOR TResourceFile.Done;
  2348. BEGIN
  2349. Flush; { Flush the file }
  2350. Index.Done; { Dispose of index }
  2351. If (Stream<>Nil) Then Dispose(Stream, Done); { Dispose of stream }
  2352. END;
  2353. {--TResourceFile------------------------------------------------------------}
  2354. { Count -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2355. {---------------------------------------------------------------------------}
  2356. FUNCTION TResourceFile.Count: Sw_Integer;
  2357. BEGIN
  2358. Count := Index.Count; { Return index count }
  2359. END;
  2360. {--TResourceFile------------------------------------------------------------}
  2361. { KeyAt -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2362. {---------------------------------------------------------------------------}
  2363. FUNCTION TResourceFile.KeyAt (I: Sw_Integer): String;
  2364. BEGIN
  2365. KeyAt := PResourceItem(Index.At(I))^.Key; { Return key }
  2366. END;
  2367. {--TResourceFile------------------------------------------------------------}
  2368. { Get -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2369. {---------------------------------------------------------------------------}
  2370. FUNCTION TResourceFile.Get (Key: String): PObject;
  2371. VAR I: Sw_Integer;
  2372. BEGIN
  2373. If (Stream = Nil) OR (NOT Index.Search(@Key, I)) { No match on key }
  2374. Then Get := Nil Else Begin
  2375. Stream^.Seek(BasePos +
  2376. PResourceItem(Index.At(I))^.Posn); { Seek to position }
  2377. Get := Stream^.Get; { Get item }
  2378. End;
  2379. END;
  2380. {--TResourceFile------------------------------------------------------------}
  2381. { SwitchTo -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2382. {---------------------------------------------------------------------------}
  2383. FUNCTION TResourceFile.SwitchTo (AStream: PStream; Pack: Boolean): PStream;
  2384. VAR NewBasePos: LongInt;
  2385. PROCEDURE DoCopyResource (Item: PResourceItem);{$IFNDEF FPC}FAR;{$ENDIF}
  2386. BEGIN
  2387. Stream^.Seek(BasePos + Item^.Posn); { Move stream position }
  2388. Item^.Posn := AStream^.GetPos - NewBasePos; { Hold new position }
  2389. AStream^.CopyFrom(Stream^, Item^.Size); { Copy the item }
  2390. END;
  2391. BEGIN
  2392. SwitchTo := Stream; { Preset return }
  2393. If (AStream<>Nil) AND (Stream<>Nil) Then Begin { Both streams valid }
  2394. NewBasePos := AStream^.GetPos; { Get position }
  2395. If Pack Then Begin
  2396. AStream^.Seek(NewBasePos + SizeOf(LongInt)*3); { Seek to position }
  2397. Index.ForEach(@DoCopyResource); { Copy each resource }
  2398. IndexPos := AStream^.GetPos - NewBasePos; { Hold index position }
  2399. End Else Begin
  2400. Stream^.Seek(BasePos); { Seek to position }
  2401. AStream^.CopyFrom(Stream^, IndexPos); { Copy the resource }
  2402. End;
  2403. Stream := AStream; { Hold new stream }
  2404. BasePos := NewBasePos; { New base position }
  2405. Modified := True; { Set modified flag }
  2406. End;
  2407. END;
  2408. {--TResourceFile------------------------------------------------------------}
  2409. { Flush -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2410. {---------------------------------------------------------------------------}
  2411. PROCEDURE TResourceFile.Flush;
  2412. VAR ResSize: LongInt; LinkSize: LongInt;
  2413. BEGIN
  2414. If (Modified) AND (Stream<>Nil) Then Begin { We have modification }
  2415. Stream^.Seek(BasePos + IndexPos); { Seek to position }
  2416. Index.Store(Stream^); { Store the item }
  2417. ResSize := Stream^.GetPos - BasePos; { Hold position }
  2418. LinkSize := ResSize + SizeOf(LongInt) * 2; { Hold link size }
  2419. Stream^.Write(RStreamBackLink, SizeOf(LongInt)); { Write link back }
  2420. Stream^.Write(LinkSize, SizeOf(LongInt)); { Write link size }
  2421. Stream^.Seek(BasePos); { Move stream position }
  2422. Stream^.Write(RStreamMagic, SizeOf(LongInt)); { Write number }
  2423. Stream^.Write(ResSize, SizeOf(LongInt)); { Write record size }
  2424. Stream^.Write(IndexPos, SizeOf(LongInt)); { Write index position }
  2425. Stream^.Flush; { Flush the stream }
  2426. End;
  2427. Modified := False; { Clear modified flag }
  2428. END;
  2429. {--TResourceFile------------------------------------------------------------}
  2430. { Delete -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2431. {---------------------------------------------------------------------------}
  2432. PROCEDURE TResourceFile.Delete (Key: String);
  2433. VAR I: Sw_Integer;
  2434. BEGIN
  2435. If Index.Search(@Key, I) Then Begin { Search for key }
  2436. Index.Free(Index.At(I)); { Delete from index }
  2437. Modified := True; { Set modified flag }
  2438. End;
  2439. END;
  2440. {--TResourceFile------------------------------------------------------------}
  2441. { Put -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2442. {---------------------------------------------------------------------------}
  2443. PROCEDURE TResourceFile.Put (Item: PObject; Key: String);
  2444. VAR I: Sw_Integer; Ts: String; P: PResourceItem;
  2445. BEGIN
  2446. If (Stream=Nil) Then Exit; { Stream not valid }
  2447. If Index.Search(@Key, I) Then P := Index.At(I) { Search for item }
  2448. Else Begin
  2449. GetMem(P, Length(Key) + (SizeOf(TResourceItem) -
  2450. SizeOf(Ts) + 1)); { Allocate memory }
  2451. If (P<>Nil) Then Begin
  2452. P^.Key := Key; { Store key }
  2453. Index.AtInsert(I, P); { Insert item }
  2454. End;
  2455. End;
  2456. If (P<>Nil) Then Begin
  2457. P^.Posn := IndexPos; { Set index position }
  2458. Stream^.Seek(BasePos + IndexPos); { Seek file position }
  2459. Stream^.Put(Item); { Put item on stream }
  2460. IndexPos := Stream^.GetPos - BasePos; { Hold index position }
  2461. P^.Size := IndexPos - P^.Posn; { Calc size }
  2462. Modified := True; { Set modified flag }
  2463. End;
  2464. END;
  2465. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2466. { TStringList OBJECT METHODS }
  2467. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2468. {--TStringList--------------------------------------------------------------}
  2469. { Load -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2470. {---------------------------------------------------------------------------}
  2471. CONSTRUCTOR TStringList.Load (Var S: TStream);
  2472. VAR Size: Word;
  2473. BEGIN
  2474. Stream := @S; { Hold stream pointer }
  2475. S.Read(Size, SizeOf(Word)); { Read size }
  2476. BasePos := S.GetPos; { Hold position }
  2477. S.Seek(BasePos + Size); { Seek to position }
  2478. S.Read(IndexSize, SizeOf(Integer)); { Read index size }
  2479. GetMem(Index, IndexSize * SizeOf(TStrIndexRec)); { Allocate memory }
  2480. S.Read(Index^, IndexSize * SizeOf(TStrIndexRec)); { Read indexes }
  2481. END;
  2482. {--TStringList--------------------------------------------------------------}
  2483. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2484. {---------------------------------------------------------------------------}
  2485. DESTRUCTOR TStringList.Done;
  2486. BEGIN
  2487. FreeMem(Index, IndexSize * SizeOf(TStrIndexRec)); { Release memory }
  2488. END;
  2489. {--TStringList--------------------------------------------------------------}
  2490. { Get -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2491. {---------------------------------------------------------------------------}
  2492. FUNCTION TStringList.Get (Key: Sw_Word): String;
  2493. VAR I: Word; S: String;
  2494. BEGIN
  2495. S := ''; { Preset empty string }
  2496. If (IndexSize>0) Then Begin { We must have strings }
  2497. I := 0; { First entry }
  2498. While (I<IndexSize) AND (S='') Do Begin
  2499. If ((Key - Index^[I].Key)<Index^[I].Count) { Diff less than count }
  2500. Then ReadStr(S, Index^[I].Offset,
  2501. Key-Index^[I].Key); { Read the string }
  2502. Inc(I); { Next entry }
  2503. End;
  2504. End;
  2505. Get := S; { Return empty string }
  2506. END;
  2507. {***************************************************************************}
  2508. { TStringList PRIVATE METHODS }
  2509. {***************************************************************************}
  2510. {--TStringLis---------------------------------------------------------------}
  2511. { ReadStr -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2512. {---------------------------------------------------------------------------}
  2513. PROCEDURE TStringList.ReadStr (Var S: String; Offset, Skip: Longint);
  2514. BEGIN
  2515. Stream^.Seek(BasePos + Offset); { Seek to position }
  2516. Inc(Skip); { Adjust skip }
  2517. Repeat
  2518. Stream^.Read(S[0], 1); { Read string size }
  2519. Stream^.Read(S[1], Ord(S[0])); { Read string data }
  2520. Dec(Skip); { One string read }
  2521. Until (Skip = 0);
  2522. END;
  2523. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2524. { TStrListMaker OBJECT METHODS }
  2525. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2526. {--TStrListMaker------------------------------------------------------------}
  2527. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2528. {---------------------------------------------------------------------------}
  2529. CONSTRUCTOR TStrListMaker.Init (AStrSize, AIndexSize: Sw_Word);
  2530. BEGIN
  2531. Inherited Init; { Call ancestor }
  2532. StrSize := AStrSize; { Hold size }
  2533. IndexSize := AIndexSize; { Hold index size }
  2534. GetMem(Strings, AStrSize); { Allocate memory }
  2535. GetMem(Index, AIndexSize * SizeOf(TStrIndexRec)); { Allocate memory }
  2536. END;
  2537. {--TStrListMaker------------------------------------------------------------}
  2538. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2539. {---------------------------------------------------------------------------}
  2540. DESTRUCTOR TStrListMaker.Done;
  2541. BEGIN
  2542. FreeMem(Index, IndexSize * SizeOf(TStrIndexRec)); { Free index memory }
  2543. FreeMem(Strings, StrSize); { Free data memory }
  2544. END;
  2545. {--TStrListMaker------------------------------------------------------------}
  2546. { Put -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2547. {---------------------------------------------------------------------------}
  2548. PROCEDURE TStrListMaker.Put (Key: Sw_Word; S: String);
  2549. BEGIN
  2550. If (Cur.Count = 16) OR (Key <> Cur.Key + Cur.Count)
  2551. Then CloseCurrent; { Close current }
  2552. If (Cur.Count = 0) Then Begin
  2553. Cur.Key := Key; { Set key }
  2554. Cur.Offset := StrPos; { Set offset }
  2555. End;
  2556. Inc(Cur.Count); { Inc count }
  2557. Move(S, Strings^[StrPos], Length(S) + 1); { Move string data }
  2558. Inc(StrPos, Length(S) + 1); { Adjust position }
  2559. END;
  2560. {--TStrListMaker------------------------------------------------------------}
  2561. { Store -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2562. {---------------------------------------------------------------------------}
  2563. PROCEDURE TStrListMaker.Store (Var S: TStream);
  2564. BEGIN
  2565. CloseCurrent; { Close all current }
  2566. S.Write(StrPos, SizeOf(Word)); { Write position }
  2567. S.Write(Strings^, StrPos); { Write string data }
  2568. S.Write(IndexPos, SizeOf(Word)); { Write index position }
  2569. S.Write(Index^, IndexPos * SizeOf(TStrIndexRec)); { Write indexes }
  2570. END;
  2571. {***************************************************************************}
  2572. { TStrListMaker PRIVATE METHODS }
  2573. {***************************************************************************}
  2574. {--TStrListMaker------------------------------------------------------------}
  2575. { CloseCurrent -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2576. {---------------------------------------------------------------------------}
  2577. PROCEDURE TStrListMaker.CloseCurrent;
  2578. BEGIN
  2579. If (Cur.Count <> 0) Then Begin
  2580. Index^[IndexPos] := Cur; { Hold index position }
  2581. Inc(IndexPos); { Next index }
  2582. Cur.Count := 0; { Adjust count }
  2583. End;
  2584. END;
  2585. {***************************************************************************}
  2586. { INTERFACE ROUTINES }
  2587. {***************************************************************************}
  2588. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2589. { DYNAMIC STRING INTERFACE ROUTINES }
  2590. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2591. {---------------------------------------------------------------------------}
  2592. { NewStr -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  2593. {---------------------------------------------------------------------------}
  2594. FUNCTION NewStr (Const S: String): PString;
  2595. VAR P: PString;
  2596. BEGIN
  2597. If (S = '') Then P := Nil Else Begin { Return nil }
  2598. GetMem(P, Length(S) + 1); { Allocate memory }
  2599. If (P<>Nil) Then P^ := S; { Hold string }
  2600. End;
  2601. NewStr := P; { Return result }
  2602. END;
  2603. {---------------------------------------------------------------------------}
  2604. { DisposeStr -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  2605. {---------------------------------------------------------------------------}
  2606. PROCEDURE DisposeStr (P: PString);
  2607. BEGIN
  2608. If (P <> Nil) Then FreeMem(P, Length(P^) + 1); { Release memory }
  2609. END;
  2610. PROCEDURE SetStr(VAR p:pString; CONST s:STRING);
  2611. BEGIN
  2612. IF p<>NIL THEN
  2613. FreeMem(P, Length(P^) + 1);
  2614. GetMem(p,LENGTH(s)+1);
  2615. pSTRING(p)^ := s
  2616. END;
  2617. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2618. { STREAM INTERFACE ROUTINES }
  2619. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2620. {---------------------------------------------------------------------------}
  2621. { Abstract -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  2622. {---------------------------------------------------------------------------}
  2623. PROCEDURE Abstract;
  2624. BEGIN
  2625. RunError(211); { Abstract error }
  2626. END;
  2627. {---------------------------------------------------------------------------}
  2628. { RegisterObjects -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 02Sep97 LdB }
  2629. {---------------------------------------------------------------------------}
  2630. PROCEDURE RegisterObjects;
  2631. BEGIN
  2632. RegisterType(RCollection); { Register object }
  2633. RegisterType(RStringCollection); { Register object }
  2634. RegisterType(RStrCollection); { Register object }
  2635. END;
  2636. {---------------------------------------------------------------------------}
  2637. { RegisterType -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 02Sep97 LdB }
  2638. {---------------------------------------------------------------------------}
  2639. PROCEDURE RegisterType (Var S: TStreamRec);
  2640. VAR P: PStreamRec;
  2641. BEGIN
  2642. P := StreamTypes; { Current reg list }
  2643. While (P <> Nil) AND (P^.ObjType <> S.ObjType)
  2644. Do P := P^.Next; { Find end of chain }
  2645. If (P = Nil) AND (S.ObjType <> 0) Then Begin { Valid end found }
  2646. S.Next := StreamTypes; { Chain the list }
  2647. StreamTypes := @S; { We are now first }
  2648. End Else RegisterError; { Register the error }
  2649. END;
  2650. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2651. { GENERAL FUNCTION INTERFACE ROUTINES }
  2652. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2653. {---------------------------------------------------------------------------}
  2654. { LongMul -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 04Sep97 LdB }
  2655. {---------------------------------------------------------------------------}
  2656. FUNCTION LongMul (X, Y: Integer): LongInt;
  2657. BEGIN
  2658. LongMul:=Longint(X*Y);
  2659. END;
  2660. {---------------------------------------------------------------------------}
  2661. { LongDiv -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 04Sep97 LdB }
  2662. {---------------------------------------------------------------------------}
  2663. FUNCTION LongDiv (X: LongInt; Y: Integer): Integer;
  2664. BEGIN
  2665. LongDiv := Integer(X DIV Y);
  2666. END;
  2667. BEGIN
  2668. invalidhandle:=UnusedHandle;
  2669. END.
  2670. {
  2671. $Log$
  2672. Revision 1.24 2003-11-03 09:42:28 marco
  2673. * Peter's Cardinal<->Longint fixes patch
  2674. Revision 1.23 2003/10/25 23:43:59 hajny
  2675. * THandle in sysutils common using System.THandle
  2676. Revision 1.22 2003/09/16 15:57:33 peter
  2677. * sparc register typo
  2678. Revision 1.21 2003/08/21 22:17:13 olle
  2679. - removed parameter from fpc_iocheck
  2680. Revision 1.20 2003/07/08 21:21:33 peter
  2681. * 1.1 does not need to load esi
  2682. Revision 1.19 2003/06/05 14:45:56 peter
  2683. * use Windows THandle
  2684. Revision 1.18 2003/01/05 16:27:05 hajny
  2685. * PString inherited from System
  2686. Revision 1.17 2002/12/07 14:37:15 carl
  2687. - avoid warnings (add typecast)
  2688. Revision 1.16 2002/10/31 13:08:04 carl
  2689. * forgot to init P buffer variable = crash
  2690. Revision 1.15 2002/10/31 12:47:30 carl
  2691. * more compatibility fixes for objects unit
  2692. Revision 1.14 2002/10/30 22:44:44 carl
  2693. * Bugfix for error checking
  2694. - DosStreamError is no longer global (bugfix 2043)
  2695. Revision 1.13 2002/10/09 16:10:14 carl
  2696. - removed OS depedencies
  2697. Revision 1.12 2002/09/07 21:15:25 carl
  2698. - some cleanup (less ifdef)
  2699. Revision 1.11 2002/09/07 15:07:45 peter
  2700. * old logs removed and tabs fixed
  2701. Revision 1.10 2002/09/01 19:03:19 florian
  2702. + powerpc support added
  2703. Revision 1.9 2002/03/28 20:56:00 carl
  2704. - remove go32v1 support
  2705. }