objects.pp 138 KB

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