CLASS/END CLASS Block  

Purpose

Create the code and data for an object.

Syntax

CLASS name  [$GUID]  [AS COM | AS EVENT]
  Class Method code blocks...
  INSTANCE ClassName AS STRING
  INTERFACE name $GUID  [AS EVENT]
    INHERIT IUNKNOWN
    Method and Property code blocks...

  END INTERFACE
  EVENT SOURCE interface-name
END CLASS

Remarks

CLASS / END CLASS statements enclose the Interface implementation(s)  and Instance variable declarations of a Class.  METHOD and PROPERTY blocks contain the code to be executed on an object.  INSTANCE statements define the variables which are unique to each instance of an object of this class.

The name and optional $GUID are supplied by the programmer to identify the class.  By default, a class is considered private, so that the methods are accessible only from within the EXE or DLL where it is defined.  The AS COM attribute makes the class available externally, to virtually any process which is COM-aware.

With a private class, the $GUID may be freely omitted, as PowerBASIC can readily identify the class by name.  With a published COM class, you should insert a specific GUID of your choice.  If omitted, a  random GUID will be created by the compiler, but it will change every time you compile the program.  This will be difficult to synchronize with other programs which wish to identify and access your object.

If a class is an Event Source (it generates events rather than handling events), one or more EVENT SOURCE statements are included to name the event interfaces.  The event interfaces must be declared and implemented separately.  An event is generated by executing a RAISEEVENT statement in the class. If a class is an Event Handler (it contains code to handle an event generated by an Event Source), the AS EVENT attribute must appear on the CLASS statement and each INTERFACE statement.  An Event Handler is also known as an "Event Sink".

See also

EVENTS, INSTANCE, INTERFACE (Direct), INTERFACE (IDBind),  Just what is COM?, METHOD, PROPERTY, RAISEEVENT, What is an object, anyway?