objects.pp 134 KB

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