MSCAL.OCX
from Didier Leduc
Using Ocx's with Clarion has always been a challenge for beginners as well as for more experienced programmers.
The documentation is too technical to be use effectively by novices.
This article does not provide an in-depth information about the architecture of an Ocx but rather a simple way to show you how to incorporate smoothly an object of the ActiveX type (new word for Ocx) in your applications.
To do this we will use the Microsoft calendar MSCAL (included with MS-Office 97 and 2000).
Notice that this technique applies also for lots of Microsoft Windows components.
We will use a Freeware product called OLEGEN to create all needed ABC class definitions for us.
You can download a copy of Princen-It OLEGEN here oleg10b3.zip
Install OLEGEN, then start:
Search for MSCAL.OCX in the C:\WINDOWS\SYSTEM32\ directory
Set the output directory to your clarion\libscr directory then press start.
- MSCAL.CLW - procedures and classes
- MSCAL.INC - declarations
will be created in your .\ LIBSRC directory
That's all for the declarions needed by MSCAL !
Inside Clarion:
To be able to test we will create a small application. For this demo we do not need to declare a DCT.
Register OLEGEN :
- SETUP template
Create a new app:
- Create a new procedure Window
- Select the button WINDOW
- Select the button CONTROL TEMPLATE
- Select OLEOBJECTCONTROL
(Careful, do not use OCXCONTROL from Clarion !)- Place the control on the screen
- Select ok to leave the screen formatter
- Select EXTENSIONS
- Select OLE/OCX
- Uncheck DEFAULT OLE ABC
- Check OLE APPLICATION BUILDER CLASS
- Select OLEAUTO:MSACAL :CALENDAR
- Leave EXTENSIONS
We need to create some local variables to be able to test the calendar.
- Select the DATA button
- Make sure to use SHORT for the month, day and year to follow the declaration in the include (INC) file generated by OLEGEN.
- select OK to leave the data
- Select the WINDOW button to get the screen formatter.
- Set the variable l :date on the screen.
- Double click on the OCX control to open the EMBEDS
- Select OLE/OCX CONTROL EXECUTABLE CODE SECTION
- (see below)
It is possible to use the METHODS from the source.
- Select CALLABCMETHOD
- Select the object .
- Select the object name from the pull-down menu (in this case OleObject1)
- Select the method to call & set the variable name to receive the information from the OCX.
- Do the same for the month with GetMonth() and the year with GetYear()
- The last thing to do is to update the local variable l:date with the values given by the OCX control.
In the EMBEDS just bellow the last input (see above) open a Source and write the following code:
- Close the EMBEDS
- Set the control variable (L:Date) on the screen.
- Set a Button QUIT on the screen
- In PROPERTIES/EXTRA for this button, select STD :CLOSE
- Close all and compile.
- The final result should be as shown below.
Remark: The month name on this demo is in Dutch as I am living in the Netherlands and the OCX uses the windows country parameters.
The variable prompt is in French as I was born there.
- Click on the OCX and control that the date is changing in the local date field.
Benschop le 25/02/2000
Didier Le Duc