classes.inc 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. {
  2. $Id$
  3. This file is part of the Free Component Library (FCL)
  4. Copyright (c) 1998 by Michael Van Canneyt and Florian Klaempfl
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. {****************************************************************************}
  12. {* TBits *}
  13. {****************************************************************************}
  14. procedure TBits.Error;
  15. begin
  16. {$ifdef NoExceptions}
  17. ;
  18. {$else}
  19. Raise(EBitsError);
  20. {$endif}
  21. end;
  22. procedure TBits.SetSize(Value: Integer);
  23. var
  24. hp : pointer;
  25. cvalue,csize : Integer;
  26. begin
  27. { ajust value to n*8 }
  28. cvalue:=Value;
  29. if cvalue mod 8<>0 then
  30. cvalue:=cvalue+(8-(cvalue mod 8));
  31. { store pointer to release it later }
  32. hp:=FBits;
  33. { ajust size to n*8 }
  34. csize:=FSize;
  35. if csize mod 8<>0 then
  36. csize:=csize+(8-(csize mod 8));
  37. if FSize>0 then
  38. begin
  39. { get new memory }
  40. GetMem(FBits,cvalue div 8);
  41. { clear the whole array }
  42. FillChar(FBits^,cvalue div 8,0);
  43. { copy old data }
  44. Move(hp^,FBits^,csize div 8);
  45. end
  46. else
  47. FBits:=nil;
  48. if assigned(hp) then
  49. FreeMem(hp,csize div 8);
  50. FSize:=Value;
  51. end;
  52. procedure TBits.SetBit(Index: Integer; Value: Boolean);
  53. type
  54. pbyte = ^byte;
  55. begin
  56. if (Index>=FSize) or (Index<0) then
  57. Error
  58. else
  59. begin
  60. if Value then
  61. pbyte(FBits)[Index div 8]:=pbyte(FBits)[Index div 8] or
  62. (1 shl (Index mod 8))
  63. else
  64. pbyte(FBits)[Index div 8]:=pbyte(FBits)[Index div 8] and
  65. not(1 shl (Index mod 8));
  66. end;
  67. end;
  68. function TBits.GetBit(Index: Integer): Boolean;
  69. type
  70. pbyte = ^byte;
  71. begin
  72. if (Index>=FSize) or (Index<0) then
  73. Error
  74. else
  75. GetBit:=(pbyte(FBits)[Index div 8] and (1 shl (Index mod 8)))<>0;
  76. end;
  77. destructor TBits.Destroy;
  78. var
  79. csize : Integer;
  80. begin
  81. { ajust size to n*8 }
  82. csize:=FSize;
  83. if csize mod 8<>0 then
  84. csize:=csize+(8-(csize mod 8));
  85. if assigned(FBits) then
  86. FreeMem(FBits,csize);
  87. inherited Destroy;
  88. end;
  89. function TBits.OpenBit: Integer;
  90. type
  91. pbyte = ^byte;
  92. var
  93. i : Integer;
  94. begin
  95. for i:=0 to FSize-1 do
  96. if (pbyte(FBits)[i div 8] and (1 shl (i mod 8)))=0 then
  97. begin
  98. OpenBit:=i;
  99. exit;
  100. end;
  101. SetSize(FSize+1);
  102. OpenBit:=FSize-1;
  103. end;
  104. {****************************************************************************}
  105. {* TStream *}
  106. {****************************************************************************}
  107. function TStream.GetPosition: Longint;
  108. begin
  109. GetPosition:=Seek(0,soFromCurrent);
  110. end;
  111. procedure TStream.SetPosition(Pos: Longint);
  112. begin
  113. Seek(soFromBeginning,Pos);
  114. end;
  115. function TStream.GetSize: Longint;
  116. var
  117. p : longint;
  118. begin
  119. p:=GetPosition;
  120. GetSize:=Seek(soFromEnd,0);
  121. Seek(soFromBeginning,p);
  122. end;
  123. procedure TStream.SetSize(NewSize: Longint);
  124. begin
  125. SetPosition(NewSize);
  126. end;
  127. procedure TStream.ReadBuffer(var Buffer; Count: Longint);
  128. begin
  129. if Read(Buffer,Count)<Count then
  130. {$ifdef NoExceptions}
  131. ;
  132. {$else}
  133. Raise(EReadError);
  134. {$endif}
  135. end;
  136. procedure TStream.WriteBuffer(const Buffer; Count: Longint);
  137. begin
  138. if Write(Buffer,Count)<Count then
  139. {$ifdef NoExceptions}
  140. ;
  141. {$else}
  142. Raise(EWriteError);
  143. {$endif}
  144. end;
  145. function TStream.CopyFrom(Source: TStream; Count: Longint): Longint;
  146. var
  147. i : longint;
  148. buffer : array[0..1023] of byte;
  149. begin
  150. CopyFrom:=0;
  151. while Count>0 do
  152. begin
  153. if (Count>sizeof(buffer)) then
  154. i:=sizeof(Buffer)
  155. else
  156. i:=Count;
  157. i:=Source.Read(buffer,i);
  158. i:=Write(buffer,i);
  159. dec(count,i);
  160. CopyFrom:=CopyFrom+i;
  161. if i=0 then
  162. exit;
  163. end;
  164. end;
  165. function TStream.ReadComponent(Instance: TComponent): TComponent;
  166. var
  167. Reader : TReader;
  168. begin
  169. Reader.Create(Self,1024);
  170. if assigned(Instance) then
  171. ReadComponent:=Reader.ReadRootComponent(Instance)
  172. else
  173. begin
  174. {!!!!!}
  175. end;
  176. Reader.Destroy;
  177. end;
  178. function TStream.ReadComponentRes(Instance: TComponent): TComponent;
  179. begin
  180. {!!!!!}
  181. end;
  182. procedure TStream.WriteComponent(Instance: TComponent);
  183. var
  184. Writer : TWriter;
  185. begin
  186. Writer.Create(Self,1024);
  187. Writer.WriteRootComponent(Instance);
  188. Writer.Destroy;
  189. end;
  190. procedure TStream.WriteComponentRes(const ResName: string; Instance: TComponent);
  191. var
  192. startpos,s : longint;
  193. begin
  194. (*
  195. {$ifdef Win16Res}
  196. { Numeric resource type }
  197. WriteByte($ff);
  198. { Application defined data }
  199. WriteWord($0a);
  200. { write the name as asciiz }
  201. WriteData(ResName[1],length(ResName));
  202. WriteByte(0);
  203. { Movable, Pure and Discardable }
  204. WriteWord($1030);
  205. { size isn't known yet }
  206. WriteDWord(0);
  207. startpos:=GetPosition;
  208. WriteComponent(Instance);
  209. { calculate size }
  210. s:=GetPosition-startpos;
  211. { back patch size }
  212. SetPosition(startpos-4);
  213. WriteDWord(s);
  214. {$endif Win16Res}
  215. *)
  216. end;
  217. procedure TStream.WriteDescendent(Instance, Ancestor: TComponent);
  218. begin
  219. {!!!!!}
  220. end;
  221. procedure TStream.WriteDescendentRes(const ResName: string; Instance, Ancestor: TComponent);
  222. begin
  223. {!!!!!}
  224. end;
  225. procedure TStream.ReadResHeader;
  226. begin
  227. {$ifdef Win16Res}
  228. try
  229. { application specific resource ? }
  230. if ReadByte<>$ff then
  231. raise EInvalidImage;
  232. if ReadWord<>$000a then
  233. raise EInvalidImage;
  234. { read name }
  235. while ReadByte<>0 do
  236. ;
  237. { check the access specifier }
  238. if ReadWord<>$1030 then
  239. raise EInvalidImage;
  240. { ignore the size }
  241. ReadDWord;
  242. except
  243. {/////
  244. on EInvalidImage do
  245. raise;
  246. else
  247. raise(EInvalidImage);
  248. }
  249. end;
  250. {$endif Win16Res}
  251. end;
  252. function TStream.ReadByte : Byte;
  253. var
  254. b : Byte;
  255. begin
  256. ReadBuffer(b,1);
  257. ReadByte:=b;
  258. end;
  259. function TStream.ReadWord : Word;
  260. var
  261. w : Word;
  262. begin
  263. ReadBuffer(w,2);
  264. ReadWord:=w;
  265. end;
  266. function TStream.ReadDWord : Cardinal;
  267. var
  268. d : Cardinal;
  269. begin
  270. ReadBuffer(d,4);
  271. ReadDWord:=d;
  272. end;
  273. procedure TStream.WriteByte(b : Byte);
  274. begin
  275. WriteBuffer(b,1);
  276. end;
  277. procedure TStream.WriteWord(w : Word);
  278. begin
  279. WriteBuffer(w,2);
  280. end;
  281. procedure TStream.WriteDWord(d : Cardinal);
  282. begin
  283. WriteBuffer(d,4);
  284. end;
  285. {****************************************************************************}
  286. {* TList *}
  287. {****************************************************************************}
  288. { TList = class(TObject)
  289. private
  290. FList: PPointerList;
  291. FCount: Integer;
  292. FCapacity: Integer;
  293. }
  294. function TList.Get(Index: Integer): Pointer;
  295. begin
  296. end;
  297. procedure TList.Grow;
  298. begin
  299. end;
  300. procedure TList.Put(Index: Integer; Item: Pointer);
  301. begin
  302. end;
  303. procedure TList.SetCapacity(NewCapacity: Integer);
  304. begin
  305. end;
  306. procedure TList.SetCount(NewCount: Integer);
  307. begin
  308. end;
  309. destructor TList.Destroy;
  310. begin
  311. Clear;
  312. inherited Destroy;
  313. end;
  314. Function TList.Add(Item: Pointer): Integer;
  315. begin
  316. Self.Insert (Count,Item);
  317. end;
  318. Procedure TList.Clear;
  319. begin
  320. end;
  321. Procedure TList.Delete(Index: Integer);
  322. begin
  323. end;
  324. class procedure Error(const Msg: string; Data: Integer);
  325. begin
  326. end;
  327. procedure TList.Exchange(Index1, Index2: Integer);
  328. begin
  329. end;
  330. function TList.Expand: TList;
  331. begin
  332. end;
  333. function TList.First: Pointer;
  334. begin
  335. end;
  336. function TList.IndexOf(Item: Pointer): Integer;
  337. begin
  338. end;
  339. procedure TList.Insert(Index: Integer; Item: Pointer);
  340. begin
  341. end;
  342. function TList.Last: Pointer;
  343. begin
  344. end;
  345. procedure TList.Move(CurIndex, NewIndex: Integer);
  346. begin
  347. end;
  348. function TList.Remove(Item: Pointer): Integer;
  349. begin
  350. end;
  351. procedure TList.Pack;
  352. begin
  353. end;
  354. procedure TList.Sort(Compare: TListSortCompare);
  355. begin
  356. end;
  357. {
  358. $Log$
  359. Revision 1.1 1998-05-04 12:16:01 florian
  360. + Initial revisions after making a new directory structure
  361. }