Ask Dr. DePhobia - Questions and Answers about Clarion
Posted September 1 1998
Q:
I want to use functions from my application in ReportWriter reports. These functions perform some special formatting that I need printed. I use them in my compiled reports, but I want the end-users to be able to use them in the reports they create too. Can you help with my question?
A:
Questions are easy. It's the answers that are tough. But seriously, ReportWriter allows you to use external functions. All you have to do is follow a few simple rules.
First of all, remember that all external functions used with ReportWriter accept only STRING parameters and must return a STRING. Of course, that does not prevent you from passing a numeric value (such as a value contained in a LONG) to a function. The Clarion language provides automatic conversion between data types. Just be aware of the conversion rules and keep in mind that some assignments can produce an unequal value in the source and destination. See "Data Type Conversion Rules" in the Language Reference or online help for details.
Second, you must "register" the external resource in a ReportWriter report library. In order to do this, you must know the function's exported name. The easiest way to know the exported name is to tell it the name to use! Use the NAME attribute when defining your function and that is the exported name.
For example:
DOW PROCEDURE(InDate),NAME('DOW')
Note: Perhaps you noticed that I use PROCEDURE instead of FUNCTION. These are completely equivalent and interchangeable. The FUNCTION statement is now a legacy statement (still supported, but only for backward compatibility).
Now for the rest of the function...
PROGRAM
MAP
DOW PROCEDURE(STRING),STRING,NAME('DOW') ! Returns Day of Week
END
CODE
DOW PROCEDURE(InDate)
DayGroup GROUP,PRE()
S1 STRING('Sunday {3}')
S2 STRING('Monday {3}')
S3 STRING('Tuesday {2}')
S4 STRING('Wednesday')
S5 STRING('Thursday {1}')
S6 STRING('Friday {3}')
S7 STRING('Saturday {1}')
END
WhichDay STRING(9),DIM(7),OVER(DayGroup)
CODE
RETURN(WhichDay[(InDate % 7) + 1])
This function accepts a date (a Clarion Standard Date, a LONG as a STRING) and returns a STRING containing the day of the week.
Compile this as a DLL.
Next, you must "register" the external function it in a Report Library.
From the Report Library window:
- Choose File > Externals.
- Press the New External button.
This is where you tell ReportWriter how it will access the external function or variable.
- Complete the information on the External dialog. As shown in the graphic below:

The DOW function is now available in ReportWriter's formula editor.
- Use the DOW function in any computed or conditional field.

The report now prints the day of the week for each record.
Q:
I am deploying both 16- and 32-bit versions of my application. I know I have to compile it twice, but sometimes I forget to change the Target File filename and I overwrite one version with the other. Is there some way I can prevent this?
A:
Perhaps a memory course? Seriously, we rely on our tools so we don't have to remember everything. And Clarion is one of those tools that has the functionality to free your mindfor important things.
There is a very simple answer. The Project System has expansion macros that enable it to name the Target file according to the target OS for which it is compiled. These macros are:
%X% - Expands to nothing in 16-bit and to 'X'in 32-bit mode
%S% - Expands to '16' in16-bit or '32' in 32 bit-mode.
Just set your project's Target File in a similar manner as shown in the graphic below:

When compiled in 32-bit mode, this project creates EvtMgrX.EXE, when compiled in 16-bit mode, it makes EvtMgr.EXE.
Now all you have to remember is which one is which.
Article comments
Post a comment
You must be logged on to post comments.
Talk To Us!
Search ClarionMag
From the archives
Sending Clarion Reports as Email Attachments (Part 1)
1/9/2001 12:00:00 AM
The email capability in version 5.5 is a nice addition to the Clarion toolset. What is still missing however, is the ability to easily send a report as an email attachment. In this article David Potter demonstrates one possible solution to this problem. Part 1 of 2.
