OCX Controls & software technologies
Borland C++ Builder users' page

This page is dedicated to all the non-professional C++ Builder developers who have never used an ActiveX control before and would like to learn the basics and a quick hands-on start. In this tutorial we will build a digital clock in 10 easy steps, using Precision 7 Segment Digital Display, nonetheless this tutorial should be useful even for the use of the other Precision controls.


  • Step 0: Make sure that the "Digital 7 Segments Display ActiveX Control Module" is correctly registered. To do that, follow the instructions in the FAQ section.

  • Step 1: Open Borland C++ Builder 6.0; from the "Component" menu select "Import ActiveX control...". A dialog like the one below appears. Select "Digital 7 Segments Display ActiveX Control module", then click "Install...".

  • Step 2: The "Install" dialog box appears. Select "Into existing package" or "Into new package" at your convenience, in the second case you will have to provide a name for the package to be created. Press "ok", a couple of confirmation dialogs will warn you that the package is going to be built and installed, and then that it was successfully built and installed. Close the package project, you will be asked to save (answer yes), the go back to "Project1" window.

  • Step 3: On the component toolbar select the "ActiveX" tab, then the control icon (the one with the "01", indicated by the arrow). Place it on the form "Form1".

  • Step 4: On the component toolbar select the "System" tab, then the timer icon (the one with the little clock, indicated by the arrow). Place it on the form "Form1".

    After adding these two components, your Form should resemble the following figure:

  • Step 5: In the form above, click on the timer icon to select object "Timer1": the "Object Inspector" window will now show properties for the "Timer1" object. Inside "Object Inspector" click on the "Events" tab, and in the "OnTimer" field, write "OnTimer". When you press Enter, the source code window will show the body of the TForm1::OnTimer method.

  • Step 6: Focus on the source code window, which is open on file "Unit1.cpp". You will need to add three sections of code:

    1. Before any other line, add the following line:
                #include <stdio.h>
                
    2. To proceed through this step you will need a valid licence number. If you will not call SetLicense providing a valid license number to the component, it will simply fail to show at runtime. Inside the constructor TForm1::TForm1, add the following line:
                Digital7SegmentsDisplay1->SetLicense( <put here your license number> );
                
    3. Now locate the following method: TForm1::OnTimer(),
                SYSTEMTIME time;
                GetLocalTime(&time);
                char strBuffer[9];
                sprintf(strBuffer,"%02i:%02i:%02i", time.wHour, time.wMinute, time.wSecond);
                Digital7SegmentsDisplay1->DisplayedString = strBuffer;
                

    The full listing, containing all the above additions, is shown in the following figure.

  • Step 7 - Finished: Simply run your program by pressing F9 to see your new digital clock running!


Copyright © 2002, by Daniele Paolo Scarpazza. All rights reserved.