Generic objects

Description

Generic object types are not any particular object type, but are instead any object type associated with an instance of an object created with the built-in function createobject. Currently createobject can only create instances of COM objects, and only those COM objects which support late-binding (i.e. the COM objects must export the IDISPATCH interface, or in other words the COM objects must be OLE automation servers).

Example

Below is a simple program that uses two generic object references objExplorer and app to access some of the COM objects exposes by Internet Explorer, and to start Internet Explorer and navigate to the IrieTools website.

   program Explorer;
   var
      objExplorer : object;
      app : object;
   begin
      objExplorer := CreateObject('InternetExplorer.Application');
      app := objExplorer.application;
      app.navigate('http://www.irietools.com', 1, , ,);
      app.quit;
      dispose(app);
      dispose(objExplorer);
   end.

Below is a more useful example program that illustrates how to send an email using the CDONTS.NewMail COM object that is installed with Microsoft IIS. You can use a similiar program to send email if your webserver uses IIS.

   program cdonts;
   const
      NORMAL = 1;
   var 
      objMail : object;
      FromAddress, ToAddress : string;
   begin
      write('Enter the from address:');
      readln(FromAddress);
      write('Enter the to address:');
      readln(ToAddress);
      objMail := CreateObject('CDONTS.NewMail');
      objMail.from := FromAddress;
      objMail.('to') := ToAddress;
      objMail.subject := 'Testing...';
      objMail.Body := 'This is a test message';
      objMail.Importance := NORMAL;
      objMail.Send( , , , , );
      dispose(objMail);
   end.

The program could also be simplified as follows

   program cdonts;
   const
      NORMAL = 1;
   var
      objMail : object;
      FromAddress, ToAddress : string;
   begin
      write('Enter the from address:');
      readln(FromAddress);
      write('Enter the to address:');
      readln(ToAddress);
      objMail := CreateObject('CDONTS.NewMail');
      objMail.Send(FromAddress, ToAddress, 'Testing...', 'This is a test message', NORMAL);
      dispose(objMail);
   end.

Syntax

The syntax for defining a new generic object type is given below:

   object-type = 'object' | 'class'

The keywords object and class can be used interchangably for now, however in later versions of Irie Pascal, which will more fully support Object Pascal, these keywords may produce slightly different effects. There appears to be two specifications for Object Pascal. The first specification is simplier and uses the keyword object and appears to be most popular on the Apple Mac. While the second specification is more sophisticated and uses the keyword class. Later versions of Irie Pascal may attempt to support both specifications of Object Pascal.