Home > Community > Forums > Custom IC SKILL > create a table inside the class

Email

* Required Fields

Recipients email * (separate multiple addresses with commas)

Your name *

Your email *

Message *

Contact Us

* Required Fields
First Name *

Last Name *

Email *

Company / Institution *

Comments: *

 create a table inside the class 

Last post Wed, Dec 19 2012 11:07 AM by skillseeker. 2 replies.
Started by skillseeker 19 Dec 2012 09:16 AM. Topic has 2 replies and 611 views
Page 1 of 1 (3 items)
Sort Posts:
  • Wed, Dec 19 2012 9:16 AM

    create a table inside the class Reply

    Hi,

    I would like to create a table for each instance of a class. How best to do it. If i define "makeTable" inside a defclass it gives me an error.

     defclass( pinInfo
        ()
        (
         ( pinName   @initarg pinName )
         ( pinType   @initarg pinType )
         ( netName   @initarg netName )

         PinTable = makeTable("aTable1" 0)

         tablep(PinTable)
        )

      );defclass

    I get an error when i define it like this "*Error* slotValue: no such slot - PinTable.

    Thanks

    • Post Points: 20
  • Wed, Dec 19 2012 9:35 AM

    Re: create a table inside the class Reply

    You can't just stick arbitrary code inside a class definition - you could either do it with an @initform:

    defclass(pinInfo
      ()
       (
        (pinName @initarg pinName)
        (pinType @initarg pinType)
        (netName @initarg netName)
        (pinTable @initform makeTable("aTable1" 0))
       )
    )

    Then:

    > a=makeInstance('pinInfo)
    stdobj@0x8564018
    > a->pinTable
    table:aTable1
    > a->pinTable["hello"]=23
    23
    > a->pinTable->??
    ("hello" 23)

    Or you could define an initializeInstance method:

    defclass(pinInfo
      ()
       (
        (pinName @initarg pinName)
        (pinType @initarg pinType)
        (netName @initarg netName)
        (pinTable)
       )
    )

    defmethod(initializeInstance @after ((obj pinInfo))
      obj->pinTable=makeTable("aTable1" 0)
    )

    Note that the second approach only works in IC615 onwards. You could use a non-@after method, but then you'd have to make sure you call callNextMethod() appropriately to ensure that any parent objects have a chance to initialize too. The @after directive tells it to call all the other @after methods, least-specific first.The intention for initializeInstance is to handle complex initialization of objects which can't be coded via the @initform (e.g. interdependencies of the arguments).

    Regards,

    Andrew.

    • Post Points: 5
  • Wed, Dec 19 2012 11:07 AM

    RE: create a table inside the class Reply
    Thanks Andrew appreciate your help. I will use the first method suggested.

    Thanks

    Devender Poreddy
    • Post Points: 5
Page 1 of 1 (3 items)
Sort Posts:
Started by skillseeker at 19 Dec 2012 09:16 AM. Topic has 2 replies.