Announcement

Collapse
No announcement yet.

Object constructor

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

  • 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
    Start as you mean to go on.

  • #2
    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.
    Forum: http://www.jose.it-berater.org/smfforum/index.php

    Comment


    • #3
      Pure guess.... I have no clue what would happen here....

      If init fails, set object to NOTHING and then use ISOBJECT()?
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        Unsetting from inside the object is a serious no no!
        hellobasic

        Comment


        • #5
          If you don't generate any bad ideas, you are not generating enough ideas.
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            ideas = no more..
            hellobasic

            Comment


            • #7
              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!
              Start as you mean to go on.

              Comment


              • #8
                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 )
                hellobasic

                Comment


                • #9
                  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.
                  Fred
                  "fharris"+Chr$(64)+"evenlink"+Chr$(46)+"com"

                  Comment


                  • #10
                    Factory Method Pattern

                    I tried several ideas nothing panned out.

                    You could use the following design pattern (or others).
                    http://en.wikipedia.org/wiki/Factory_method_pattern


                    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

                    Comment

                    Working...
                    X