objects.pp 136 KB

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