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

Fallout Shelter pulls in ten times its u...
When the Fallout TV series was announced I, like I assume many others, assumed it was going to be an utter pile of garbage. Well, as we now know that couldn't be further from the truth. It was a smash hit, and this success has of course given the... | Read more »
Recruit two powerful-sounding students t...
I am a fan of anime, and I hear about a lot that comes through, but one that escaped my attention until now is A Certain Scientific Railgun T, and that name is very enticing. If it's new to you too, then players of Blue Archive can get a hands-on... | Read more »
Top Hat Studios unveils a new gameplay t...
There are a lot of big games coming that you might be excited about, but one of those I am most interested in is Athenian Rhapsody because it looks delightfully silly. The developers behind this project, the rather fancy-sounding Top Hat Studios,... | Read more »
Bound through time on the hunt for sneak...
Have you ever sat down and wondered what would happen if Dr Who and Sherlock Holmes went on an adventure? Well, besides probably being the best mash-up of English fiction, you'd get the Hidden Through Time series, and now Rogueside has announced... | Read more »
The secrets of Penacony might soon come...
Version 2.2 of Honkai: Star Rail is on the horizon and brings the culmination of the Penacony adventure after quite the escalation in the latest story quests. To help you through this new expansion is the introduction of two powerful new... | Read more »
The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »

Price Scanner via MacPrices.net

Verizon has Apple AirPods on sale this weeken...
Verizon has Apple AirPods on sale for up to 31% off MSRP on their online store this weekend. Their prices are the lowest price available for AirPods from any Apple retailer. Verizon service is not... Read more
Apple has 15-inch M2 MacBook Airs available s...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs available starting at $1019 and ranging up to $300 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at Apple.... Read more
May 2024 Apple Education discounts on MacBook...
If you’re a student, teacher, or staff member at any educational institution, you can use your .edu email address when ordering at Apple Education to take up to $300 off the purchase of a new MacBook... Read more
Clearance 16-inch M2 Pro MacBook Pros in stoc...
Apple has clearance 16″ M2 Pro MacBook Pros available in their Certified Refurbished store starting at $2049 and ranging up to $450 off original MSRP. Each model features a new outer case, shipping... Read more
Save $300 at Apple on 14-inch M3 MacBook Pros...
Apple has 14″ M3 MacBook Pros with 16GB of RAM, Certified Refurbished, available for $270-$300 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year warranty is... Read more
Apple continues to offer 14-inch M3 MacBook P...
Apple has 14″ M3 MacBook Pros, Certified Refurbished, available starting at only $1359 and ranging up to $270 off MSRP. Each model features a new outer case, shipping is free, and an Apple 1-year... Read more
Apple AirPods Pro with USB-C return to all-ti...
Amazon has Apple’s AirPods Pro with USB-C in stock and on sale for $179.99 including free shipping. Their price is $70 (28%) off MSRP, and it’s currently the lowest price available for new AirPods... Read more
Apple Magic Keyboards for iPads are on sale f...
Amazon has Apple Magic Keyboards for iPads on sale today for up to $70 off MSRP, shipping included: – Magic Keyboard for 10th-generation Apple iPad: $199, save $50 – Magic Keyboard for 11″ iPad Pro/... Read more
Apple’s 13-inch M2 MacBook Airs return to rec...
Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices currently... Read more
Best Buy is clearing out iPad Airs for up to...
In advance of next week’s probably release of new and updated iPad Airs, Best Buy has 10.9″ M1 WiFi iPad Airs on record-low sale prices for up to $200 off Apple’s MSRP, starting at $399. Sale prices... Read more

Jobs Board

Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
*Apple* App Developer - Datrose (United Stat...
…year experiencein programming and have computer knowledge with SWIFT. Job Responsibilites: Apple App Developer is expected to support essential tasks for the RxASL Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple 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.