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

Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »
Live, Playdate, Live! – The TouchArcade...
In this week’s episode of The TouchArcade Show we kick things off by talking about all the games I splurged on during the recent Playdate Catalog one-year anniversary sale, including the new Lucas Pope jam Mars After Midnight. We haven’t played any... | Read more »

Price Scanner via MacPrices.net

Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more
New promo at Visible: Buy a new iPhone, get $...
Switch to Visible, and buy a new iPhone, and Visible will take $10 off their monthly Visible+ service for 24 months. Visible+ is normally $45 per month. With this promotion, the cost of Visible+ is... Read more
B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for $100 off Apple’s new MSRP, only $899. Free 1-2 day delivery is available to most US addresses. Their... Read more
Take advantage of Apple’s steep discounts on...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more

Jobs Board

Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply 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
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
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
Business Analyst | *Apple* Pay - Banco Popu...
Business Analyst | Apple PayApply now " Apply now + Apply Now + Start applying with LinkedIn Start + Please wait Date:Mar 19, 2024 Location: San Juan-Cupey, PR Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.