Announcement

Collapse
No announcement yet.

Object constructor

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Brian Chirgwin
    replied
    Factory Method Pattern

    I tried several ideas nothing panned out.

    You could use the following design pattern (or others).



    Originally posted by Mark Smit View Post
    Hey guys,

    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?

    Thanks

    Leave a comment:


  • Fred Harris
    replied
    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.

    Doesn't PB implement Try - Catch - Throw? I'm pretty sure it does.

    Leave a comment:


  • Edwin Knoppert
    replied
    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.

    It's somewhere on msdn (years ago )

    Leave a comment:


  • Mark Smit
    replied
    Throw

    Hey guys,

    Thanks for the ideas

    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.

    Thanks again!

    Leave a comment:


  • Edwin Knoppert
    replied
    ideas = no more..

    Leave a comment:


  • Michael Mattias
    replied
    If you don't generate any bad ideas, you are not generating enough ideas.

    Leave a comment:


  • Edwin Knoppert
    replied
    Unsetting from inside the object is a serious no no!

    Leave a comment:


  • Michael Mattias
    replied
    Pure guess.... I have no clue what would happen here....

    If init fails, set object to NOTHING and then use ISOBJECT()?

    Leave a comment:


  • José Roca
    replied
    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.

    Leave a comment:


  • Mark Smit
    started a topic Object constructor

    Object constructor

    Hey guys,

    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?

    Thanks
Working...
X