Please enable JavaScript to view this site.

DAQFactory User's Guide

Navigation: 5 Sequences & Scripting > 5.20 Object Oriented Programming

5.20.12 OnCreate / OnDestroy

Scroll Prev Top Next More

There are also two built in functions you can use to initialize and de-initialize your object.   If you have a member function called OnCreate(), it will be called when the object is first instantiated (i.e. when new() is called with your class).  If you have a member function called OnDestroy(), it will be called when the last reference to your object is lost and your object is deleted.  So, you might do:

 

class Person

  local string name

  local string address

  local string zip

  function PrintMe()

    ? name

    ? address

    ? zip

  endfunction 

  function OnCreate()

    name = "Not Entered"

    address = "Not Entered"

    zip = "Not Entered"

  endfunction

  function OnDestroy()

    ? name + " has been destroyed!"

  endfunction

endclass

Unlike C++ and other OOP languages, if your class is derived from other classes, the OnCreate() and OnDestroy() functions are only called on the class that is created.  The parent's OnCreate() and OnDestroy() functions are not called automatically.  If you want to call them, simply use the parent keyword: parent.OnCreate() or parent.OnDestroy() from within the appropriate function.