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

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.