objects.pp 135 KB

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