objects.pp 134 KB

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