Using controls in applications
Create an application named OcxProgressBarApp and add a visual part name ElapsedTimeView.
In the Composition Editor that opens, select the OLE Control part from the OLE category and drop the part on the window.
Open the settings for the OLE Control part and change them as follows:
1. For clientName, select ESPROGRESSBAR.ProgressBarCtrl.1.
2. For framingSpec, set the left and right attachments to XmATTACHFORM.
3. Ensure that maximum is set to 100.
4. Close and then reopen the Properties window.
Notice that the control's properties are now shown in the Properties window and that the OLE Control has assumed the characteristics of the progress bar.
Next, press mouse button 2 on the control and, from the popup menu, select Quick Form. Select Position from the displayed list and click on the window. By changing the value for the Position property, you can change the extent to which the progress bar fills.
For example, select Test icon, type a number between 1 and 100 in the Position field, and click on the progress bar.
To complete the application, add three labels, a spin button, and two push buttons. Rename and rearrange the parts so your application resembles the one shown in Adding OLE controls.
Change the settings for the spin button so maximum is set to 100 and minumum is set to 1. Rename the label indicating the number of elapsed seconds to Elapsed Seconds.
Finally, add two scripts that will fill the progress bar as time elapses and reset the progress bar's Position property to 0. The scripts are trackTime and resetProgressBar:
trackTime
"Show elapsed time in the Elapsed Time label and in the progress
bar control. For each second that elapses, bump time + 1 until
timeToElapse is reached."
| startTime secondsToRun timeToElapse index olePos oleProg oleCurr |
startTime := Time now asSeconds.
secondsToRun := (self subpartNamed: 'Spin Button1') object.
timeToElapse := startTime + secondsToRun.
index := 0.
olePos :=(self subpartNamed: 'PositionField') object.
oleProg := ((100 - olePos)/secondsToRun) rounded.
[ (timeToElapse - startTime) timesRepeat:
(Delay forSeconds: 1) wait.
index := index +1.
(self subpartNamed: 'Elapsed Seconds') object: index.
oleCurr :=(self subpartNamed:'PositionField') object.
(self subpartNamed: 'PositionField')
object: (oleProg + oleCurr).] ]
forkAt: Processor userBackgroundPriority
resetProgressBar
"Reset the progress bar control and the Position field to 0."
(self subpartNamed: 'PositionField') object: 0
Return to the Composition Editor and make two connections:
Connect the clicked event of Start to the trackTime script.
Connect the clicked event of Reset to the resetProgressBar script.
After you make the connection, the Composition Editor resembles the following:
OLE example
Now, test the application: select Test icon, pick a number in the spin button, and select Start. Using Reset, you can set the Position property of the progress bar to 0.
Last modified date: 07/22/2020