Enumerating instances

Question:
I want to use many instances of a class in my form, but can’t seem to figure out an easy way to check on the status of all the instances at once.

Answer:
There are two separate problems for you to deal with. The first is the need to enumerate through the objects in your form. You can accomplish this by using a form property, FirstChild, and an object level method, NextControl().

Each form has a FirstChild property, which is a reference to the first object in the internal list of objects that belong to a form. You can create an object variable and set it to reference this object. To enumerate through the objects on a form, you can set up a DO loop to iterate through the objects on the form with the NextControl() method of the current object, which returns either a reference to the next control in the form or a null value. The code for this procedure for a form named frmMain looks like this:

DIM objNext AS ObjectobjNext = frmMain.FirstChildDO UNTIL ISNULL(objNext)        conditional code        objNext = objNext.NextControl()LOOP

The enumeration described above will cycle through objects one level below the containing form. This means it will pick up the instance of a class on the form but not any objects contained in the form.

You can identify instances of a class with the HasProperty operator, which is new in OPO version 1.0.16. The HasProperty operator returns True if the object on the left has the property on the right and False if it doesn’t. If the class you were looking for has a property called “udpRequired”, the code for the above loop would look something like this:

DIM objNext AS ObjectobjNext = frmMain.FirstChildDO UNTIL ISNULL(objNext)        IF objNext HasProperty udpRequired THEN                conditional code        END IF        objNext = objNext.NextControl()LOOP

For instance, you can use the conditional code to test for a failure condition. If the failure condition is true, you can use EXIT DO to leave the loop. You can easily determine if any of the class instances caused a failure by checking the value of objNext after the loop. If there were no failures and the loop ended naturally, objNext will be null, otherwise, objNext will contain a reference to the first instance of the class that failed.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

homes in the real estate industry

Exploring the Latest Tech Trends Impacting the Real Estate Industry

The real estate industry is changing thanks to the newest technological advancements. These new developments — from blockchain and AI to virtual reality and 3D printing — are poised to change how we buy and sell homes. Real estate brokers, buyers, sellers, wholesale real estate professionals, fix and flippers, and beyond may