You are not logged in. You can browse in the PowerBASIC Community, but you must click Login (top right) before you can post. If this is your first visit, check out the FAQ or Sign Up.
Does anyone know how to force an object to fail during creation? Is there some way in the CREATE method to bail out if something doesn't initialize properly?
I once wrote a grid control in C++ and my constructor didn't do much - which makes sense. Then I created an initiate method where the properties of the grid are set, windows created, etc. In that kind of situation you can check for failed procedure calls and set flags, etc. I believe a PB constructor is like a C++ constructor in that it doesn't return a value, so its probably not a good idea to put code in there that can fail.
Later on i thought the same about try catch however, i ever read something about activex that rules say that once one instance can be created all next instances should be able to instantiate.
This is not a technical matter but just expected activex behaviour.
The whole reason I asked is because I was reading Game Coding Complete when I came across chapter 7 which discusses object initialization. The author showed an example if initializing an object in the constructor. In the event of an error it would throw an exception. To my knowledge PB doesn't offer the same TRY CATCH as C++ so I thought I'd ask to see how it could be done in PB lingo.
Looks like Jose's example will be "the way" for now.
You can't, but you can use an instance variable as a flag, implement a method or property that returns the value of the flag and check it after the object has been created.
Does anyone know how to force an object to fail during creation? Is there some way in the CREATE method to bail out if something doesn't initialize properly?
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: