objects.pas 161 KB

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