home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / sys / next / programm / 5296 < prev    next >
Encoding:
Text File  |  1992-07-28  |  1.8 KB  |  83 lines

  1. Newsgroups: comp.sys.next.programmer
  2. Path: sparky!uunet!paladin.american.edu!europa.asd.contel.com!darwin.sura.net!Sirius.dfn.de!zrz.tu-berlin.de!cs.tu-berlin.de!marcel
  3. From: marcel@opal.cs.tu-berlin.de (Marcel Weiher)
  4. Subject: Re: Getting ids of Outlets of an object
  5. Message-ID: <1992Jul28.174149.15452@cs.tu-berlin.de>
  6. Keywords: outlets, object
  7. Sender: news@cs.tu-berlin.de
  8. Organization: Techn. University of Berlin, Germany
  9. References: <1992Jul28.053907.9425@viman.com>
  10. Distribution: fb20
  11. Date: Tue, 28 Jul 1992 17:41:49 GMT
  12. Lines: 69
  13.  
  14. vikram@viman.com  (Vikram Duvvoori) writes:
  15.  
  16.  
  17. >Hi, 
  18. >    We are interested in developing some general tools that can  
  19. >dynamically access the various outlets of instances of other objects at  
  20. >run-time.
  21. [...]
  22. >Appkit, to determine the tags for the outlets of the instance variables. Are  
  23. >there any methods that give you information on the instance variables and list  
  24. >of methods for an object?
  25.  
  26. One of the neat things about Objective-C is that it is so dynamic, and yes
  27. it even retains structure information at runtime.
  28.  
  29. Look in the include file <objc/objc-class.h>, with a little
  30. code to illustrate:
  31.  
  32. ------------------------snip----------------------------
  33. mport <objc/Object.h>
  34. #import <objc/objc-class.h>
  35.  
  36. @interface Hi : Object
  37. {
  38.     int hi1;
  39.     int hi2;
  40. }
  41.  
  42. @end
  43.  
  44. @implementation Hi
  45.  
  46. -printIVars
  47. {
  48.     Hi*   s1=self;
  49.     struct objc_ivar_list  *iv=s1->isa->ivars;
  50.     struct objc_ivar *p1;
  51.     int i;
  52.  
  53.     p1=&iv->ivar_list;
  54.     for (i=0; i< iv->ivar_count ; i++ )
  55.     {
  56.         printf( "name= %s, type=%s, offset=%d\n",p1->ivar_name,p1->ivar_type,p1->ivar_offset);
  57.         p1++;
  58.     }
  59. }
  60.  
  61.  
  62. main()
  63. {
  64.     id hi=[Hi new];
  65.     [hi printIVars];
  66. }
  67.  
  68.  
  69. @end
  70.  
  71. --------------------------snip----------------------
  72.  
  73. This produces the following output on my system:
  74.  
  75. marcel@spock[benchmarks]ivar
  76. name= hi1, type=i, offset=4
  77. name= hi2, type=i, offset=8
  78. marcel@spock[benchmarks]
  79.  
  80.  
  81. Marcel
  82.  
  83.