xobjects.pas 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. unit xobjects;
  2. {
  3. $Id$
  4. Copyright (c) 2000 by Daniel Mantione
  5. member of the Free Pascal development team
  6. This unit provides an extends the Tobject type with additional methods
  7. to check the type of an object. It should only be used within
  8. Turbo Pascal, the Free Pascal objects unit already contains this
  9. functionality.
  10. This program is free software; you can redistribute it and/or modify
  11. it under the terms of the GNU General Public License as published by
  12. the Free Software Foundation; either version 2 of the License, or
  13. (at your option) any later version.
  14. This program is distributed in the hope that it will be useful,
  15. but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. GNU General Public License for more details.
  18. You should have received a copy of the GNU General Public License
  19. along with this program; if not, write to the Free Software
  20. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. ****************************************************************************
  22. }
  23. interface
  24. {As TP does not store a link to the parent's VMT in the VMT, a function like
  25. is_object would be impossible.
  26. We use a very dirty trick to get it done; in an objects constructor the
  27. setparent procedure should be called, which stores the link to the parent
  28. into the DMT link. (!!!)}
  29. uses objects;
  30. type Pobject=^Tobject;
  31. Tobject=object(objects.Tobject)
  32. function is_object(typ:pointer):boolean;
  33. procedure setparent(typ:pointer);
  34. end;
  35. implementation
  36. type vmt=record
  37. size,negsize:word;
  38. dmtlink:pointer;
  39. end;
  40. function Tobject.is_object(typ:pointer):boolean;assembler;
  41. asm
  42. les di,self
  43. mov bx,[es:di] {Get vmt link.}
  44. jmp @a3
  45. @a2:
  46. mov bx,[bx+4] {Get dmt link, offset.}
  47. or bx,bx
  48. mov al,0
  49. jz @a1
  50. @a3:
  51. cmp bx,typ.word {Compare with typ.}
  52. jne @a2
  53. mov al,1
  54. @a1:
  55. end;
  56. procedure Tobject.setparent(typ:pointer);assembler;
  57. asm
  58. les di,self
  59. mov bx,[es:di] {Get vmt link.}
  60. mov ax,typ.word
  61. mov cx,typ+2.word
  62. mov [bx+4],ax
  63. mov [bx+6],cx
  64. end;
  65. end.