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 W, Bw: Longint; P: PByte;
  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 W: Longint;
  1462. P: PByte;
  1463. DosStreamError : Word;
  1464. BEGIN
  1465. if Status <> StOK then exit; { Exit if error }
  1466. If (Handle = InvalidHandle) Then Error(stWriteError, 103); { File not open }
  1467. If (LastMode=1) Then Flush; { Flush read buffer }
  1468. LastMode := 2; { Now set write mode }
  1469. P := @Buf; { Transfer address }
  1470. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1471. If (BufPtr=BufSize) Then Begin { Buffer is full }
  1472. BlockWrite(FileInfo, Buffer^, BufSize,W); { Write to file }
  1473. DosStreamError := IOResult;
  1474. If (DosStreamError<>0) OR (W<>BufSize) Then { We have an error }
  1475. If (DosStreamError=0) Then Error(stWriteError, 0) { Unknown write error }
  1476. Else Error(stError, DosStreamError); { Specific write error }
  1477. BufPtr := 0; { Reset BufPtr }
  1478. End;
  1479. If (Status=stOk) Then Begin { Status still okay }
  1480. W := BufSize - BufPtr; { Space in buffer }
  1481. If (Count < W) Then W := Count; { Transfer size }
  1482. Move(P^, Buffer^[BufPtr], W); { Data to buffer }
  1483. Dec(Count, W); { Reduce count }
  1484. Inc(BufPtr, W); { Advance buffer ptr }
  1485. Inc(P,W); { Transfer address }
  1486. Inc(Position, W); { Advance position }
  1487. If (Position > StreamSize) Then { File has expanded }
  1488. StreamSize := Position; { Update new size }
  1489. End;
  1490. End;
  1491. END;
  1492. {$IFDEF IO_CHECK_ON}
  1493. {$UNDEF IO_CHECK_ON}
  1494. {$I+}
  1495. {$ENDIF}
  1496. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1497. { TMemoryStream OBJECT METHODS }
  1498. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1499. {--TMemoryStream------------------------------------------------------------}
  1500. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1501. {---------------------------------------------------------------------------}
  1502. CONSTRUCTOR TMemoryStream.Init (ALimit: LongInt; ABlockSize: Word);
  1503. VAR W: Word;
  1504. BEGIN
  1505. Inherited Init; { Call ancestor }
  1506. If (ABlockSize=0) Then BlkSize := 8192 Else { Default blocksize }
  1507. BlkSize := ABlockSize; { Set blocksize }
  1508. If (ALimit = 0) Then W := 1 Else { At least 1 block }
  1509. W := (ALimit + BlkSize - 1) DIV BlkSize; { Blocks needed }
  1510. If NOT ChangeListSize(W) Then { Try allocate blocks }
  1511. Error(stInitError, 0); { Initialize error }
  1512. END;
  1513. {--TMemoryStream------------------------------------------------------------}
  1514. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1515. {---------------------------------------------------------------------------}
  1516. DESTRUCTOR TMemoryStream.Done;
  1517. BEGIN
  1518. ChangeListSize(0); { Release all memory }
  1519. Inherited Done; { Call ancestor }
  1520. END;
  1521. {--TMemoryStream------------------------------------------------------------}
  1522. { Truncate -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1523. {---------------------------------------------------------------------------}
  1524. PROCEDURE TMemoryStream.Truncate;
  1525. VAR W: Word;
  1526. BEGIN
  1527. If (Status=stOk) Then Begin { Check status okay }
  1528. If (Position = 0) Then W := 1 Else { At least one block }
  1529. W := (Position + BlkSize - 1) DIV BlkSize; { Blocks needed }
  1530. If ChangeListSize(W) Then StreamSize := Position { Set stream size }
  1531. Else Error(stError, 0); { Error truncating }
  1532. End;
  1533. END;
  1534. {--TMemoryStream------------------------------------------------------------}
  1535. { Read -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1536. {---------------------------------------------------------------------------}
  1537. PROCEDURE TMemoryStream.Read (Var Buf; Count: Longint);
  1538. VAR W, CurBlock, BlockPos: Word; Li: LongInt; P, Q: PByte;
  1539. BEGIN
  1540. If (Position + Count > StreamSize) Then { Insufficient data }
  1541. Error(stReadError, 0); { Read beyond end!!! }
  1542. P := @Buf; { Transfer address }
  1543. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1544. CurBlock := Position DIV BlkSize; { Current block }
  1545. { * REMARK * - Do not shorten this, result can be > 64K }
  1546. Li := CurBlock; { Transfer current block }
  1547. Li := Li * BlkSize; { Current position }
  1548. { * REMARK END * - Leon de Boer }
  1549. BlockPos := Position - Li; { Current position }
  1550. W := BlkSize - BlockPos; { Current block space }
  1551. If (W > Count) Then W := Count; { Adjust read size }
  1552. Q := BlkList^[CurBlock] + BlockPos; { Calc pointer }
  1553. Move(Q^, P^, W); { Move data to buffer }
  1554. Inc(Position, W); { Adjust position }
  1555. Inc(P, W);
  1556. Dec(Count, W); { Adjust count left }
  1557. End;
  1558. If (Count<>0) Then FillChar(P^, Count, #0); { Error clear buffer }
  1559. END;
  1560. {--TMemoryStream------------------------------------------------------------}
  1561. { Write -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1562. {---------------------------------------------------------------------------}
  1563. PROCEDURE TMemoryStream.Write (Var Buf; Count: Longint);
  1564. VAR
  1565. W, CurBlock, BlockPos: Word;
  1566. Li: LongInt;
  1567. P, Q: PByte;
  1568. BEGIN
  1569. If (Position + Count > MemSize) Then Begin { Expansion needed }
  1570. If (Position + Count = 0) Then W := 1 Else { At least 1 block }
  1571. W := (Position+Count+BlkSize-1) DIV BlkSize; { Blocks needed }
  1572. If NOT ChangeListSize(W) Then
  1573. Error(stWriteError, 0); { Expansion failed!!! }
  1574. End;
  1575. P := @Buf; { Transfer address }
  1576. While (Count>0) AND (Status=stOk) Do Begin { Check status & count }
  1577. CurBlock := Position DIV BlkSize; { Current segment }
  1578. { * REMARK * - Do not shorten this, result can be > 64K }
  1579. Li := CurBlock; { Transfer current block }
  1580. Li := Li * BlkSize; { Current position }
  1581. { * REMARK END * - Leon de Boer }
  1582. BlockPos := Position - Li; { Current position }
  1583. W := BlkSize - BlockPos; { Current block space }
  1584. If (W > Count) Then W := Count; { Adjust write size }
  1585. Q := BlkList^[CurBlock] + BlockPos; { Calc pointer }
  1586. Move(P^, Q^, W); { Transfer data }
  1587. Inc(Position, W); { Adjust position }
  1588. Inc(P, W);
  1589. Dec(Count, W); { Adjust count left }
  1590. If (Position > StreamSize) Then { File expanded }
  1591. StreamSize := Position; { Adjust stream size }
  1592. End;
  1593. END;
  1594. {***************************************************************************}
  1595. { TMemoryStream PRIVATE METHODS }
  1596. {***************************************************************************}
  1597. {--TMemoryStream------------------------------------------------------------}
  1598. { ChangeListSize -> Platforms DOS/DPMI/WIN/OS2 - Checked 19May96 LdB }
  1599. {---------------------------------------------------------------------------}
  1600. FUNCTION TMemoryStream.ChangeListSize (ALimit: Longint): Boolean;
  1601. VAR
  1602. I, W: Longint;
  1603. Li: LongInt;
  1604. P: PPointerArray;
  1605. OldVal : Boolean;
  1606. BEGIN
  1607. If (ALimit <> BlkCount) Then Begin { Change is needed }
  1608. ChangeListSize := False; { Preset failure }
  1609. If (ALimit > MaxPtrs) Then Exit; { To many blocks req }
  1610. If (ALimit <> 0) Then Begin { Create segment list }
  1611. Li := ALimit * SizeOf(Pointer); { Block array size }
  1612. If (MaxAvail > Li) Then Begin
  1613. GetMem(P, Li); { Allocate memory }
  1614. FillChar(P^, Li, #0); { Clear the memory }
  1615. End Else Begin
  1616. OldVal:=ReturnNilIfGrowHeapFails;
  1617. ReturnNilIfGrowHeapFails:=true;
  1618. GetMem(P,Li);
  1619. ReturnNilIfGrowHeapFails:=OldVal;
  1620. If P = Nil Then Exit;
  1621. FillChar(P^, Li, #0); { Clear the memory }
  1622. End; { Insufficient memory }
  1623. If (BlkCount <> 0) AND (BlkList <> Nil) Then { Current list valid }
  1624. If (BlkCount <= ALimit) Then Move(BlkList^,
  1625. P^, BlkCount * SizeOf(Pointer)) Else { Move whole old list }
  1626. Move(BlkList^, P^, Li); { Move partial list }
  1627. End Else P := Nil; { No new block list }
  1628. If (ALimit < BlkCount) Then { Shrink stream size }
  1629. For W := BlkCount-1 DownTo ALimit Do
  1630. FreeMem(BlkList^[W], BlkSize); { Release memory block }
  1631. If (P <> Nil) AND (ALimit > BlkCount) Then Begin { Expand stream size }
  1632. For W := BlkCount To ALimit-1 Do Begin
  1633. If (MaxAvail < BlkSize) Then Begin { Check enough memory }
  1634. OldVal:=ReturnNilIfGrowHeapFails;
  1635. ReturnNilIfGrowHeapFails:=true;
  1636. GetMem(P^[W],BlkSize);
  1637. ReturnNilIfGrowHeapFails:=OldVal;
  1638. If P = Nil Then Begin
  1639. For I := BlkCount To W-1 Do
  1640. FreeMem(P^[I], BlkSize); { Free mem allocated }
  1641. FreeMem(P, Li); { Release memory }
  1642. Exit;
  1643. End { Now exit }
  1644. End Else GetMem(P^[W], BlkSize); { Allocate memory }
  1645. End;
  1646. End;
  1647. If (BlkCount <> 0) AND (BlkList<>Nil) Then
  1648. FreeMem(BlkList, BlkCount * SizeOf(Pointer)); { Release old list }
  1649. BlkList := P; { Hold new block list }
  1650. BlkCount := ALimit; { Hold new count }
  1651. { * REMARK * - Do not shorten this, result can be > 64K }
  1652. MemSize := BlkCount; { Block count }
  1653. MemSize := MemSize * BlkSize; { Current position }
  1654. { * REMARK END * - Leon de Boer }
  1655. End;
  1656. ChangeListSize := True; { Successful }
  1657. END;
  1658. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1659. { TCollection OBJECT METHODS }
  1660. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1661. {--TCollection--------------------------------------------------------------}
  1662. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1663. {---------------------------------------------------------------------------}
  1664. CONSTRUCTOR TCollection.Init (ALimit, ADelta: Sw_Integer);
  1665. BEGIN
  1666. Inherited Init; { Call ancestor }
  1667. Delta := ADelta; { Set increment }
  1668. SetLimit(ALimit); { Set limit }
  1669. END;
  1670. {--TCollection--------------------------------------------------------------}
  1671. { Load -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1672. {---------------------------------------------------------------------------}
  1673. CONSTRUCTOR TCollection.Load (Var S: TStream);
  1674. VAR C, I: Sw_Integer;
  1675. BEGIN
  1676. If S.TPCompatible Then Begin
  1677. { I ignore endianness issues here. If endianness is different,
  1678. you can't expect binary compatible resources anyway. }
  1679. Count := 0; S.Read(Count, Sizeof(Word));
  1680. Limit := 0; S.Read(Limit, Sizeof(Word));
  1681. Delta := 0; S.Read(Delta, Sizeof(Word))
  1682. End
  1683. Else Begin
  1684. S.Read(Count, Sizeof(Count)); { Read count }
  1685. S.Read(Limit, Sizeof(Limit)); { Read limit }
  1686. S.Read(Delta, Sizeof(Delta)); { Read delta }
  1687. End;
  1688. Items := Nil; { Clear item pointer }
  1689. C := Count; { Hold count }
  1690. I := Limit; { Hold limit }
  1691. Count := 0; { Clear count }
  1692. Limit := 0; { Clear limit }
  1693. SetLimit(I); { Set requested limit }
  1694. Count := C; { Set count }
  1695. For I := 0 To C-1 Do AtPut(I, GetItem(S)); { Get each item }
  1696. END;
  1697. {--TCollection--------------------------------------------------------------}
  1698. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1699. {---------------------------------------------------------------------------}
  1700. DESTRUCTOR TCollection.Done;
  1701. BEGIN
  1702. FreeAll; { Free all items }
  1703. SetLimit(0); { Release all memory }
  1704. END;
  1705. {--TCollection--------------------------------------------------------------}
  1706. { At -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1707. {---------------------------------------------------------------------------}
  1708. FUNCTION TCollection.At (Index: Sw_Integer): Pointer;
  1709. BEGIN
  1710. If (Index < 0) OR (Index >= Count) Then Begin { Invalid index }
  1711. Error(coIndexError, Index); { Call error }
  1712. At := Nil; { Return nil }
  1713. End Else At := Items^[Index]; { Return item }
  1714. END;
  1715. {--TCollection--------------------------------------------------------------}
  1716. { IndexOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1717. {---------------------------------------------------------------------------}
  1718. FUNCTION TCollection.IndexOf (Item: Pointer): Sw_Integer;
  1719. VAR I: Sw_Integer;
  1720. BEGIN
  1721. If (Count>0) Then Begin { Count is positive }
  1722. For I := 0 To Count-1 Do { For each item }
  1723. If (Items^[I]=Item) Then Begin { Look for match }
  1724. IndexOf := I; { Return index }
  1725. Exit; { Now exit }
  1726. End;
  1727. End;
  1728. IndexOf := -1; { Return index }
  1729. END;
  1730. {--TCollection--------------------------------------------------------------}
  1731. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1732. {---------------------------------------------------------------------------}
  1733. FUNCTION TCollection.GetItem (Var S: TStream): Pointer;
  1734. BEGIN
  1735. GetItem := S.Get; { Item off stream }
  1736. END;
  1737. {--TCollection--------------------------------------------------------------}
  1738. { LastThat -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1739. {---------------------------------------------------------------------------}
  1740. FUNCTION TCollection.LastThat (Test: Pointer): Pointer;
  1741. VAR I: LongInt;
  1742. BEGIN
  1743. For I := Count DownTo 1 Do
  1744. Begin { Down from last item }
  1745. IF Boolean(Byte(Longint(CallPointerLocal(Test,PreviousFramePointer,Items^[I-1])))) THEN
  1746. Begin { Test each item }
  1747. LastThat := Items^[I-1]; { Return item }
  1748. Exit; { Now exit }
  1749. End;
  1750. End;
  1751. LastThat := Nil; { None passed test }
  1752. END;
  1753. {--TCollection--------------------------------------------------------------}
  1754. { FirstThat -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1755. {---------------------------------------------------------------------------}
  1756. FUNCTION TCollection.FirstThat (Test: Pointer): Pointer;
  1757. VAR I: LongInt;
  1758. BEGIN
  1759. For I := 1 To Count Do Begin { Up from first item }
  1760. IF Boolean(Byte(Longint(CallPointerLocal(Test,PreviousFramePointer,Items^[I-1])))) THEN
  1761. Begin { Test each item }
  1762. FirstThat := Items^[I-1]; { Return item }
  1763. Exit; { Now exit }
  1764. End;
  1765. End;
  1766. FirstThat := Nil; { None passed test }
  1767. END;
  1768. {--TCollection--------------------------------------------------------------}
  1769. { Pack -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1770. {---------------------------------------------------------------------------}
  1771. PROCEDURE TCollection.Pack;
  1772. VAR I, J: Sw_Integer;
  1773. BEGIN
  1774. I := 0; { Initialize dest }
  1775. J := 0; { Intialize test }
  1776. While (I<Count) AND (J<Limit) Do Begin { Check fully packed }
  1777. If (Items^[J]<>Nil) Then Begin { Found a valid item }
  1778. If (I<>J) Then Begin
  1779. Items^[I] := Items^[J]; { Transfer item }
  1780. Items^[J] := Nil; { Now clear old item }
  1781. End;
  1782. Inc(I); { One item packed }
  1783. End;
  1784. Inc(J); { Next item to test }
  1785. End;
  1786. If (I<Count) Then Count := I; { New packed count }
  1787. END;
  1788. {--TCollection--------------------------------------------------------------}
  1789. { FreeAll -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1790. {---------------------------------------------------------------------------}
  1791. PROCEDURE TCollection.FreeAll;
  1792. VAR I: Sw_Integer;
  1793. BEGIN
  1794. for I := Count-1 downto 0 do
  1795. FreeItem(At(I));
  1796. Count := 0; { Clear item count }
  1797. END;
  1798. {--TCollection--------------------------------------------------------------}
  1799. { DeleteAll -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1800. {---------------------------------------------------------------------------}
  1801. PROCEDURE TCollection.DeleteAll;
  1802. BEGIN
  1803. Count := 0; { Clear item count }
  1804. END;
  1805. {--TCollection--------------------------------------------------------------}
  1806. { Free -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1807. {---------------------------------------------------------------------------}
  1808. PROCEDURE TCollection.Free (Item: Pointer);
  1809. BEGIN
  1810. Delete(Item); { Delete from list }
  1811. FreeItem(Item); { Free the item }
  1812. END;
  1813. {--TCollection--------------------------------------------------------------}
  1814. { Insert -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1815. {---------------------------------------------------------------------------}
  1816. PROCEDURE TCollection.Insert (Item: Pointer);
  1817. BEGIN
  1818. AtInsert(Count, Item); { Insert item }
  1819. END;
  1820. {--TCollection--------------------------------------------------------------}
  1821. { Delete -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1822. {---------------------------------------------------------------------------}
  1823. PROCEDURE TCollection.Delete (Item: Pointer);
  1824. BEGIN
  1825. AtDelete(IndexOf(Item)); { Delete from list }
  1826. END;
  1827. {--TCollection--------------------------------------------------------------}
  1828. { AtFree -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1829. {---------------------------------------------------------------------------}
  1830. PROCEDURE TCollection.AtFree (Index: Sw_Integer);
  1831. VAR Item: Pointer;
  1832. BEGIN
  1833. Item := At(Index); { Retreive item ptr }
  1834. AtDelete(Index); { Delete item }
  1835. FreeItem(Item); { Free the item }
  1836. END;
  1837. {--TCollection--------------------------------------------------------------}
  1838. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1839. {---------------------------------------------------------------------------}
  1840. PROCEDURE TCollection.FreeItem (Item: Pointer);
  1841. VAR P: PObject;
  1842. BEGIN
  1843. P := PObject(Item); { Convert pointer }
  1844. If (P<>Nil) Then Dispose(P, Done); { Dispose of object }
  1845. END;
  1846. {--TCollection--------------------------------------------------------------}
  1847. { AtDelete -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1848. {---------------------------------------------------------------------------}
  1849. PROCEDURE TCollection.AtDelete (Index: Sw_Integer);
  1850. BEGIN
  1851. If (Index >= 0) AND (Index < Count) Then Begin { Valid index }
  1852. Dec(Count); { One less item }
  1853. If (Count>Index) Then Move(Items^[Index+1],
  1854. Items^[Index], (Count-Index)*Sizeof(Pointer)); { Shuffle items down }
  1855. End Else Error(coIndexError, Index); { Index error }
  1856. END;
  1857. {--TCollection--------------------------------------------------------------}
  1858. { ForEach -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1859. {---------------------------------------------------------------------------}
  1860. PROCEDURE TCollection.ForEach (Action: Pointer);
  1861. VAR I: LongInt;
  1862. BEGIN
  1863. For I := 1 To Count Do { Up from first item }
  1864. CallPointerLocal(Action,PreviousFramePointer,Items^[I-1]); { Call with each item }
  1865. END;
  1866. {--TCollection--------------------------------------------------------------}
  1867. { SetLimit -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1868. {---------------------------------------------------------------------------}
  1869. PROCEDURE TCollection.SetLimit (ALimit: Sw_Integer);
  1870. VAR
  1871. AItems: PItemList;
  1872. BEGIN
  1873. If (ALimit < Count) Then
  1874. ALimit := Count;
  1875. If (ALimit > MaxCollectionSize) Then
  1876. ALimit := MaxCollectionSize;
  1877. If (ALimit <> Limit) Then
  1878. Begin
  1879. If (ALimit = 0) Then
  1880. AItems := Nil
  1881. Else
  1882. Begin
  1883. GetMem(AItems, ALimit * SizeOf(Pointer));
  1884. If (AItems<>Nil) Then
  1885. FillChar(AItems^,ALimit * SizeOf(Pointer), #0);
  1886. End;
  1887. If (AItems<>Nil) OR (ALimit=0) Then
  1888. Begin
  1889. If (AItems <>Nil) AND (Items <> Nil) Then
  1890. Move(Items^, AItems^, Count*SizeOf(Pointer));
  1891. If (Limit <> 0) AND (Items <> Nil) Then
  1892. FreeMem(Items, Limit * SizeOf(Pointer));
  1893. end;
  1894. Items := AItems;
  1895. Limit := ALimit;
  1896. End;
  1897. END;
  1898. {--TCollection--------------------------------------------------------------}
  1899. { Error -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1900. {---------------------------------------------------------------------------}
  1901. PROCEDURE TCollection.Error (Code, Info: Integer);
  1902. BEGIN
  1903. RunError(212 - Code); { Run error }
  1904. END;
  1905. {--TCollection--------------------------------------------------------------}
  1906. { AtPut -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1907. {---------------------------------------------------------------------------}
  1908. PROCEDURE TCollection.AtPut (Index: Sw_Integer; Item: Pointer);
  1909. BEGIN
  1910. If (Index >= 0) AND (Index < Count) Then { Index valid }
  1911. Items^[Index] := Item { Put item in index }
  1912. Else Error(coIndexError, Index); { Index error }
  1913. END;
  1914. {--TCollection--------------------------------------------------------------}
  1915. { AtInsert -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1916. {---------------------------------------------------------------------------}
  1917. PROCEDURE TCollection.AtInsert (Index: Sw_Integer; Item: Pointer);
  1918. VAR I: Sw_Integer;
  1919. BEGIN
  1920. If (Index >= 0) AND (Index <= Count) Then Begin { Valid index }
  1921. If (Count=Limit) Then SetLimit(Limit+Delta); { Expand size if able }
  1922. If (Limit>Count) Then Begin
  1923. If (Index < Count) Then Begin { Not last item }
  1924. For I := Count-1 DownTo Index Do { Start from back }
  1925. Items^[I+1] := Items^[I]; { Move each item }
  1926. End;
  1927. Items^[Index] := Item; { Put item in list }
  1928. Inc(Count); { Inc count }
  1929. End Else Error(coOverflow, Index); { Expand failed }
  1930. End Else Error(coIndexError, Index); { Index error }
  1931. END;
  1932. {--TCollection--------------------------------------------------------------}
  1933. { Store -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1934. {---------------------------------------------------------------------------}
  1935. PROCEDURE TCollection.Store (Var S: TStream);
  1936. var
  1937. LimitWord, DeltaWord: Word;
  1938. PROCEDURE DoPutItem (P: Pointer);{$IFNDEF FPC}FAR;{$ENDIF}
  1939. BEGIN
  1940. PutItem(S, P); { Put item on stream }
  1941. END;
  1942. BEGIN
  1943. If S.TPCompatible Then Begin
  1944. { Check if it is safe to write in TP-compatible stream.
  1945. If Count is too big, signal an error.
  1946. If Limit or Delta are too big, write smaller values. }
  1947. If (Count > MaxTPCompatibleCollectionSize)
  1948. Then S.Error(stWriteError, 0)
  1949. Else Begin
  1950. S.Write(Count, Sizeof(Word));
  1951. if Limit > MaxTPCompatibleCollectionSize
  1952. then LimitWord := MaxTPCompatibleCollectionSize
  1953. else LimitWord := Limit;
  1954. S.Write(LimitWord, Sizeof(Word));
  1955. if Delta > MaxTPCompatibleCollectionSize
  1956. then DeltaWord := MaxTPCompatibleCollectionSize
  1957. else DeltaWord := Delta;
  1958. S.Write(DeltaWord, Sizeof(Word));
  1959. End
  1960. End
  1961. Else Begin
  1962. S.Write(Count, Sizeof(Count)); { Write count }
  1963. S.Write(Limit, Sizeof(Limit)); { Write limit }
  1964. S.Write(Delta, Sizeof(Delta)); { Write delta }
  1965. End;
  1966. ForEach(@DoPutItem); { Each item to stream }
  1967. END;
  1968. {--TCollection--------------------------------------------------------------}
  1969. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1970. {---------------------------------------------------------------------------}
  1971. PROCEDURE TCollection.PutItem (Var S: TStream; Item: Pointer);
  1972. BEGIN
  1973. S.Put(Item); { Put item on stream }
  1974. END;
  1975. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1976. { TSortedCollection OBJECT METHODS }
  1977. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  1978. {--TSortedCollection--------------------------------------------------------}
  1979. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1980. {---------------------------------------------------------------------------}
  1981. CONSTRUCTOR TSortedCollection.Init (ALimit, ADelta: Sw_Integer);
  1982. BEGIN
  1983. Inherited Init(ALimit, ADelta); { Call ancestor }
  1984. Duplicates := False; { Clear flag }
  1985. END;
  1986. {--TSortedCollection--------------------------------------------------------}
  1987. { Load -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1988. {---------------------------------------------------------------------------}
  1989. CONSTRUCTOR TSortedCollection.Load (Var S: TStream);
  1990. BEGIN
  1991. Inherited Load(S); { Call ancestor }
  1992. S.Read(Duplicates, SizeOf(Duplicates)); { Read duplicate flag }
  1993. END;
  1994. {--TSortedCollection--------------------------------------------------------}
  1995. { KeyOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  1996. {---------------------------------------------------------------------------}
  1997. FUNCTION TSortedCollection.KeyOf (Item: Pointer): Pointer;
  1998. BEGIN
  1999. KeyOf := Item; { Return item as key }
  2000. END;
  2001. {--TSortedCollection--------------------------------------------------------}
  2002. { IndexOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2003. {---------------------------------------------------------------------------}
  2004. FUNCTION TSortedCollection.IndexOf (Item: Pointer): Sw_Integer;
  2005. VAR I, J: Sw_Integer;
  2006. BEGIN
  2007. J := -1; { Preset result }
  2008. If Search(KeyOf(Item), I) Then Begin { Search for item }
  2009. If Duplicates Then { Duplicates allowed }
  2010. While (I < Count) AND (Item <> Items^[I]) Do
  2011. Inc(I); { Count duplicates }
  2012. If (I < Count) Then J := I; { Index result }
  2013. End;
  2014. IndexOf := J; { Return result }
  2015. END;
  2016. {--TSortedCollection--------------------------------------------------------}
  2017. { Compare -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2018. {---------------------------------------------------------------------------}
  2019. FUNCTION TSortedCollection.Compare (Key1, Key2: Pointer): Sw_Integer;
  2020. BEGIN
  2021. Abstract; { Abstract method }
  2022. Compare:=0;
  2023. END;
  2024. {--TSortedCollection--------------------------------------------------------}
  2025. { Search -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2026. {---------------------------------------------------------------------------}
  2027. FUNCTION TSortedCollection.Search (Key: Pointer; Var Index: Sw_Integer): Boolean;
  2028. VAR L, H, I, C: Sw_Integer;
  2029. BEGIN
  2030. Search := False; { Preset failure }
  2031. L := 0; { Start count }
  2032. H := Count - 1; { End count }
  2033. While (L <= H) Do Begin
  2034. I := (L + H) SHR 1; { Mid point }
  2035. C := Compare(KeyOf(Items^[I]), Key); { Compare with key }
  2036. If (C < 0) Then L := I + 1 Else Begin { Item to left }
  2037. H := I - 1; { Item to right }
  2038. If C = 0 Then Begin { Item match found }
  2039. Search := True; { Result true }
  2040. If NOT Duplicates Then L := I; { Force kick out }
  2041. End;
  2042. End;
  2043. End;
  2044. Index := L; { Return result }
  2045. END;
  2046. {--TSortedCollection--------------------------------------------------------}
  2047. { Insert -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2048. {---------------------------------------------------------------------------}
  2049. PROCEDURE TSortedCollection.Insert (Item: Pointer);
  2050. VAR I: Sw_Integer;
  2051. BEGIN
  2052. If NOT Search(KeyOf(Item), I) OR Duplicates Then { Item valid }
  2053. AtInsert(I, Item); { Insert the item }
  2054. END;
  2055. {--TSortedCollection--------------------------------------------------------}
  2056. { Store -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2057. {---------------------------------------------------------------------------}
  2058. PROCEDURE TSortedCollection.Store (Var S: TStream);
  2059. BEGIN
  2060. TCollection.Store(S); { Call ancestor }
  2061. S.Write(Duplicates, SizeOf(Duplicates)); { Write duplicate flag }
  2062. END;
  2063. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2064. { TStringCollection OBJECT METHODS }
  2065. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2066. {--TStringCollection--------------------------------------------------------}
  2067. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2068. {---------------------------------------------------------------------------}
  2069. FUNCTION TStringCollection.GetItem (Var S: TStream): Pointer;
  2070. BEGIN
  2071. GetItem := S.ReadStr; { Get new item }
  2072. END;
  2073. {--TStringCollection--------------------------------------------------------}
  2074. { Compare -> Platforms DOS/DPMI/WIN/OS2 - Checked 21Aug97 LdB }
  2075. {---------------------------------------------------------------------------}
  2076. FUNCTION TStringCollection.Compare (Key1, Key2: Pointer): Sw_Integer;
  2077. VAR I, J: Sw_Integer; P1, P2: PString;
  2078. BEGIN
  2079. P1 := PString(Key1); { String 1 pointer }
  2080. P2 := PString(Key2); { String 2 pointer }
  2081. If (Length(P1^)<Length(P2^)) Then J := Length(P1^)
  2082. Else J := Length(P2^); { Shortest length }
  2083. I := 1; { First character }
  2084. While (I<J) AND (P1^[I]=P2^[I]) Do Inc(I); { Scan till fail }
  2085. If (I=J) Then Begin { Possible match }
  2086. { * REMARK * - Bug fix 21 August 1997 }
  2087. If (P1^[I]<P2^[I]) Then Compare := -1 Else { String1 < String2 }
  2088. If (P1^[I]>P2^[I]) Then Compare := 1 Else { String1 > String2 }
  2089. If (Length(P1^)>Length(P2^)) Then Compare := 1 { String1 > String2 }
  2090. Else If (Length(P1^)<Length(P2^)) Then { String1 < String2 }
  2091. Compare := -1 Else Compare := 0; { String1 = String2 }
  2092. { * REMARK END * - Leon de Boer }
  2093. End Else If (P1^[I]<P2^[I]) Then Compare := -1 { String1 < String2 }
  2094. Else Compare := 1; { String1 > String2 }
  2095. END;
  2096. {--TStringCollection--------------------------------------------------------}
  2097. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2098. {---------------------------------------------------------------------------}
  2099. PROCEDURE TStringCollection.FreeItem (Item: Pointer);
  2100. BEGIN
  2101. DisposeStr(Item); { Dispose item }
  2102. END;
  2103. {--TStringCollection--------------------------------------------------------}
  2104. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 22May96 LdB }
  2105. {---------------------------------------------------------------------------}
  2106. PROCEDURE TStringCollection.PutItem (Var S: TStream; Item: Pointer);
  2107. BEGIN
  2108. S.WriteStr(Item); { Write string }
  2109. END;
  2110. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2111. { TStrCollection OBJECT METHODS }
  2112. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2113. {--TStrCollection-----------------------------------------------------------}
  2114. { Compare -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2115. {---------------------------------------------------------------------------}
  2116. FUNCTION TStrCollection.Compare (Key1, Key2: Pointer): Sw_Integer;
  2117. VAR I, J: Sw_Integer; P1, P2: PByteArray;
  2118. BEGIN
  2119. P1 := PByteArray(Key1); { PChar 1 pointer }
  2120. P2 := PByteArray(Key2); { PChar 2 pointer }
  2121. I := 0; { Preset no size }
  2122. If (P1<>Nil) Then While (P1^[I]<>0) Do Inc(I); { PChar 1 length }
  2123. J := 0; { Preset no size }
  2124. If (P2<>Nil) Then While (P2^[J]<>0) Do Inc(J); { PChar 2 length }
  2125. If (I < J) Then J := I; { Shortest length }
  2126. I := 0; { First character }
  2127. While (I<J) AND (P1^[I]=P2^[I]) Do Inc(I); { Scan till fail }
  2128. If (P1^[I]=P2^[I]) Then Compare := 0 Else { Strings matched }
  2129. If (P1^[I]<P2^[I]) Then Compare := -1 Else { String1 < String2 }
  2130. Compare := 1; { String1 > String2 }
  2131. END;
  2132. {--TStrCollection-----------------------------------------------------------}
  2133. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2134. {---------------------------------------------------------------------------}
  2135. FUNCTION TStrCollection.GetItem (Var S: TStream): Pointer;
  2136. BEGIN
  2137. GetItem := S.StrRead; { Get string item }
  2138. END;
  2139. {--TStrCollection-----------------------------------------------------------}
  2140. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2141. {---------------------------------------------------------------------------}
  2142. PROCEDURE TStrCollection.FreeItem (Item: Pointer);
  2143. VAR I: Sw_Integer; P: PByteArray;
  2144. BEGIN
  2145. If (Item<>Nil) Then Begin { Item is valid }
  2146. P := PByteArray(Item); { Create byte pointer }
  2147. I := 0; { Preset no size }
  2148. While (P^[I]<>0) Do Inc(I); { Find PChar end }
  2149. FreeMem(Item, I+1); { Release memory }
  2150. End;
  2151. END;
  2152. {--TStrCollection-----------------------------------------------------------}
  2153. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2154. {---------------------------------------------------------------------------}
  2155. PROCEDURE TStrCollection.PutItem (Var S: TStream; Item: Pointer);
  2156. BEGIN
  2157. S.StrWrite(Item); { Write the string }
  2158. END;
  2159. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2160. { TUnSortedStrCollection OBJECT METHODS }
  2161. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2162. {--TUnSortedCollection------------------------------------------------------}
  2163. { Insert -> Platforms DOS/DPMI/WIN/OS2 - Checked 23May96 LdB }
  2164. {---------------------------------------------------------------------------}
  2165. PROCEDURE TUnSortedStrCollection.Insert (Item: Pointer);
  2166. BEGIN
  2167. AtInsert(Count, Item); { Insert - NO sorting }
  2168. END;
  2169. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2170. { TResourceItem RECORD }
  2171. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2172. TYPE
  2173. TResourceItem = packed RECORD
  2174. Posn: LongInt; { Resource position }
  2175. Size: LongInt; { Resource size }
  2176. Key : String; { Resource key }
  2177. End;
  2178. PResourceItem = ^TResourceItem;
  2179. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2180. { TResourceCollection OBJECT METHODS }
  2181. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2182. {--TResourceCollection------------------------------------------------------}
  2183. { KeyOf -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2184. {---------------------------------------------------------------------------}
  2185. FUNCTION TResourceCollection.KeyOf (Item: Pointer): Pointer;
  2186. BEGIN
  2187. KeyOf := @PResourceItem(Item)^.Key; { Pointer to key }
  2188. END;
  2189. {--TResourceCollection------------------------------------------------------}
  2190. { GetItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2191. {---------------------------------------------------------------------------}
  2192. FUNCTION TResourceCollection.GetItem (Var S: TStream): Pointer;
  2193. VAR B: Byte; Pos: Longint; Size: Longint; Ts: String; P: PResourceItem;
  2194. BEGIN
  2195. S.Read(Pos, SizeOf(Pos)); { Read position }
  2196. S.Read(Size, SizeOf(Size)); { Read size }
  2197. S.Read(B, 1); { Read key length }
  2198. GetMem(P, B + (SizeOf(TResourceItem) -
  2199. SizeOf(Ts) + 1)); { Allocate min memory }
  2200. If (P<>Nil) Then Begin { If allocate works }
  2201. P^.Posn := Pos; { Xfer position }
  2202. P^.Size := Size; { Xfer size }
  2203. P^.Key[0] := Char(B); { Xfer string length }
  2204. S.Read(P^.Key[1], B); { Xfer string data }
  2205. End;
  2206. GetItem := P; { Return pointer }
  2207. END;
  2208. {--TResourceCollection------------------------------------------------------}
  2209. { FreeItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2210. {---------------------------------------------------------------------------}
  2211. PROCEDURE TResourceCollection.FreeItem (Item: Pointer);
  2212. VAR Ts: String;
  2213. BEGIN
  2214. If (Item<>Nil) Then FreeMem(Item,
  2215. SizeOf(TResourceItem) - SizeOf(Ts) +
  2216. Length(PResourceItem(Item)^.Key) + 1); { Release memory }
  2217. END;
  2218. {--TResourceCollection------------------------------------------------------}
  2219. { PutItem -> Platforms DOS/DPMI/WIN/OS2 - Checked 24May96 LdB }
  2220. {---------------------------------------------------------------------------}
  2221. PROCEDURE TResourceCollection.PutItem (Var S: TStream; Item: Pointer);
  2222. VAR Ts: String;
  2223. BEGIN
  2224. If (Item<>Nil) Then S.Write(PResourceItem(Item)^,
  2225. SizeOf(TResourceItem) - SizeOf(Ts) +
  2226. Length(PResourceItem(Item)^.Key) + 1); { Write to stream }
  2227. END;
  2228. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2229. { PRIVATE RESOURCE MANAGER CONSTANTS }
  2230. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2231. CONST
  2232. RStreamMagic: LongInt = $52504246; { 'FBPR' }
  2233. RStreamBackLink: LongInt = $4C424246; { 'FBBL' }
  2234. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2235. { PRIVATE RESOURCE MANAGER TYPES }
  2236. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2237. TYPE
  2238. {$IFDEF NewExeFormat} { New EXE format }
  2239. TExeHeader = packed RECORD
  2240. eHdrSize: Word;
  2241. eMinAbove: Word;
  2242. eMaxAbove: Word;
  2243. eInitSS: Word;
  2244. eInitSP: Word;
  2245. eCheckSum: Word;
  2246. eInitPC: Word;
  2247. eInitCS: Word;
  2248. eRelocOfs: Word;
  2249. eOvlyNum: Word;
  2250. eRelocTab: Word;
  2251. eSpace: Array[1..30] of Byte;
  2252. eNewHeader: Word;
  2253. END;
  2254. {$ENDIF}
  2255. THeader = packed RECORD
  2256. Signature: Word;
  2257. Case Integer Of
  2258. 0: (
  2259. LastCount: Word;
  2260. PageCount: Word;
  2261. ReloCount: Word);
  2262. 1: (
  2263. InfoType: Word;
  2264. InfoSize: Longint);
  2265. End;
  2266. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2267. { TResourceFile OBJECT METHODS }
  2268. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2269. {--TResourceFile------------------------------------------------------------}
  2270. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2271. {---------------------------------------------------------------------------}
  2272. CONSTRUCTOR TResourceFile.Init(AStream: PStream);
  2273. VAR Found, Stop: Boolean; Header: THeader;
  2274. {$IFDEF NewExeFormat} ExeHeader: TExeHeader; {$ENDIF}
  2275. BEGIN
  2276. TObject.Init; { Initialize object }
  2277. Found := False; { Preset false }
  2278. If (AStream<>Nil) Then Begin
  2279. Stream := AStream; { Hold stream }
  2280. BasePos := Stream^.GetPos; { Get position }
  2281. Repeat
  2282. Stop := True; { Preset stop }
  2283. If (BasePos <= Stream^.GetSize-SizeOf(THeader))
  2284. Then Begin { Valid file header }
  2285. Stream^.Seek(BasePos); { Seek to position }
  2286. Stream^.Read(Header, SizeOf(THeader)); { Read header }
  2287. Case Header.Signature Of
  2288. {$IFDEF NewExeFormat} { New format file }
  2289. $5A4D: Begin
  2290. Stream^.Read(ExeHeader, SizeOf(TExeHeader));
  2291. BasePos := ExeHeader.eNewHeader; { Hold position }
  2292. Stop := False; { Clear stop flag }
  2293. End;
  2294. $454E: Begin
  2295. BasePos := Stream^.GetSize - 8; { Hold position }
  2296. Stop := False; { Clear stop flag }
  2297. End;
  2298. $4246: Begin
  2299. Stop := False; { Clear stop flag }
  2300. Case Header.Infotype Of
  2301. $5250: Begin { Found Resource }
  2302. Found := True; { Found flag is true }
  2303. Stop := True; { Set stop flag }
  2304. End;
  2305. $4C42: Dec(BasePos, Header.InfoSize-8);{ Found BackLink }
  2306. $4648: Dec(BasePos, SizeOf(THeader)*2);{ Found HelpFile }
  2307. Else Stop := True; { Set stop flag }
  2308. End;
  2309. End;
  2310. $424E: If Header.InfoType = $3230 { Found Debug Info }
  2311. Then Begin
  2312. Dec(BasePos, Header.InfoSize); { Adjust position }
  2313. Stop := False; { Clear stop flag }
  2314. End;
  2315. {$ELSE}
  2316. $5A4D: Begin
  2317. Inc(BasePos, LongInt(Header.PageCount)*512
  2318. - (-Header.LastCount AND 511)); { Calc position }
  2319. Stop := False; { Clear stop flag }
  2320. End;
  2321. $4246: If Header.InfoType = $5250 Then { Header was found }
  2322. Found := True Else Begin
  2323. Inc(BasePos, Header.InfoSize + 8); { Adjust position }
  2324. Stop := False; { Clear stop flag }
  2325. End;
  2326. {$ENDIF}
  2327. End;
  2328. End;
  2329. Until Stop; { Until flag is set }
  2330. End;
  2331. If Found Then Begin { Resource was found }
  2332. Stream^.Seek(BasePos + SizeOf(LongInt) * 2); { Seek to position }
  2333. Stream^.Read(IndexPos, SizeOf(LongInt)); { Read index position }
  2334. Stream^.Seek(BasePos + IndexPos); { Seek to resource }
  2335. Index.Load(Stream^); { Load resource }
  2336. End Else Begin
  2337. IndexPos := SizeOf(LongInt) * 3; { Set index position }
  2338. Index.Init(0, 8); { Set index }
  2339. End;
  2340. END;
  2341. {--TResourceFile------------------------------------------------------------}
  2342. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2343. {---------------------------------------------------------------------------}
  2344. DESTRUCTOR TResourceFile.Done;
  2345. BEGIN
  2346. Flush; { Flush the file }
  2347. Index.Done; { Dispose of index }
  2348. If (Stream<>Nil) Then Dispose(Stream, Done); { Dispose of stream }
  2349. END;
  2350. {--TResourceFile------------------------------------------------------------}
  2351. { Count -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2352. {---------------------------------------------------------------------------}
  2353. FUNCTION TResourceFile.Count: Sw_Integer;
  2354. BEGIN
  2355. Count := Index.Count; { Return index count }
  2356. END;
  2357. {--TResourceFile------------------------------------------------------------}
  2358. { KeyAt -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2359. {---------------------------------------------------------------------------}
  2360. FUNCTION TResourceFile.KeyAt (I: Sw_Integer): String;
  2361. BEGIN
  2362. KeyAt := PResourceItem(Index.At(I))^.Key; { Return key }
  2363. END;
  2364. {--TResourceFile------------------------------------------------------------}
  2365. { Get -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2366. {---------------------------------------------------------------------------}
  2367. FUNCTION TResourceFile.Get (Key: String): PObject;
  2368. VAR I: Sw_Integer;
  2369. BEGIN
  2370. If (Stream = Nil) OR (NOT Index.Search(@Key, I)) { No match on key }
  2371. Then Get := Nil Else Begin
  2372. Stream^.Seek(BasePos +
  2373. PResourceItem(Index.At(I))^.Posn); { Seek to position }
  2374. Get := Stream^.Get; { Get item }
  2375. End;
  2376. END;
  2377. {--TResourceFile------------------------------------------------------------}
  2378. { SwitchTo -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2379. {---------------------------------------------------------------------------}
  2380. FUNCTION TResourceFile.SwitchTo (AStream: PStream; Pack: Boolean): PStream;
  2381. VAR NewBasePos: LongInt;
  2382. PROCEDURE DoCopyResource (Item: PResourceItem);{$IFNDEF FPC}FAR;{$ENDIF}
  2383. BEGIN
  2384. Stream^.Seek(BasePos + Item^.Posn); { Move stream position }
  2385. Item^.Posn := AStream^.GetPos - NewBasePos; { Hold new position }
  2386. AStream^.CopyFrom(Stream^, Item^.Size); { Copy the item }
  2387. END;
  2388. BEGIN
  2389. SwitchTo := Stream; { Preset return }
  2390. If (AStream<>Nil) AND (Stream<>Nil) Then Begin { Both streams valid }
  2391. NewBasePos := AStream^.GetPos; { Get position }
  2392. If Pack Then Begin
  2393. AStream^.Seek(NewBasePos + SizeOf(LongInt)*3); { Seek to position }
  2394. Index.ForEach(@DoCopyResource); { Copy each resource }
  2395. IndexPos := AStream^.GetPos - NewBasePos; { Hold index position }
  2396. End Else Begin
  2397. Stream^.Seek(BasePos); { Seek to position }
  2398. AStream^.CopyFrom(Stream^, IndexPos); { Copy the resource }
  2399. End;
  2400. Stream := AStream; { Hold new stream }
  2401. BasePos := NewBasePos; { New base position }
  2402. Modified := True; { Set modified flag }
  2403. End;
  2404. END;
  2405. {--TResourceFile------------------------------------------------------------}
  2406. { Flush -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2407. {---------------------------------------------------------------------------}
  2408. PROCEDURE TResourceFile.Flush;
  2409. VAR ResSize: LongInt; LinkSize: LongInt;
  2410. BEGIN
  2411. If (Modified) AND (Stream<>Nil) Then Begin { We have modification }
  2412. Stream^.Seek(BasePos + IndexPos); { Seek to position }
  2413. Index.Store(Stream^); { Store the item }
  2414. ResSize := Stream^.GetPos - BasePos; { Hold position }
  2415. LinkSize := ResSize + SizeOf(LongInt) * 2; { Hold link size }
  2416. Stream^.Write(RStreamBackLink, SizeOf(LongInt)); { Write link back }
  2417. Stream^.Write(LinkSize, SizeOf(LongInt)); { Write link size }
  2418. Stream^.Seek(BasePos); { Move stream position }
  2419. Stream^.Write(RStreamMagic, SizeOf(LongInt)); { Write number }
  2420. Stream^.Write(ResSize, SizeOf(LongInt)); { Write record size }
  2421. Stream^.Write(IndexPos, SizeOf(LongInt)); { Write index position }
  2422. Stream^.Flush; { Flush the stream }
  2423. End;
  2424. Modified := False; { Clear modified flag }
  2425. END;
  2426. {--TResourceFile------------------------------------------------------------}
  2427. { Delete -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2428. {---------------------------------------------------------------------------}
  2429. PROCEDURE TResourceFile.Delete (Key: String);
  2430. VAR I: Sw_Integer;
  2431. BEGIN
  2432. If Index.Search(@Key, I) Then Begin { Search for key }
  2433. Index.Free(Index.At(I)); { Delete from index }
  2434. Modified := True; { Set modified flag }
  2435. End;
  2436. END;
  2437. {--TResourceFile------------------------------------------------------------}
  2438. { Put -> Platforms DOS/DPMI/WIN/OS2 - Checked 18Jun96 LdB }
  2439. {---------------------------------------------------------------------------}
  2440. PROCEDURE TResourceFile.Put (Item: PObject; Key: String);
  2441. VAR I: Sw_Integer; Ts: String; P: PResourceItem;
  2442. BEGIN
  2443. If (Stream=Nil) Then Exit; { Stream not valid }
  2444. If Index.Search(@Key, I) Then P := Index.At(I) { Search for item }
  2445. Else Begin
  2446. GetMem(P, Length(Key) + (SizeOf(TResourceItem) -
  2447. SizeOf(Ts) + 1)); { Allocate memory }
  2448. If (P<>Nil) Then Begin
  2449. P^.Key := Key; { Store key }
  2450. Index.AtInsert(I, P); { Insert item }
  2451. End;
  2452. End;
  2453. If (P<>Nil) Then Begin
  2454. P^.Posn := IndexPos; { Set index position }
  2455. Stream^.Seek(BasePos + IndexPos); { Seek file position }
  2456. Stream^.Put(Item); { Put item on stream }
  2457. IndexPos := Stream^.GetPos - BasePos; { Hold index position }
  2458. P^.Size := IndexPos - P^.Posn; { Calc size }
  2459. Modified := True; { Set modified flag }
  2460. End;
  2461. END;
  2462. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2463. { TStringList OBJECT METHODS }
  2464. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2465. {--TStringList--------------------------------------------------------------}
  2466. { Load -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2467. {---------------------------------------------------------------------------}
  2468. CONSTRUCTOR TStringList.Load (Var S: TStream);
  2469. VAR Size: Word;
  2470. BEGIN
  2471. Stream := @S; { Hold stream pointer }
  2472. S.Read(Size, SizeOf(Word)); { Read size }
  2473. BasePos := S.GetPos; { Hold position }
  2474. S.Seek(BasePos + Size); { Seek to position }
  2475. S.Read(IndexSize, SizeOf(Integer)); { Read index size }
  2476. GetMem(Index, IndexSize * SizeOf(TStrIndexRec)); { Allocate memory }
  2477. S.Read(Index^, IndexSize * SizeOf(TStrIndexRec)); { Read indexes }
  2478. END;
  2479. {--TStringList--------------------------------------------------------------}
  2480. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2481. {---------------------------------------------------------------------------}
  2482. DESTRUCTOR TStringList.Done;
  2483. BEGIN
  2484. FreeMem(Index, IndexSize * SizeOf(TStrIndexRec)); { Release memory }
  2485. END;
  2486. {--TStringList--------------------------------------------------------------}
  2487. { Get -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2488. {---------------------------------------------------------------------------}
  2489. FUNCTION TStringList.Get (Key: Sw_Word): String;
  2490. VAR I: Word; S: String;
  2491. BEGIN
  2492. S := ''; { Preset empty string }
  2493. If (IndexSize>0) Then Begin { We must have strings }
  2494. I := 0; { First entry }
  2495. While (I<IndexSize) AND (S='') Do Begin
  2496. If ((Key - Index^[I].Key)<Index^[I].Count) { Diff less than count }
  2497. Then ReadStr(S, Index^[I].Offset,
  2498. Key-Index^[I].Key); { Read the string }
  2499. Inc(I); { Next entry }
  2500. End;
  2501. End;
  2502. Get := S; { Return empty string }
  2503. END;
  2504. {***************************************************************************}
  2505. { TStringList PRIVATE METHODS }
  2506. {***************************************************************************}
  2507. {--TStringLis---------------------------------------------------------------}
  2508. { ReadStr -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2509. {---------------------------------------------------------------------------}
  2510. PROCEDURE TStringList.ReadStr (Var S: String; Offset, Skip: Longint);
  2511. BEGIN
  2512. Stream^.Seek(BasePos + Offset); { Seek to position }
  2513. Inc(Skip); { Adjust skip }
  2514. Repeat
  2515. Stream^.Read(S[0], 1); { Read string size }
  2516. Stream^.Read(S[1], Ord(S[0])); { Read string data }
  2517. Dec(Skip); { One string read }
  2518. Until (Skip = 0);
  2519. END;
  2520. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2521. { TStrListMaker OBJECT METHODS }
  2522. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2523. {--TStrListMaker------------------------------------------------------------}
  2524. { Init -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2525. {---------------------------------------------------------------------------}
  2526. CONSTRUCTOR TStrListMaker.Init (AStrSize, AIndexSize: Sw_Word);
  2527. BEGIN
  2528. Inherited Init; { Call ancestor }
  2529. StrSize := AStrSize; { Hold size }
  2530. IndexSize := AIndexSize; { Hold index size }
  2531. GetMem(Strings, AStrSize); { Allocate memory }
  2532. GetMem(Index, AIndexSize * SizeOf(TStrIndexRec)); { Allocate memory }
  2533. END;
  2534. {--TStrListMaker------------------------------------------------------------}
  2535. { Done -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2536. {---------------------------------------------------------------------------}
  2537. DESTRUCTOR TStrListMaker.Done;
  2538. BEGIN
  2539. FreeMem(Index, IndexSize * SizeOf(TStrIndexRec)); { Free index memory }
  2540. FreeMem(Strings, StrSize); { Free data memory }
  2541. END;
  2542. {--TStrListMaker------------------------------------------------------------}
  2543. { Put -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2544. {---------------------------------------------------------------------------}
  2545. PROCEDURE TStrListMaker.Put (Key: Sw_Word; S: String);
  2546. BEGIN
  2547. If (Cur.Count = 16) OR (Key <> Cur.Key + Cur.Count)
  2548. Then CloseCurrent; { Close current }
  2549. If (Cur.Count = 0) Then Begin
  2550. Cur.Key := Key; { Set key }
  2551. Cur.Offset := StrPos; { Set offset }
  2552. End;
  2553. Inc(Cur.Count); { Inc count }
  2554. Move(S, Strings^[StrPos], Length(S) + 1); { Move string data }
  2555. Inc(StrPos, Length(S) + 1); { Adjust position }
  2556. END;
  2557. {--TStrListMaker------------------------------------------------------------}
  2558. { Store -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2559. {---------------------------------------------------------------------------}
  2560. PROCEDURE TStrListMaker.Store (Var S: TStream);
  2561. BEGIN
  2562. CloseCurrent; { Close all current }
  2563. S.Write(StrPos, SizeOf(Word)); { Write position }
  2564. S.Write(Strings^, StrPos); { Write string data }
  2565. S.Write(IndexPos, SizeOf(Word)); { Write index position }
  2566. S.Write(Index^, IndexPos * SizeOf(TStrIndexRec)); { Write indexes }
  2567. END;
  2568. {***************************************************************************}
  2569. { TStrListMaker PRIVATE METHODS }
  2570. {***************************************************************************}
  2571. {--TStrListMaker------------------------------------------------------------}
  2572. { CloseCurrent -> Platforms DOS/DPMI/WIN/OS2 - Checked 30Jun97 LdB }
  2573. {---------------------------------------------------------------------------}
  2574. PROCEDURE TStrListMaker.CloseCurrent;
  2575. BEGIN
  2576. If (Cur.Count <> 0) Then Begin
  2577. Index^[IndexPos] := Cur; { Hold index position }
  2578. Inc(IndexPos); { Next index }
  2579. Cur.Count := 0; { Adjust count }
  2580. End;
  2581. END;
  2582. {***************************************************************************}
  2583. { INTERFACE ROUTINES }
  2584. {***************************************************************************}
  2585. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2586. { DYNAMIC STRING INTERFACE ROUTINES }
  2587. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2588. {---------------------------------------------------------------------------}
  2589. { NewStr -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  2590. {---------------------------------------------------------------------------}
  2591. FUNCTION NewStr (Const S: String): PString;
  2592. VAR P: PString;
  2593. BEGIN
  2594. If (S = '') Then P := Nil Else Begin { Return nil }
  2595. GetMem(P, Length(S) + 1); { Allocate memory }
  2596. If (P<>Nil) Then P^ := S; { Hold string }
  2597. End;
  2598. NewStr := P; { Return result }
  2599. END;
  2600. {---------------------------------------------------------------------------}
  2601. { DisposeStr -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  2602. {---------------------------------------------------------------------------}
  2603. PROCEDURE DisposeStr (P: PString);
  2604. BEGIN
  2605. If (P <> Nil) Then FreeMem(P, Length(P^) + 1); { Release memory }
  2606. END;
  2607. PROCEDURE SetStr(VAR p:pString; CONST s:STRING);
  2608. BEGIN
  2609. IF p<>NIL THEN
  2610. FreeMem(P, Length(P^) + 1);
  2611. GetMem(p,LENGTH(s)+1);
  2612. pSTRING(p)^ := s
  2613. END;
  2614. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2615. { STREAM INTERFACE ROUTINES }
  2616. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2617. {---------------------------------------------------------------------------}
  2618. { Abstract -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 12Jun96 LdB }
  2619. {---------------------------------------------------------------------------}
  2620. PROCEDURE Abstract;
  2621. BEGIN
  2622. RunError(211); { Abstract error }
  2623. END;
  2624. {---------------------------------------------------------------------------}
  2625. { RegisterObjects -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 02Sep97 LdB }
  2626. {---------------------------------------------------------------------------}
  2627. PROCEDURE RegisterObjects;
  2628. BEGIN
  2629. RegisterType(RCollection); { Register object }
  2630. RegisterType(RStringCollection); { Register object }
  2631. RegisterType(RStrCollection); { Register object }
  2632. END;
  2633. {---------------------------------------------------------------------------}
  2634. { RegisterType -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 02Sep97 LdB }
  2635. {---------------------------------------------------------------------------}
  2636. PROCEDURE RegisterType (Var S: TStreamRec);
  2637. VAR P: PStreamRec;
  2638. BEGIN
  2639. P := StreamTypes; { Current reg list }
  2640. While (P <> Nil) AND (P^.ObjType <> S.ObjType)
  2641. Do P := P^.Next; { Find end of chain }
  2642. If (P = Nil) AND (S.ObjType <> 0) Then Begin { Valid end found }
  2643. S.Next := StreamTypes; { Chain the list }
  2644. StreamTypes := @S; { We are now first }
  2645. End Else RegisterError; { Register the error }
  2646. END;
  2647. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2648. { GENERAL FUNCTION INTERFACE ROUTINES }
  2649. {+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++}
  2650. {---------------------------------------------------------------------------}
  2651. { LongMul -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 04Sep97 LdB }
  2652. {---------------------------------------------------------------------------}
  2653. FUNCTION LongMul (X, Y: Integer): LongInt;
  2654. BEGIN
  2655. LongMul:=Longint(X*Y);
  2656. END;
  2657. {---------------------------------------------------------------------------}
  2658. { LongDiv -> Platforms DOS/DPMI/WINDOWS/OS2 - Checked 04Sep97 LdB }
  2659. {---------------------------------------------------------------------------}
  2660. FUNCTION LongDiv (X: LongInt; Y: Integer): Integer;
  2661. BEGIN
  2662. LongDiv := Integer(X DIV Y);
  2663. END;
  2664. BEGIN
  2665. invalidhandle:=UnusedHandle;
  2666. END.
  2667. {
  2668. $Log$
  2669. Revision 1.25 2003-11-03 17:46:37 peter
  2670. * fixed crash in bufstream.write
  2671. Revision 1.24 2003/11/03 09:42:28 marco
  2672. * Peter's Cardinal<->Longint fixes patch
  2673. Revision 1.23 2003/10/25 23:43:59 hajny
  2674. * THandle in sysutils common using System.THandle
  2675. Revision 1.22 2003/09/16 15:57:33 peter
  2676. * sparc register typo
  2677. Revision 1.21 2003/08/21 22:17:13 olle
  2678. - removed parameter from fpc_iocheck
  2679. Revision 1.20 2003/07/08 21:21:33 peter
  2680. * 1.1 does not need to load esi
  2681. Revision 1.19 2003/06/05 14:45:56 peter
  2682. * use Windows THandle
  2683. Revision 1.18 2003/01/05 16:27:05 hajny
  2684. * PString inherited from System
  2685. Revision 1.17 2002/12/07 14:37:15 carl
  2686. - avoid warnings (add typecast)
  2687. Revision 1.16 2002/10/31 13:08:04 carl
  2688. * forgot to init P buffer variable = crash
  2689. Revision 1.15 2002/10/31 12:47:30 carl
  2690. * more compatibility fixes for objects unit
  2691. Revision 1.14 2002/10/30 22:44:44 carl
  2692. * Bugfix for error checking
  2693. - DosStreamError is no longer global (bugfix 2043)
  2694. Revision 1.13 2002/10/09 16:10:14 carl
  2695. - removed OS depedencies
  2696. Revision 1.12 2002/09/07 21:15:25 carl
  2697. - some cleanup (less ifdef)
  2698. Revision 1.11 2002/09/07 15:07:45 peter
  2699. * old logs removed and tabs fixed
  2700. Revision 1.10 2002/09/01 19:03:19 florian
  2701. + powerpc support added
  2702. Revision 1.9 2002/03/28 20:56:00 carl
  2703. - remove go32v1 support
  2704. }