objects.pp 135 KB

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