objects.pp 131 KB

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