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

Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
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 below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »

Price Scanner via MacPrices.net

Apple Watch Ultra 2 now available at Apple fo...
Apple has, for the first time, begun offering Certified Refurbished Apple Watch Ultra 2 models in their online store for $679, or $120 off MSRP. Each Watch includes Apple’s standard one-year warranty... Read more
AT&T has the iPhone 14 on sale for only $...
AT&T has the 128GB Apple iPhone 14 available for only $5.99 per month for new and existing customers when you activate unlimited service and use AT&T’s 36 month installment plan. The fine... Read more
Amazon is offering a $100 discount on every M...
Amazon is offering a $100 instant discount on each configuration of Apple’s new 13″ M3 MacBook Air, in Midnight, this weekend. These are the lowest prices currently available for new 13″ M3 MacBook... Read more
You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more

Jobs Board

*Apple* Systems Administrator - JAMF - Syste...
Title: Apple Systems Administrator - JAMF ALTA is supporting a direct hire opportunity. This position is 100% Onsite for initial 3-6 months and then remote 1-2 Read more
Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.