2
0

objects.pp 136 KB

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