objects.pp 136 KB

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