TweetFollow Us on Twitter

4D Externals
Volume Number:4
Issue Number:11
Column Tag:Database Corner

4th Dimension® Externals

By Todd Carper, ACIUS, Inc., Cupertino, CA

[Todd Carper is a Technical Support Engineer for 4th Dimension® and handles all external procedure development. He has been there for one year.]

External Procedures in 4th Dimension®

4th Dimension is a powerful and sophisticated database for the Macintosh. It provides an excellent environment for developing custom databases and applications. 4th Dimension allows you to quickly generate screens, menus, buttons, scrollable areas, and procedures to create a true Macintosh interface without starting from scratch.

4th Dimension’s language enables you to avoid pages of code and hours of work by accessing the Macintosh ToolBox with high level commands. Though the language is very powerful it may not contain all the built-in commands to meet every need. For this reason 4th Dimension was designed as an open architecture database that can utilize your own commands. These commands are called “external procedures”, and this document will discuss the design and implementation of external procedures.

External procedures enable you to add unlimited functionality to a 4th Dimension database or application. For example, you can add sound, pop-up menus, picture buttons, mathematics, or telecommunications capabilities. External procedures are extensions to the 4th Dimension commands that you create like XCMDs for HyperCard. Once the procedure is installed, it is part of 4th Dimension and can be called just as you call built-in commands.

External procedures can be written in assembly language, or any higher level language that compiles to native 68000 code. It is very important that the code be stand-alone, in that it does not require additional modules to function properly. This article will use Pascal programs created with the Apple Macintosh Programmers Workshop (MPW) Pascal.

Calling the Externals

When 4th Dimension ‘calls’ the external procedure, it simply performs a direct link, Link A6, to the routine and executes the supplied code until the code ends, and by nature executes a return statement to the calling routine.

Because the supplied code is being called from within another application, you should not try to access any global variables, as those are stored off the A5 register and it’s contents may not be correct for your call. Therefore always declare your variables local. If you need the variables to be used as if they were global then define them within a procedure, and have all called procedures and functions defined within the procedure defining the ‘global’ variables.

The idea is to make all references relative. This is important because when the code is moved into 4th Dimension, the Code 0 segment is not used. (This is where the Jump table is located). Therefore if you have procedures you want to call, they should be declared as FORWARD and your top most procedure should be the one that ‘runs’ your program.

Following is an example external procedure. This procedure will receive a number, multiply the number by 2, and return the result. Because the variable is declared as a var in the procedure parameter list, the result can be returned to 4th Dimension.

Program Ext_Doubler;
VarDumInt:Integer;

procedure Doubler(var TheInt:Integer);
begin
 TheInt:=TheInt*2;
end;  {Doubler}

Begin
 Doubler(DumInt); {Used for compile only}
End.    {Main Block}

Following is an example utilizing multiple procedures which doesn’t take any parameters. It simply assigns the string ‘Hello there’ to the global variable Global2. It then beeps once for each character in the string. The variables Global1 and Global2, appear to be global type variables because the procedures which use them are within the scope of the procedure which defines both the variables and the procedure using the variables.

The main block calls the procedure Caller, (this call i4th Dimensionns only.) Caller then calls the procedure to be executed, HaveGlobals. HaveGlobals was declared as FORWARD so that Caller would know that it exists. HaveGlobals defines the variables to be used by the procedures defined in it’s scope. HaveGlobals assigns the string to Global2. It then calls First to assign the length of Global1 to Global2. Then Second is called to have the system beep Global1 times.

Program TestProg;

Uses Memtypes, QuickDraw, OSIntf;

procedure HaveGlobals; FORWARD;
{so Caller knows about the procedure}

procedure Caller;
begin
 HaveGlobals;
end;

procedure HaveGlobals;
var
 Global1:Integer;
 Global2:str255;

 procedure First;
 begin
 Global1:=Length(Global2);
 end; {First}

 procedure Second;
 var Count:Integer;
 begin
 For Count:=1 to Global1 do Sysbeep(2);
 end; {Second}

begin {HaveGlobals}
 Global2:=’Hello there’;
 First;
 Second;
end; {HaveGlobals}

Begin {Main Block}
 Caller;
End. {program}

Creation of External procedures

Be sure that if your external compiles to more than 1 code segment, or if one of the linked modules is placed in it’s own segment, that you join the segments into 1 complete segment. This is important if your application uses the SANE library.

You can compile to an application and then use the 4D External Mover™ to transfer the code segment and to specify the parameters. You can also compile directly to a Proc.Ext type file and specify the parameter list. Then you can use the 4D External Mover to copy the already set-up external to the proper Proc.Ext file. There will also be an item in the list, (if viewed in the 4D External Mover), with the name %A5Init. This item may be deleted from the list as it is not needed by the external.

Here is an example of a MPW linker spec to join the SANE code segment with the Main code segment and the method of installing directly into a Proc.Ext type file.

link -w -p MyProg.p.o 
 “{Libraries}”Interface.o 
 “{Libraries}”Runtime.o 
 “{PLibraries}”Paslib.o 
 “{PLibraries}”SANELib.o 
 -rt ‘4DEX=15000’  #Specify resource ID.
 # Joins segment Main and the Sane libraries into
 # one. *
 -sg “Main2=Main,SANELib “
 # Change segment name. **
 -sn ‘Main2’=’MyProg(&S;&R)’ 
 # Specify the creator and type.
 -c “4DMX” -t “PEXT”
 -o MyProg

* Note: for this external procedure, the Sane libraries are needed, therefore, they must exist in the same segment as the main code. If your code does not require the Sane libraries then this command is not necessary. Be sure to note the case used in “SANELib ” and the space which is between ‘b’ and the quote mark.

** The segment name was changed from Main2 to MyProg, the additional parameters, in parens, specify the types of the parameters being passed from 4th Dimension. In this example, (&S;&R), specifies that a String and a Real are to be passed. String first, Real second. Each parameter is preceded by an ampersand, ‘&’. A semicolon is used to separate each parameter.

The parameter types are as follows:

I Integer

L LongInt

R Real

S String

T Text

D Date

P Picture

Following are the Pascal type definitions for Date and Text fields.

Date    type
 Date4D = record
 day:integer;
 month:integer;
 year:integer;
 end;

Text    type
 TERec4D = record
 length:integer;
 text:CharsHandle;
 end;

With the release of the 128k ROMs, the restriction of code segments being less than 32k has gone away. Because of this, your external procedure may be very large. There is one important note however; you cannot perform a branch to an address which is farther than 32k from where you are branching from. The linker will catch this and you will have to put in a ‘stepping stone’ procedure. All these procedures do is call the procedure you wanted to call originally. They are located between the calling procedure and the procedure to be called and are used as stepping stones to get to the proper procedure.

In this example, we want to call Proc4 from Proc1. Proc1 and Proc3 are very large; such that the distance from the call to Proc3 and the location of Proc3 is greater than 32k when compiled. To accomplish the call we need to insert a ‘stepping stone’ procedure after Proc1 called Step. Proc1 calls the procedure Step. Step then calls Proc3. In this way, the distance between calls is less than 32k.

Program Ext_StepStone;

Uses Memtypes;

Var
 {Variable definitions}

procedure Proc2; Forward;
procedure Proc3; Forward;
procedure Step; Forward;

procedure Proc1;
var
 MyVar:str255;
begin
 MyVar:=’Hello’;
 {Now we call Step to get to Proc3}
 Step;
   {Lot’s of Code}
end;    {Proc1}

procedure Step;
begin
 {This routine just calls Proc3}
 Proc3;
end;    {Step}

procedure Proc2;
begin
   {Lot’s of code}
end;    {Proc2}

procedure Proc3;
begin
 {Here’s the code we want to use}
   {Some more code}
end;    {Proc3}

Begin {Main Block}
 Proc1;
End.  {Main Block}

Handles and External procedures

Whenever storing a data structure, be sure that you are accessing it via a Handle and that you lock the Handle if you want to ensure that it is there when you return.

Be sure to Dispose of all Handles that you have created when you have finished with them. If you leave unused handles in memory, you could run out of memory at a later point in the program.

Using Pictures in Externals

When passing Picture variables, to and from external procedures, be sure to include room for the additional 6 bytes needed by 4th Dimension to store the (Horizontal, Vertical) origin of the picture used when it is displayed in an On-Background field, (4 bytes), and the mode in which the picture is to be displayed, (2 bytes). For most pictures this means using SetHandleSize to increase the allocated space:

 SetHandleSize(Handle(MyPic),      
 GetHandleSize(Handle(MyPic))+6)

* Remember, Pictures can now be greater than 32k in size. Therefore the PicSize element of the PicHandle record, may not be valid. You should always call GetHandleSize to learn the size of the Picture.

When using externals it is sometimes necessary to save a complex data structure or just a handle of a type unknown to 4th Dimension. To store types of handle other than PicHandle, you can simply use Type Coercion to change the handle to type PicHandle and then pass the handle back to 4th Dimension in the form of a picture. Do not attempt to display the ‘picture’ as strange things will definitely happen.

Here is an example of storing SND’s in a 4th Dimension picture field. This example reads an SND resource from a file and returns to 4th Dimension a picture variable containing the SND. You can then store the picture (SND) and replay it at a later time using PlayPict, (the routine PlayPict follows this one). SoundToPict takes 3 parameters, SoundToPict(Parm1;Parm2;Parm3). Parm1 is the name of the file on disk containing the SND. Parm2 is the name of the SND to be retrieved. Parm3 returns a picture variable containing the SND. For information about the Resource Manager, see Inside Macintosh.

Program Ext_SoundToPict;

Uses MemTypes, QuickDraw, OSIntf,
 ToolIntf, PackIntf, Sound;

Var
 DFile, DSound:str255;
 DPict:PicHandle;

procedure SoundToPict(
 var TheFile, SoundName:str255;
 var MyPict:PicHandle);

type
 FFSynthHandle = ^FFSynthPtr;

var
 MySound:FFSynthHandle;
 TheRes:integer;
 MyPtr:Ptr;
 MyFFPtr:FFSynthPtr;

begin
 MyPict:=Nil;
 TheRes:=OpenResFile(TheFile);
 MySound:=FFSynthHandle(GetNamedResource
 (‘Snd ‘,SoundName));  {Locate SND}
 {Test if the sound was found and read}
 if MySound<>Nil then
 begin
 Hlock(Handle(MySound));
 {Copy the Pointer}
 MyPtr:=Ptr(MySound^);
 {Type coerce the new Ptr}
 MyFFPtr:=FFSynthPtr(MyPtr);
 {Set the playback mode and ratio}
 MyFFPtr^.mode:=FFMode;
 MyFFPtr^.count:=FixRatio(1,1);
 MyFFPtr^.wavebytes[0]:=0;
 {Type coerce the handle to type}
 {PicHandle}
 MyPict:=Pichandle(MySound);
 {Lock the picture so we don’t lose it}
 HLock(Handle(MyPict));
 {Coerce and Copy the pointer}
 MyPict^:=PicPtr(MyPtr);
 {Unlock the Handles before leaving}
 HUnlock(Handle(MySound));
 Hunlock(Handle(MyPict));
 {Now Detach the Resource since we}
 {have another handle to it.}
 DetachResource(Handle(MySound));
 end; {if mysound<>Nil}
 CloseResFile(TheRes);
end;    {SoundToPict}

Begin
 SoundToPict(DFile, DSound, DPict);
End.    {Main Block}

This routine is used to play the SND that was stored in a 4th Dimension picture field. It takes a 4th Dimension picture variable and converts the ‘picture’ to a sound. The sound is then played with StartSound. If the passed picture variable does not contain information generated by SoundToPict, you will get unexpected results. For information about the Sound Driver, see Inside Macintosh.

Program Ext_PlayPict;

Uses MemTypes, QuickDraw, OSIntf,
 ToolIntf, PackIntf, Sound;

Var
 DPict:PicHandle;
 DFile, DSound:integer;

procedure PlayPict(
 var Numer, Denom:integer;
 var MyPict:PicHandle);

type
 FFSynthHandle=^FFSynthPtr;

var
 MySound:FFSynthHandle;
 MyPtr:Ptr;
 MyFFPtr:FFSynthPtr;

begin
 {make sure that we recieved something}
 if MyPict<>Nil then
 begin
 {Coerce the handle}
 MySound:=FFSynthHandle(MyPict);
 {Lock the sound so we don’t lose it}
 HLock(Handle(MySound));
 {Copy the pointer}
 MyPtr:=Ptr(MySound^);
 {Type Coerce the pointer}
 MyFFPtr:=FFSynthPtr(MyPtr);
 {Set the playback mode}
 MyFFPtr^.mode:=FFMode;
 {Set the playback count to the}
 {parameters passed.}
 MyFFPtr^.count:=FixRatio(Numer, Denom);
 MyFFPtr^.wavebytes[0]:=0;
 {Play the sound}
 StartSound(MyPtr,
 GetHandleSize(Handle(MySound)),
 POINTER(-1));
 {Unlock the sound so it can be}
 {disposed}
 HUnLock(Handle(MySound));
 end;   {if MyPict<>Nil}
end;    {PlayPict}

Begin
 PlayPict(DFile, DSound, DPict);
End.    {Main Block}

The Grafport and External procedures

If you change the current Grafport or it’s settings, you must restore the Grafport to it’s original status before returning to 4th Dimension. For example, if you were to call an external procedure that changed the current Grafport to an off-screen port, perform some drawing operations, and use CopyBits to copy the image to the original Grafport, you must restore the Grafport to it’s original location before you leave the external procedure. You cannot access QuickDraw globals, therefore you must do the following to track the current GrafPort:

{Get the current GrafPort, DO NOT use  ThePort}
GetPort(OrgPort);
{Set to the new port}
SetPort(MyPort);
.
.
.
{Set the port back to it’s original status}
SetPort(OrgPort);

Changing the Mac environment

It is sometimes necessary to modify the settings of certain Mac items, such as the Serial Port buffer size. By default the buffer size is 64 bytes. Many applications that use the serial ports for communication need to have the buffer much larger. The buffer size can be modified while in 4th Dimension but you must remember to re-assign the buffer to it’s original location before exiting 4th Dimension or else the new buffer might be cleared by another system operation and there would be an erroneous pointer to buffer space.

Here is an example of how to modify the serial port buffers. This routine creates a new buffer the size of NbOfBytes for serial port access. SetSerialBuf takes 3 parameters, SetSerialBuf(Device;BufHandle;BufSize). Where Device contains the value 0 or 1 to specify Printer or Modem, respectively. BufHandle will return the address of the generated buffer. (Do not change this variable after the call, as it is needed to find and dispose of the buffer later.) BufSize specifies the size of the buffer in bytes, to be created. BufSize will return the size of the buffer actually created. The minimum buffer size is 1024 bytes. The maximum buffer size is 32000 bytes. In the case of an error, BufSize will return a negative number specifying the Macintosh Error Code. For an explanation of Macintosh Error Codes and information about the Device Manager, see Inside Macintosh.

Program Ext_SetSerBuf;

Uses  MemTypes,QuickDraw,OSIntf,ToolIntf,
 Packintf;
{$D+}
{$R-} 
Var
 BufHandle:Handle;
 PrinterOrModem,NbOfBytes:Integer;

procedure SetSerBuf(
 var PrinterOrModem:Integer;
 var BufHandle:Handle;
 var NbOfBytes:Integer);

var Error,RefNum:Integer;

begin
 {default buffersize of 1024 bytes}
 if NbOfBytes<1 then NbOfBytes:=1024;
 {max buffer size is 32000}
 if NbOfBytes>32000 then
 NbOfBytes:=32000;
 {generate space for the new buffer}
 BufHandle:=NewHandle(Ord4(NbOfBytes));
 {Test for Handle allocation error}
 Error:=MemError;
 if Error=NoErr then
 begin
 {Move Handle out of the way to avoid}
 {fragmentation.}
 MoveHHI(BufHandle);
 {Lock that puppy down}
 HLock(BufHandle);
 {Set Reference Number accordingly.}
 {0 is Printer, 1 is Modem}
 if PrinterOrModem=0 then
 RefNum:=-8 {Printer}
 else
 RefNum:=-6;{Modem}
 {Reassign the serial port buffer} Error:=SerSetBuf(RefNum,Ptr(BufHandle^)
   ,Ord(GetHandleSize(BufHandle)));
 {Test for errors from reassignment}
 if Error<>NoErr then
 begin
 {If errors then beep and undo what we}
 {have done.}
 SysBeep(10);
 {Assign the error code to NbOfBytes}
 {so that it is returned}
 NbOfBytes:=Error;
 {Unlock and dispose of buffer}
 HUnLock(BufHandle);  DisposHandle(BufHandle);  BufHandle:=Nil;
 end;   {if Error<>NoErr}
 end    {if Error=NoErr, TRUE}
 else
 begin
 {there was a memory allocation error}
 SysBeep(10);
 NbOfBytes:=Error;
 end;   {if Error=NoErr, FALSE}
end;    {SetSerBuf}

Begin
 SetSerBuf(PrinterOrModem,BufHandle,
 NbOfBytes);
End. {Main Block}

This routine disposes of the buffer created by SetSerialBuf and reassigns the serial port back to it’s default buffer. ClearSerBuf takes two parameters, SetSerBuf(Device; BufHandle). Device specifies the printer or modem port and should be the same value that was used when SetSerBuf was called. BufHandle contains the address to the buffer generated by SetSerBuf.

Program Ext_ClearSerBuf;

Uses
 MemTypes,QuickDraw,OSIntf,ToolIntf,
 PackIntf;
{$D+}
{$R-}
var
 BufHandle:Handle;
 PrinterOrModem,NbOfBytes:Integer;

procedure ClearSerBuf(
 var PrinterOrModem:Integer;
 var BufHandle:Handle);

var Error,RefNum:Integer;

begin
 {test for validity of passed Handle}
 if BufHandle<>Nil then
 begin
 {set RefNum according to the port}
 if PrinterOrModem=0 then
 RefNum:=-8
 else
 RefNum:=-6;
 {Disable usage of our buffer}
 Error:=SerSetBuf(RefNum,Ptr(BufHandle^)
 ,0);
 {Test for errors}
 if Error=NoErr then
 begin
 {Unlock and Dispose of the Handle}
 HUnLock(BufHandle);      DisposHandle(BufHandle);
 BufHandle:=Nil;
 end  {if Error=NoErr, TRUE}
 else
 {Problem encountered}
 SysBeep(10);  {if Error=NoErr, FALSE}
 end    {if BufHandle<>Nil, TRUE}
 else
 {Non-Valid Handle was passed}
 SysBeep(10);
 {if BufHandle<>Nil, FALSE}
end;    {ClearSerBuf}

Begin
 ClearSerBuf(PrinterOrModem,BufHandle);
End.  {Main Block}

External Areas

External Areas provide a way for an external procedure to take complete control of an area on a 4th Dimension input layout. You could, for example, allow the user to draw shapes using QuickDraw, implement a full-function word processor, or display a picture format that is not supported by 4th Dimension such as TIFF.

You need at least two external procedures to operate an external area. One of the external procedures will control the activity in the external area. One or more external procedures will be used to exchange information with the external area procedure. When the 4th Dimension input layout is opened, the external area procedure will be called and should create a data structure in memory. This data structure will be used by other external procedures to ‘talk’ with the external area. In this way your 4th Dimension procedure can know what is happening in the external area and it can provide the external area procedure with information about other user operations.

You define an external area on a 4th Dimension layout by drawing a variable field and specifying it as an External Area. The variable name will be used to store the address of the data structure defined in your external area. You enter the name of the external area procedure in the format box in the variable definition dialog. (The box may be labeled as ‘Not Used’.) The size of the variable box on the layout will determine the size and location of the rectangle which your external area procedure can control.

Procedures that are to be used as external area procedures must be defined as follows:

procedure MyExtArea(
 var AreaEvent:EventRecord;
 var AreaRect:Rect;
 var AreaName:str255;
 var AreaHndl:MyDataHndl);

EventRecord, Rect, and str255 are defined in Inside Macintosh.

AreaEvent is used to inform your external area of Macintosh events.

AreaRect contains the current location of your external area on the screen.

AreaName contains the name of the 4th Dimension variable on the layout which defines the external area.

AreaHndl contains is a handle to your data structure defined as type MyDataHndl. AreaHndl is used to exchange information between your 4th Dimension procedure and your external area procedure.

You can test for the following events via the EventRecord.what parameter:

InitEvt 16

DeInitEvt 17

CursorEvt 18

SelectReq 20

ActivNote 21

DeActivNote 22

NotUsed 23

NotUsed 24

ScrollEvt 25

DrawReq 26

UpdateEvt predefined in the Toolbox

MouseDown predefined in the Toolbox

Event 16 is informing you that your routine has been called for the first time and you should create any data structures required by your external area. (Define AreaHndl.)

Event 17 is informing you that your routine is about to be removed and you should clean-up and dispose of any data structures you created. (Dispose of AreaHndl.)

Event 18 is informing you that the cursor is over the area defined for your external area.

Event 20 is a request for you to accept all keyboard events. If you return the value 101 in the message element, you will receive all subsequent keyboard events until the user clicks on another item in the input layout.

Event 21 is sent only if you requested to be selectable when you received event 20. The receipt of event 21 means that your area has been selected and you should prepare to receive keyboard events.

Event 22 is sent only if you requested to be selectable when you received event 20. The receipt of event 22 means that your area has been deselected and you should not continue testing for keyboard events.

Event 25 is informing you that the window is being scrolled. This is so you can update the rectangle coordinates you are using. DO NOT update the screen when this event has been received. You will receive an UpdateEvt if the screen needs to be updated.

Event 26 is a request for you to display your picture in the 4th Dimension Layout Editor in place of the 1’s and 0’s displayed by 4th Dimension. If you return the value 102 in the message element, 4th Dimension will not draw the area occupied by the defined variable associated with the external area procedure. If you accept responsibility for drawing the area, then you must draw a picture or nothing will be displayed.

You do not directly pass parameters to an external area procedure, rather you access the data structure defined as type MyDataHndl and place information in the data structure for the external area to recognize and act upon.

For example, the following external area procedure detects a mouse down event within an external area. When a mouse down is detected in the external area, a 1 will be stored in the data structure pointed to by AreaHndl. This external area procedure is useful for defining invisible buttons on a 4th Dimension input layout.

Program Ext_AreaButton;

Uses MemTypes, QuickDraw, OSIntf,
 ToolIntf, PackIntf;

Const
 InitEvt=16;
 DeInitEvt=17;

Type
 {This is the definition of the data}
 {structure I want to use.  All I want}
 {to know is if the Mouse was clicked}
 {in the external area.  0 if NO,}
 {1 if YES.}
 MyData = record
   Status:Integer;
 end;
 MyDataPtr = ^ MyData;
 MyDataHndl = ^MyDataPtr;

Var
 AreaEv:EventRecord;
 AreaRec:Rect;
 AreaNam:str255;
 AreaHnd:MyDataHndl;

procedure AreaButton(
 var AreaEvent:EventRecord;
 var AreaRect:Rect;
 var AreaName:str255;
 var AreaHndl:MyDataHndl);

var tPoint:Point;{Tracks the mouse location.}

begin
 Case AreaEvent.What of
 InitEvt:
 begin
 {Create a new handle for our}
 {structure.}
 AreaHndl:=MyDataHndl(NewHandle(
 sizeof(MyData)));
 {Initialize the setting to 0. Not}
 {clicked.}
 AreaHndl^^.Status:=0;
 end; {InitEvt}
 MouseDown:
 begin
 {Wait for mouse up so we know they}
 {completed the click within our}
 {area and didn’t drag out of the}
 {area before releasing.}
 While StillDown do begin end;
 {Is the mouse in our area?}
 GetMouse(tPoint);
 {AreaRect is our rect so test if the}
 {point is in our area.}
 if(PtInRect(tPoint, AreaRect)) then
 {They clicked in our area so}
 {Status=1.  Clicked}
 AreaHndl^^.Status:=1;
 end; {MouseDown}
 DeInitEvt:
 begin  {Get rid of our handle}
 DisposHandle(Handle(AreaHndl));
 end; {DeInitEvt}
 end; {Case AreaEvent.What}
end;  {AreaButton}

Begin
 AreaButton(AreaEv, AreaRec, AreaNam,
 AreaHnd);
End.    {Main Block}

The external area procedure above will track whether a mouse down has occurred in the external area. Now we need to check it’s status from our 4th Dimension procedure. We check the status by calling another external procedure which accesses the data structure we created and returns the current setting of AreaHndl^^.Status. Once we’ve tested the variable, we set AreaHndl^^.Status back to 0, (not clicked), so we can test for the next mouse down.

We check the current setting with the following external procedure:

Program Ext_GetButton;

Uses MemTypes, QuickDraw, OSIntf,
 ToolIntf, PackIntf;

Type
 MyData = record
 Status:Integer;
 end;
 MyDataPtr = ^ MyData;
 MyDataHndl = ^MyDataPtr;

Var
 Areahnd:MyDataHndl;
 Result:Integer;

procedure GetButton(
 var AreaHndl:MyDataHndl;
 var Result:Integer);

begin
 {Result returns Status}
 Result:=AreaHndl^^.Status;
 {Set Status to Not Clicked}
 AreaHndl^^.Status:=0;
end;    {GetButton}

Begin
 GetButton(AreaHnd, Result);
End.

From 4th Dimension we would call this procedure as GetButton(MyButton;Clicked). Where MyButton is the name of the 4th Dimension variable defining the space for the external area. (Remember, the variable name contains the address of the data structure in memory.) Clicked is a 4th Dimension global variable which will return the current setting of AreaHndl^^.Status.

When writing and installing external areas it is important to note that once you have assigned the external area to a variable in the layout editor, the External is called by the layout editor. Therefore, it is important that your routine be ready to be called immediately.

4D External Mover

There are 3 resource types used for 4th Dimension externals plus any additional resources required by your external procedure. They are 4DEX, 4DTE, and 4BND.

4DEX contains the code for your external procedure. Each procedure must have only one 4DEX resource. Therefore, if your procedure compiles to more than one code segment, you must use linker commands to join the code segments.

4DTE contains the comments about the external procedure. The information in 4DTE resources, appear in the comments field in 4D External Mover, for the associated 4DEX code.

4BND contains the bundling information needed by 4D External Mover to properly copy your external routines and bundled resources to other files. Bundling ensures that when you use the 4D External Mover to transfer an external to another file, that you get all necessary resources which have been bundled with that external procedure.

When 4D External Mover copies external procedures and any associated resources, specified in the bundle, it checks the global resource id’s of resources currently in the file. If the resource id of the external you want to install is already in use, then 4D External Mover will change the global id of the resource being copied. If the id changes, 4D External Mover will also update the bundle information for that external procedure. Because the resource id may change when the resource is later copied, it is important to not access needed resources directly via the global resource id, unless you are sure the id is correct. Following is example code for obtaining the global id of resources which may have moved. This code is from the 4th Dimension Utilities and Developers Notes.

{The CurProcResid function is assembly}
{code which returns the 4BND resource}
{number.}

function CurProcResid:Integer;
INLINE $3EAD, $DE4E;

function GetResNum(T:ResType; Localid:Integer):Integer; FORWARD;
.
. Your code here
.

{Pass GetResNum the resource type and}
{the local id and it will return the}
{global id.}

function GetResNum;

type
 ResEntry = record
 Typ:ResType;
 LocalNum, GlobalNum:Integer;
 end;
 ResTab = record
 nbEntry:Integer;
 Tab:array[1..1] of ResEntry;
 end;
 ResTabPtr = ^ResTab;
 ResTabHandle = ^ResTabPtr;

var
 i:Integer;
 r:ResTabHandle;
 Done:Boolean;

begin
 GetResNum:=0;
 Done:=False;
 i:=1;
 {Get the pointer to 4BND resource}
 r:=POINTER(GetResource(‘4BND’,
 CurProcResId));
 {make sure we found the resource}
 if r<> Nil then
 begin
 {Cycle thru all the entries in the}
 {4BND resource}
 while((i<=r^^.nbEntry) and
 (Not(Done))) do
 begin
 {loop until we find the one with}
 {the localID and the type we want}
 with r^^.Tab[i] do
 begin
 {check for a match}
 if (t=Typ) and
 (LocalNum=LocalId) then
 begin
 {we found it, so return the}
 {GlobalID to the calling routine}
 GetResNum:=GlobalNum;
 Done:=True;
 end; {if}
 end; {with}
 i:=i+1;{increment our entry counter}
 end;   {while}
 end;   {if r<>Nil}
end;    {GetResNum}

4th Dimension and external procedures can significantly improve your programming efficiency. 4th Dimension can fulfill most of your program development and data management needs. External procedures can supplement 4th Dimension by providing an open architecture and greater flexibility. This document provided the information you need to create and install external procedures to 4th Dimension. I hope this will help you to create externals to make your 4th Dimension databases and applications insanely great.

 
AAPL
$100.75
Apple Inc.
+0.64
MSFT
$46.36
Microsoft Corpora
-0.08
GOOG
$577.36
Google Inc.
+1.00

MacTech Search:
Community Search:

Software Updates via MacUpdate

QuickBooks 2015 16.0.0.1352 R1 - Financi...
QuickBooks 2015 helps you manage your business easily and efficiently. Organize your finances all in one place, track money going in and out of your business, and spot areas where you can save.... Read more
Mac DVDRipper Pro 5.0.1 - Copy, backup,...
Mac DVDRipper Pro is the DVD backup solution that lets you protect your DVDs from scratches, save your batteries by reading your movies from your hard disk, manage your collection with just a few... Read more
Apple OS X bash Update 1.0 - Fix for sec...
The OS X bash Update fixes a security flaw in the bash UNIX shell on OS X 10.9.5 (also on OS X 10.8 and 10.7 [see Related Links below]). OS X 10.9.5 or later Downloads for OS X 10.8 and OS X 10.7 in... Read more
SyncTwoFolders 2.0.5 - Syncs two user-sp...
SyncTwoFolders simply synchronizes two folders. It supports synchronization across mounted network drives and it is a possibility to run a simulation showing in a log what will be done. Please visit... Read more
FinderPop 2.5.7 - Classic Mac utility, n...
FinderPop is a Universal preference pane that extends OS X's contextual menus using a FinderPop Items folder much as the Apple Menu Items folder used to do for the Apple menu. It has other features... Read more
VueScan 9.4.45 - Scanner software with a...
VueScan is a scanning program that works with most high-quality flatbed and film scanners to produce scans that have excellent color fidelity and color balance. VueScan is easy to use, and has... Read more
LibreOffice 4.3.2.2 - Free Open Source o...
LibreOffice is an office suite (word processor, spreadsheet, presentations, drawing tool) compatible with other major office suites. The Document Foundation is coordinating development and... Read more
calibre 2.4 - Complete e-library managem...
Calibre is a complete e-book library manager. Organize your collection, convert your books to multiple formats, and sync with all of your devices. Let Calibre be your multi-tasking digital... Read more
Default Folder X 4.6.9b1 - Enhances Open...
Default Folder X attaches a toolbar to the right side of the Open and Save dialogs in any OS X-native application. The toolbar gives you fast access to various folders and commands. You just click... Read more
Beamer 2.0.4 - Stream any movie file fro...
Beamer streams to your Apple TV.... Plays any movie file - Just like the popular desktop movie players, Beamer accepts all common formats, codecs and resolutions. AVI, MKV, MOV, MP4, WMV, FLV. To... Read more

Latest Forum Discussions

See All

WW2: Sandbox. Strategy & Tactics (G...
WW2: Sandbox. Strategy & Tactics 1.0.0 Device: iOS Universal Category: Games Price: $9.99, Version: 1.0.0 (iTunes) Description: Sandbox is the unlimited sequel to our Strategy & Tactics: World War II. We've abandoned... | Read more »
apeFilter (Music)
apeFilter 1.0 Device: iOS Universal Category: Music Price: $6.99, Version: 1.0 (iTunes) Description: | Read more »
Shred It! Review
Shred It! Review By Jennifer Allen on September 30th, 2014 Our Rating: :: GORGEOUS BUT BASICUniversal App - Designed for iPhone and iPad It might look lovely, but Shred It! is a pretty shallow endless runner/snowboarding game.   | Read more »
It Came From Canada: Angry Birds: Transf...
Anyone afraid that throwing Transformers into the Angry Birds mix would result in a Michael Bay-level of childhood pillaging can rest easy. While Rovio’s famous fowls may be a 21st century staple, Angry Birds: Transformers wears its affection for... | Read more »
Galaxy Trucker Review
Galaxy Trucker Review By Rob Thomas on September 30th, 2014 Our Rating: :: IN FOR THE LONG HAULiPad Only App - Designed for the iPad We got a great big convoy, rockin’ through the night… the endless night of outer space, that is.... | Read more »
Moon and Sun – children’s book Review
Moon and Sun – children’s book Review By Amy Solomon on September 30th, 2014 Our Rating: Moon and Sun is a fable-like children’s book with lush illustrations.   Developer: Marcio Monteiro Price: $3.99 Version: 1.0 App Reviewed on... | Read more »
Kairosoft Finally Brings The Pyraplex to...
Kairosoft Finally Brings The Pyraplex to iOS Posted by Jessica Fisher on September 30th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Yeti’s Parole Officer Review
Yeti’s Parole Officer Review By Jennifer Allen on September 30th, 2014 Our Rating: Universal App - Designed for iPhone and iPad Yeti’s Parole Officer proves that looks aren’t everything in this entertaining, if plain, piece of... | Read more »
Record Keeper and World Wide Words – Two...
Record Keeper and World Wide Words – Two New Final Fantasy Games Arrive on iOS in Japan Posted by Ellis Spice on September 30th, 2014 [ permalink ] | Read more »
iPollute Review
iPollute Review By Nadia Oxford on September 30th, 2014 Our Rating: :: iPOLLUTE, uPOLLUTEUniversal App - Designed for iPhone and iPad iPollute is a delightful-looking pollution simulator, though it’s a bit light on “game” content... | Read more »

Price Scanner via MacPrices.net

Apple Boycotts German Magazine Computer Bild...
Apple has revoked its PR accreditation of Germany’s Computer Bild, Europe’s best-selling PC magazine, in reaction to Bild’s posting of a “#Bentgate” YouTube video. Axel Telzerow, editor in chief of... Read more
iPhone 6 & iPhone 6 Plus Available in Chi...
Apple has announced that iPhone 6 and iPhone 6 Plus will be available in China beginning Friday, October 17 from the Apple Online Store (http://www.apple.com), Apple’s retail stores, and an expansive... Read more
MacBook Airs on sale for $100 off MSRP, start...
Best Buy has the new 2014 MacBook Airs on sale for $100 off MSRP on their online store. Choose free home shipping or free local store pickup (if available). Prices valid for online orders only, in-... Read more
Apple Releases OS X Mavericks bash Update 1.0...
Apple has released a patch update for OS X Mavericks users to address the recently-detected “Shellshock” security bug in BSD UNIX’s bash shell. Apple says only a few Mac users who had manually... Read more
Pivotal Payments Ready for Apple Pay – FlexPo...
Pivotal Payments, a provider of merchant services and global payment processing solutions, has announced its proprietary FlexPoint platform will support credit and debit transactions through Apple’s... Read more
iStabilizer Announces Tabarm — First Friction...
iStabilizer, a specialist in universal lightweight compact tripods, steady cams, dollies, mounts, and remotes for smartphones, tablets, and cameras, announced today the iStabilizer tabArm, the first... Read more
IStabilizer Flex Smartphone Tripod Wins Usa T...
iStabilizer, a specialist in universal lightweight compact tripods, steady cams, and other products for smartphones, tablets, and cameras, has announced today that its iStabilizer Flex smartphone... Read more
13-inch 2.8GHz Retina MacBook Pro on sale for...
B&H Photo has the new 2014 13″ 2.8GHz Retina MacBook Pro on sale for $1699.99 including free shipping plus NY sales tax only. They’ll also include free copies of Parallels Desktop and LoJack for... Read more
15-inch Retina MacBook Pros on sale for up to...
B&H Photo has the new 2014 15″ Retina MacBook Pros on sale for up to $150 off MSRP. Shipping is free, and B&H charges NY sales tax only. They’ll also include free copies of Parallels Desktop... Read more
Get Down to Business On Your iPad With Free N...
Utah based Poem LLC has introduced Nexticy 1.0, a full-featured, affordable (Free) forms application for iPad. Nexticy makes it ‘way easy’ to create, store, retrieve and analyze paper-like forms of... Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
Senior Event Manager, *Apple* Retail Market...
…This senior level position is responsible for leading and imagining the Apple Retail Team's global event strategy. Delivering an overarching brand story; in-store, Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.