TweetFollow Us on Twitter

REALbasic Plugin

Volume Number: 15 (1999)
Issue Number: 10
Column Tag: Programming

REALbasic Plug-in Programming

by Erick J. Tejkowski

Extend REALbasic to suit your needs

Introduction

REALbasic is an object-oriented, Basic-flavored, rapid application development environment. With it you can build and compile Macintosh and Windows applications. The environment comes complete with numerous classes, objects, properties, and methods for the programmer to use. Many different aspects of Mac/PC programming are included in the REALbasic environment, for example windows, QuickTime, sockets, and threads to name a few. Sometimes, however, your application requires something that REALbasic cannot provide. To gain this functionality, the programmer has to tap other resources. For example, REALbasic allows the inclusion of Applescripts, Hypercard XCMDs, and shared libraries. Furthermore, REALbasic can also be expanded with the use of native plugins. In this article, we will examine the methods used in developing plugins for REALbasic using Metrowerks CodeWarrior.

To begin, we will prepare the compiler for REALbasic plugins. Then, we are on to coding. In the first code example, we will examine some sample code for a method-based plugin. The second example will look at code for a basic custom control. Finally, we will wrap it up by including some discussion on the potential uses of REALbasic plugins.

The Setup

A REALbasic plugin is a code resource. It can come in 68K or PPC flavors, but unless your plugin requires some specific speed enhancements or other PPC specific code, most people prefer to make 68K versions, as this allows everyone to take advantage of the plugin. There are also some specific differences between REALbasic 1 and 2 versions of plugins. For this article, we will only consider REALbasic 2 plugins, as it is the most current release, but most of the information will pertain to REALbasic 1 plugin development, although there are some distinct differences. Interestingly, some REALbasic 1 plugins work with REALbasic 2, but never vice versa.

Since the plugin is a code resource, CodeWarrior needs some special adjustments before we can begin work on our first REALbasic plugin. To begin, create a folder named MyRBPlugin. To this folder add the file named PluginMain.cpp and the folder entitled Includes. These can be found in the REALbasic plugin SDK on REALsoftware's web site. See the Bibliography for more information. Next, launch CodeWarrior and create a new project with the MacOS:C_C++:MacOSToolbox:68K stationery. Uncheck the Create Folder check box. Name the project MyPlug.pi (option-p) and put it in your MyRBPlugin folder. Remove the SillyBalls.c, and SillyBalls.rsrc files.

Select New from the File menu and create a new document. Save it in your MyRBPlugin folder with the name MySource.cpp. Select Add Window from the Project menu, which will add MySource.cpp to your project. Select Add Files... from the Project menu and add the PluginMain.cpp file you copied to your folder earlier. Your project should resemble Figure 1.


Figure 1.MyPlug.pi project window..

Your project target might not look exactly the same as Figure 1. Your target might be named Mac OS Toolbox DEBUG 68K instead of plugin68k. To change this, you need to make some changes to the preference settings. It just so happens that this is also where code resource settings are made. This leads us to our next step.

Open the Project Settings dialog from the Edit menu. Select the Target Settings in the Target submenu. Change the Target Name to plugin68k. Next, select the Access Paths item. Select User Paths and click the Add button. Choose the folder entitled Includes that you copied to your project folder earlier. Now, select 68K Target and name your plugin. Name it myPlugin68K. Make sure that Code Resource is selected from the Project popup menu. Change the Creator to SfTg, the Type to RBPl, the ResType to PL68, and the ResID to 128. Figure 2 recaps the 68K Target settings.


Figure 2.68K Target Settings.

Finally, in the 68K Processor settings, check the following checkboxes: 68020 Codegen, MPW C Calling Conventions, 4-Byte Ints, and 8-Byte Doubles. Click the Save button and relink the project if necessary.

Additional Resources

These settings will work for both code examples to be discussed later. To build the custom control in Listing 2, though, one more step is required. A control in REALbasic also needs some additional resources. Start your favorite resource editor and create a new file named MyRsrc.rsrc. To this file, add a 'PICT' resource with an ID of 128. This is the unselected appearance of the control on the REALbasic toolbar. A 'PICT' resource with an ID of 129 is the selected appearance of the control (i.e. the appearance as the control is dragged to a window). Both of these resources should have pixel dimensions of 28 wide by 24 high to appear properly in the REALbasic toolbar. In addition to the required 'PICT' resources, our control is going to make use of some icon resources. These icon resources will be used to draw the custom switch we are going to create.

Add a resource of type 'icl8' with a high number, to avoid collisions with REALbasic's own resources. For our example use 1280. This is the appearance of the switch when used in a REALbasic application. Draw whatever you would like here or use the resource example available on the MacTech web site. This resource will be the "off" position. Since we are using an icon here, the dimensions are 32 wide by 32 high. Once you have completed the artwork for your switch, drag the 'icl8' to the 'ICN#' and 'icl4' boxes on the right. You need not worry about the other sizes, as they are not important for this example. Since we are building a toggle style switch as our custom control, you will also need to add another icon resource. This resource will be the "on" position. Create it just as you created the "off" position, but give it a number of 1290. An example resource file might look something like Figure 3.


Figure 3.An Example Switch and Its Associated Icons.

In addition to the icon resources, REALbasic plugins require you to indicate which user-defined resources will be used in the control. To do this, you must create a 'PLRm' resource, which lists all of the accessory resources you will use. To enter the data for 'PLRm' resources, you must first make a copy of the necessary 'TMPL' resource. The template resource can be found in the REALbasic plugin SDK or by opening a copy of REALbasic itself. Once this 'TMPL' resource has been added to your file, you can proceed to add the necessary 'PLRm' resources. When creating PLRm resources, the first entry is the four-letter signature for the particular resource you are adding. The second entry is the resource number you will be using. More info on this topic is also available in the SDK. Figure 4 shows what the 'PLRm' resource looks like for our project.


Figure 4.The ‘PLRm’ resource.

Once you have added these extra resources, save the file. We will come back to it later in the article when we build the custom control. Your plugin environment is now set. On to programming!

Source Code

Our first example is going to perform three functions. It will convert an integer to Roman numerals and vice versa as well as convert an integer to an ordinal number. MySource.cpp begins with a few #includes necessary for our plugin and functions called within our plugin. You will also notice some structs, which will be used later in the code.

#include "rb_plugin.h"
#include <string.h>
#include <stdio.h>
#include <ctype.h>

//for Roman numerals
struct numeral {
      long val;
      int  ch;
};

static struct numeral numerals[] = {
      {    1L, 'I' },
      {    5L, 'V' },
      {   10L, 'X' },
      {   50L, 'L' },
      {  100L, 'C' },
      {  500L, 'D' },
      { 1000L, 'M' }
};

// for ordinals
static char *text[] = {"th", "st", "nd", "rd"};

Next, we do something a little unusual; we jump to the end of the source code. This is where the structure of the plugin is defined. The PluginEntry registers all of the methods and controls for your plugin. Be sure to add the letters "defn" to the end of each method you are registering.

void PluginEntry(void)
{
	REALRegisterMethod(&ConvertToOrdinaldefn);
	REALRegisterMethod(&IntegerToRomandefn);
	REALRegisterMethod(&RomanToIntegerdefn);
}

Continuing to follow the code in a backward direction, you will notice the REALMethodDefinition for each of the functions described in the PluginEntry. These are descriptions of the functions, as they will be used within REALbasic itself and the corresponding function in our source code file.

REALmethodDefinition ConvertToOrdinaldefn = {
	(REALproc) ConvertToOrdinalfunc,
	REALnoImplementation,
	"ConvertToOrdinal(i as integer) as string"
};

REALmethodDefinition IntegerToRomandefn = {
	(REALproc) IntegerToRomanfunc,
	REALnoImplementation,
	"IntegerToRoman(i as integer) as string"
};

REALmethodDefinition RomanToIntegerdefn = {
	(REALproc) RomanToIntegerfunc,
	REALnoImplementation,
	"RomanToInteger(s as string) as integer"
};

Finally, we code our functions. The functions look like typical C/C++ functions, except that they sometimes have strangely named data types. An integer can be used as a parameter to your function (ConvertToOrdinalfunc and IntegerToRomanfunc) or as a return value (RomanToIntegerfunc). Strings being the weird birds that they are in C/C++ get special treatment when used in REALbasic plugins. If a string is to be used as a parameter to a function, you simply typecast the variable to a REALstring type. Should you wish to return a string, you must first define the return type as REALstring. Then, at the end of the function where you would like to return the string back to REALbasic, use REALBuildString with a character array and its length as parameters. As usual, a glance at the source code will help explain things much better than words can.

//Integer to Ordinal
static REALstring ConvertToOrdinalfunc( int number)
{
  if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
            number = 0;
      
  return REALBuildString(text[number], strlen(text[number]));
}  

// Integer to Roman numerals
static REALstring IntegerToRomanfunc(int value)
{
  int dvalue;
    char roman[80];
    roman[0] = '\0';

    dvalue = value;
    while( value >= 1000 )
    {
        strcat( roman, "M" );
        value -= 1000;
    }
    if( value >= 900 )
    {
        strcat( roman, "CM" );
        value -= 900;
    }
    while( value >= 500 )
    {
        strcat( roman, "D" );
        value -= 500;
    }
    if( value >= 400 )
    {
        strcat( roman, "CD" );
        value -= 400;
    }
    while( value >= 100 )
    {
        strcat( roman, "C" );
        value -= 100;
    }
    if( value >= 90 )
    {
        strcat( roman, "XC" );
        value -= 90;
    }
    while( value >= 50 )
    {
        strcat( roman, "L" );
        value -= 50;
    }
    if( value >= 40 )
    {
        strcat( roman, "XL" );
        value -= 40;
    }
    while( value >= 10 )
    {
        strcat( roman, "X" );
        value -= 10;
    }
    if( value >= 9 )
    {
        strcat( roman, "IX" );
        value -= 9;
    }
    while( value >= 5 )
    {
        strcat( roman, "V" );
        value -= 5;
    }
    if( value >= 4 )
    {
        strcat( roman, "IV" );
        value -= 4;
    }
    while( value > 0 )
    {
        strcat( roman, "I" );
        value-;
    }
 
    return REALBuildString(roman, strlen(roman));
    	
}

// Roman numerals to Decimal numbers
static int RomanToIntegerfunc(REALstring nString)
{
	 int i, j, k;
     long retval = 0L;
     char* str = REALCString(nString);
        
        
     if (!str || NULL == *str)
            return -1L;
      for (i = 0, k = -1; str[i]; ++i)
      {
            for (j = 0; j < 7; ++j)
            {
                  if (numerals[j].ch == toupper(str[i]))
                        break;
            }
            if (7 == j)
                  return -1L;
            if (k >= 0 && k < j)
            {
                  retval -= numerals[k].val * 2;
                  retval += numerals[j].val;
            }
            else  retval += numerals[j].val;
            k = j;
      }
      
      if (retval<=3999)
      return retval;
      else
        return 3999;
}

In case you are confused by examining the code in quasi-reverse order, the final code listing should appear in the following order:

Listing 1: MySource.cpp

#include "rb_plugin.h"
#include <string.h>	// necessary for some of our string routines
#include <stdio.h>
#include <ctype.h>

//for Roman numerals
struct numeral {
      long val;
      int  ch;
};

static struct numeral numerals[] = {
      {    1L, 'I' },
      {    5L, 'V' },
      {   10L, 'X' },
      {   50L, 'L' },
      {  100L, 'C' },
      {  500L, 'D' },
      { 1000L, 'M' }
};

// for ordinals
static char *text[] = {"th", "st", "nd", "rd"};

//Integer to Ordinal
static REALstring ConvertToOrdinalfunc( int number)
{
 if (((number %= 100) > 9 && number < 20) || (number %= 10) > 3)
            number = 0;
      
      return REALBuildString(text[number], strlen(text[number]));
}  

// Integer to Roman numerals
static REALstring IntegerToRomanfunc(int value)
{
  int dvalue;
    char roman[80];
    roman[0] = '\0';

    dvalue = value;
    while( value >= 1000 )
    {
        strcat( roman, "M" );
        value -= 1000;
    }
    if( value >= 900 )
    {
        strcat( roman, "CM" );
        value -= 900;
    }
    while( value >= 500 )
    {
        strcat( roman, "D" );
        value -= 500;
    }
    if( value >= 400 )
    {
        strcat( roman, "CD" );
        value -= 400;
    }
    while( value >= 100 )
    {
        strcat( roman, "C" );
        value -= 100;
    }
    if( value >= 90 )
    {
        strcat( roman, "XC" );
        value -= 90;
    }
    while( value >= 50 )
    {
        strcat( roman, "L" );
        value -= 50;
    }
    if( value >= 40 )
    {
        strcat( roman, "XL" );
        value -= 40;
    }
    while( value >= 10 )
    {
        strcat( roman, "X" );
        value -= 10;
    }
    if( value >= 9 )
    {
        strcat( roman, "IX" );
        value -= 9;
    }
    while( value >= 5 )
    {
        strcat( roman, "V" );
        value -= 5;
    }
    if( value >= 4 )
    {
        strcat( roman, "IV" );
        value -= 4;
    }
    while( value > 0 )
    {
        strcat( roman, "I" );
        value-;
    }
 
    return REALBuildString(roman, strlen(roman));
    	
}

// Roman numerals to Decimal numbers
static int RomanToIntegerfunc(REALstring nString)
{
	 int i, j, k;
     long retval = 0L;
     char* str = REALCString(nString);
        
        
     if (!str || NULL == *str)
            return -1L;
      for (i = 0, k = -1; str[i]; ++i)
      {
            for (j = 0; j < 7; ++j)
            {
                  if (numerals[j].ch == toupper(str[i]))
                        break;
            }
            if (7 == j)
                  return -1L;
            if (k >= 0 && k < j)
            {
                  retval -= numerals[k].val * 2;
                  retval += numerals[j].val;
            }
            else  retval += numerals[j].val;
            k = j;
      }
      
      if (retval<=3999)
      return retval;
      else
        return 3999;
      
	
}

REALmethodDefinition ConvertToOrdinaldefn = {
	(REALproc) ConvertToOrdinalfunc,
	REALnoImplementation,
	"ConvertToOrdinal(i as integer) as string"
};

REALmethodDefinition IntegerToRomandefn = {
	(REALproc) IntegerToRomanfunc,
	REALnoImplementation,
	"IntegerToRoman(i as integer) as string"
};

REALmethodDefinition RomanToIntegerdefn = {
	(REALproc) RomanToIntegerfunc,
	REALnoImplementation,
	"RomanToInteger(s as string) as integer"
};


void PluginEntry(void)
{
	REALRegisterMethod(&ConvertToOrdinaldefn);
	REALRegisterMethod(&IntegerToRomandefn);
	REALRegisterMethod(&RomanToIntegerdefn);
}

Now that we have covered the settings and some sample code, our final step is to compile it. Proceed to the Make item of the Project menu. If all goes well, you will find a REALbasic plugin in your MyRBPlugin folder upon compilation. If something goes wrong, remain calm and recheck all of your settings. Are all of the files named appropriately? Are all preferences set correctly? Are all files included correctly? Believe me, it can sometimes take the most time getting the compiler to behave, as you desire. Persevere! Of course, you can always check one of the references in the Bibliography for more help too.

REALbasic Controls

The second example we will look at is a custom control. Whereas the first example only gave us three invisible methods for use in REALbasic, this example will add a colorful control to the existing toolbar. To make this control, start a new project in CodeWarrior and follow the steps as outlined previously for making a REALbasic plugin. In addition, you will also need to add the resource file you made earlier. You should also consider renaming the target settings so that the plugin has a unique name.

The source code for the custom control looks quite similar to the first example. There are, however, some very noticeable differences. We start in a typical manner by defining some structs, but this time we also define the events that the control will receive. In our case, we will only define the MouseUp event for our simple toggle switch. This is how the event will appear in REALbasic. We also define a structure that holds the state of the switch (value) as well as the enabled state of the control (enabled).

#include "rb_plugin.h"

static void DrawMyIcon (Rect r, short ID);

extern struct REALcontrol myControl;

REALevent myEvents[] = {
	{ "MouseUp(globalX as Integer, globalY as Integer)" }
};

struct myData
{
	Boolean enabled;
	Boolean	value;
	
};

Next, we define six functions. These functions are the bulk of the control. They define what actions occur when the control needs to be redrawn, what happens when the control has received one of our events, and performs initialization of the control. One of the functions called DrawMyIcon is an auxilliary function, hence the prototype for it at the beginning of the code.

The initialization function sets the control to an enabled state and the value property to false. The value property will be used to tell us if the switch is an on or off state. The DoMouseDown and DoMouseUp functions handle mouse events for the control. Before MouseUp or MouseDrag events are called, the MouseDown function must return TRUE. DrawMyIcon is responsible for redrawing the control. As an added bonus, the proper GrafPort is already set up for us before myDraw is called. Thus, we can simply draw to it without any further preparation. The final function is called DoNothing and is included only because REALbasic requires its presence for compilation of the plugin. This would normally be a REALbasic method, as seen in Example 1.

static void myInit(REALcontrolInstance instance)
{
ControlData(myControl, instance, myData, data);
	
	data->enabled = true;
	data->value = false;
	
}

static void myDraw(REALcontrolInstance instance)
{
	ControlData(myControl, instance, myData, data);
	RGBColor oldCol, fillCol;
	Rect r;
	short			ctrlWidth,ctrlHeight;

	REALGetControlBounds(instance, &r);
			
	 		
	ctrlWidth = r.right - r.left;
	ctrlHeight = r.bottom - r.top;
	short			rsrcnum;
	
	if ((data->value)==true)
		{
	 		rsrcnum=1280;
	 	}
	else
	 	{
	 		rsrcnum=1290;
	 	}	
	 		
	 		 		
	Rect			lRect;
	REALGetControlBounds(instance, &lRect);
	 		
	ctrlWidth = lRect.right - lRect.left;
	ctrlHeight = lRect.bottom - lRect.top;
	 		
	DrawMyIcon(lRect, rsrcnum);
}

static void DrawMyIcon (Rect r, short ID)
{
	Handle	myIconSuite;
	OSErr	myErr;
	IconAlignmentType	align;
	IconTransformType	transform;
	
MyErr =GetIconSuite
(&myIconSuite,ID,svLarge1Bit+svLarge4Bit+svLarge8Bit);
	if (myIconSuite != nil)
	{
		align = atTopLeft;
		transform = ttNone;
		SetRect(&r,r.left,r.top,r.left+32,r.top+32);
		myErr = PlotIconSuite(&r, align, transform, myIconSuite);
		DisposeIconSuite(myIconSuite,true);
	}
	
}

static Boolean myDoMouseDown
(REALcontrolInstance, int x, int y, int modifiers)
{
	return true;
}

static void myDoMouseUp(REALcontrolInstance instance, int x, int y)
{
	ControlData(myControl, instance, myData, data);

	Point			myWhere;
	short			tempX, tempY;
	
	GetMouse(&myWhere);
	tempX = myWhere.h; 
	tempY = myWhere.v; 
			
	
	void (*fp)(REALcontrolInstance instance, int, int);

	fp = (void (*)(REALcontrolInstance instance, int, int)) 

REALGetEventInstance(instance, &myEvents[0]);
		
	if ((fp) && (data->enabled))
	{
		fp(instance, tempX, tempY);
			
	}
		
}

static void myDoNothing(REALcontrolInstance instance)
{ }

Lastly, the source code defines the properties, behavior, and structure
of the control. myProperties[] defines the location in which the various
properties will appear in the property panel, the name of the variable
that will appear in the panel, and the data type it will contain.
MyBehavior describes which functions will be called for each of the
events a control can receive. We will only use three: initialization,
redraw, and mouseup. The Init routine, as well as the Dispose routine
not used here, are automatically called when an object is created. The
other behaviors are listed in the SDK. Finally, the structure of the
control is defined. KCurrentREALControlVersion is a constant provided by
REALsoftware. The next field is the name of the control, as it will
appear in REALbasic. Further down you will see the numbers 128, 129, 32,
32. The first pair of numbers is the ‘PICT‘ resources of the toolbar
icons. The next pair of numbers is the initial size of the control when
it is dragged to a window in the REALbasic IDE. The remainder of the
structure defines the names of the associated property, method, and
event functions. Finally, the code ends by registering the control with
REALbasic. Save the source code and compile the control. Listing 2 shows
the completed source code for the custom control.

Listing 2: mycontrol.cpp

#include “rb_plugin.h”

static void DrawMyIcon (Rect r, short ID);
extern struct REALcontrol myControl;

REALevent myEvents[] = {
	{ “MouseUp(globalX as Integer, globalY as Integer)” }
};

struct myData
{
	Boolean enabled;
	Boolean	value;
	
};

static void myInit(REALcontrolInstance instance)
{
	ControlData(myControl, instance, myData, data);
	
	data->enabled = true;
	data->value = false;
}

static void myDraw(REALcontrolInstance instance)
{
	ControlData(myControl, instance, myData, data);
	RGBColor oldCol, fillCol;
	Rect r;
	short			ctrlWidth,ctrlHeight;

	REALGetControlBounds(instance, &r);
			
	 		
	ctrlWidth = r.right - r.left;
	ctrlHeight = r.bottom - r.top;
	short			rsrcnum;
	
	if ((data->value)==true)
		{
	 		rsrcnum=1280;
	 	}
	else
	 	{
	 		rsrcnum=1290;
	 	}	
	 		
	 		 		
	Rect			lRect;
	REALGetControlBounds(instance, &lRect);
	 		
	ctrlWidth = lRect.right - lRect.left;
	ctrlHeight = lRect.bottom - lRect.top;
	 		
	DrawMyIcon(lRect, rsrcnum);
}

static void DrawMyIcon (Rect r, short ID)
{
	Handle	myIconSuite;
	OSErr	myErr;
	IconAlignmentType	align;
	IconTransformType	transform;
	
	
myErr = GetIconSuite(&myIconSuite,ID,svLarge1Bit+svLarge4Bit+svLarge8Bit);
	
	if (myIconSuite != nil)
	{
		align = atTopLeft;
		transform = ttNone;
		SetRect(&r,r.left,r.top,r.left+32,r.top+32);
		myErr = PlotIconSuite(&r, align, transform, myIconSuite);
		DisposeIconSuite(myIconSuite,true);
	}
	
}

static Boolean myDoMouseDown
(REALcontrolInstance, int x, int y, int modifiers)
{
	return true;
}

static void myDoMouseUp(REALcontrolInstance instance, int x, int y)
{
	ControlData(myControl, instance, myData, data);

	Point			myWhere;
	short			tempX, tempY;
	
	GetMouse(&myWhere);
	tempX = myWhere.h; 
	tempY = myWhere.v; 
			
	
	void (*fp)(REALcontrolInstance instance, int, int);

	fp = (void (*)(REALcontrolInstance instance, int, int)) 

REALGetEventInstance(instance, &myEvents[0]);
		
	if ((fp) && (data->enabled))
	{
		fp(instance, tempX, tempY);
			
	}
		
}

static void myDoNothing(REALcontrolInstance instance)
{
	
}

REALproperty myProperties[] = {
{“Appearance”, “Enabled”, “Boolean”, REALpropInvalidate, REALstandardGetter, 
  REALstandardSetter, FieldOffset(myData, enabled)},
{“Appearance”, “Value”, “Boolean”, REALpropInvalidate,REALstandardGetter, 
  REALstandardSetter, FieldOffset(myData, value)},
};

REALmethodDefinition myMethods[] = {
{ (REALproc) myDoNothing, REALnoImplementation, “DoNothing” },
};

REALcontrolBehaviour myBehaviour = {
	myInit,		//the Init function
	nil,				//the Dispose function
	myDraw,		//the ReDaw function
	myDoMouseDown,
	nil,
	myDoMouseUp,
};

REALcontrol myControl = {
	kCurrentREALControlVersion,
	“MySwitch”,
	sizeof(myData),
	NULL,
	128,129,
	32,32,
	myProperties,
	sizeof(myProperties) / sizeof(REALproperty),
	myMethods,
	sizeof(myMethods) / sizeof(REALmethodDefinition),
	myEvents,
	sizeof(myEvents) / sizeof(REALevent),
	&myBehaviour
};

void PluginEntry(void)
{
	REALRegisterControl(&myControl);
}

Testing the Code

"OK", you say, "but now what?" Well, the reason we went through all of the trouble to make these plugins was to extend our programming abilities in REALbasic itself. To take advantage of our new plugins, we need to copy the plugins to a folder entitled Plugins, which resides in the same folder as the REALbasic application and fire up the REALbasic environment. Now, whenever you want to use the functions that we coded in our source code earlier, we can simply call them just like we call any REALbasic method. They are always available to us just as the native methods included in REALbasic. You should also see a new control in the toolbar. You can use it by dragging it into a window in your REALbasic project. Wow! Stop and think about that for a second. In a small way, you have just become a programmer of the REALbasic environment. Cool, eh?

To test our functions, open a window in REALbasic. Drag three PushButtons onto the window as well as an Editfield. Then, add the following code:

Window1.PushButton1.Action:
Sub Action()
	//ConvertToOrdinal(i as integer) as string
	msgBox editfield1.text+ConvertToOrdinal(val(editfield1.text))
End Sub

Window1.PushButton2.Action:
Sub Action()
	//IntegerToRoman(i as integer) as string
	msgBox IntegerToRoman(val(editfield1.text))
End Sub

Window1.PushButton3.Action:
Sub Action()
	//IntegerToRoman(i as integer) as string
	msgBox str(RomanToInteger(editfield1.text))
End Sub

To test the control, drag it from the toolbar onto a window. Double-click the new control and add the following code:

Window1.MySwitch1.MouseUp:
Sub MouseUp(globalX as Integer, globalY as Integer()
	me.value=not(me.value)
End Sub

Select Run from the Debug menu and marvel at your work.

Conclusion

The plugin we discussed extended REALbasic giving it three additional methods. We also compiled a custom control switch for use in REALbasic. Although both of these tasks might have just as easily been done in REALbasic itself, it at least gives you an idea of how to go about making your own plugins and controls for REALbasic. It would not take much more effort to build a custom slider control or add sophisticated mathematical routines to your plugin. Further details about the capabilites of REALbasic plugins are included in the SDK. You can also find a lot of assistance on the REALbasic users listservs which you can register for following the links at REALsofware's web site. Many REALbasic users are willing to offer suggestions and help with your plugin questions. In fact, a listserv is entirely devoted to plugin development in REALbasic.

Plugins are a fantastic addition for developers using REALbasic. REALsoftware knew that they could never cover every use that users envisioned, so they gave us a way to extend REALbasic. Some possible uses for REALbasic have already begun development, while others have never been attempted, given the relative youth of REALbasic. Some possibilities include graphic libraries, networking functions, high-speed mathematical calculations (for use with 3D), hardware support, as well as more arcane system commands from the Mac Toolbox. You might also find it more convenient to transfer some of your tried-and-true functions from your C/C++ libraries into a REALbasic plugin rather than porting them all to REALbasic (This was my original intention for using the functions in your source code.). Developing controls for REALbasic can be equally rewarding. The concepts are nearly identical to the included source code, but some additional code is required. Check the SDK and the Bibliography for further details and examples. Some possible ideas for controls include: custom widgets, an audio/video capture control, customized versions of existing controls, an infrared control, a speech recognition control, among others. Only your imagination holds you back now.

Bibliography

The best information available to the budding REALbasic plugin programmer is the Internet. A good place to begin is the REALbasic home site. There you can download the plugin SDK as well as a demo version of REALbasic. You can also find instructions for subscribing to the various email lists available to REALbasic programmers.

REALsoftware http://www.realsoftware.com

REALbasic http://www.realbasic.com

Other sites have plugin source code, example projects, and compiled plugins available for download. Many of the plugin authors are also the same people on the listservs who will be willing to answer questions you might have regarding plugins.

Purple E Software http://www.norcom2000.com/users/ejt/purplee.html Okay, I admit I am partial to this site, since it is my own, but it does include several freeware plugins for REALbasic as well as other tips and tricks.

Essence Software http://www.essencesw.com/ Numerous REALbasic plugins, including video capture, QuickDraw 3D, and SuperSocket.

Thomas Tempelmann http://www.tempel.org/rb/ Too many plugins to list! Loads of source code is included. A required site for the REALbasic plugin developer.

Einhugur Software http://www.treknet.is/einhugur/realbasic/ Another jewel in the REALbasic community. Contains many useful plugins and links.


Erick J. Tejkowski is an IT professional for the Macintosh-loving Zipatoni Company in St. Louis, Missouri. When he's not busy trying to raise a trilingual daughter (English, Spanish, and German) with his wife Lisa, he programs shareware and freeware software for his own Purple E Software. His software has appeared in Macintosh publications around the world. You can reach him at ejt@norcom2000.com.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.