Announcement

Collapse
No announcement yet.

Another Class migration problem (sorry)

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

  • Another Class migration problem (sorry)

    I'm felling really noobyish but I'm stumped.

    And yes I know extracts of pieces of code are more difficult but posting the whole program is just not possible:

    I've been migrating to a more class oriented approach, and with a few stumbles, it has been going quite well. This was just another global table being converted, like others before it, but this one is balking.

    I'm getting a data type mismatch on a method call and I'm stumped.

    Here's some extracted stuff:
    Code:
    In the equates etc. .INC file
    
    TYPE LCtlCmd                                             ' Final Line Command entry (After validation)
       SrcCmd  AS STRING * 4                                 ' Source Command (C, M, CC, etc.)
       SrcFrom AS LONG                                       ' Source Start Line number
       SrcTo   AS LONG                                       ' Source End Line number
       SrcRepeat  AS LONG                                    ' Source Repeat
       DstCmd  AS STRING * 4                                 ' Dest Command (A, B, OO, etc.)
       DstFrom AS LONG                                       ' Dest Start Line number
       DstTo   AS LONG                                       ' Dest Eend Line number
       DstRepeat  AS LONG                                    ' Dest Repeat
    END TYPE
    
    In the Class definition .INC file
    
       INSTANCE LTblB()     AS LCtlCmd                       ' Complete line command list
    
    in the constructor method of the class
    
      DIM LTblB(500)  AS INSTANCE LCtlCmd                    ' Complete line command list
      
    In the INTERFACE section of the CLASS
    
      METHOD LTblBGet (BYVAL ix AS LONG) AS LCtlCmd: METHOD = LTblB(ix): END METHOD
    
    in a SUB in the main module (TabP is the created CLASS, works for all kinds of other METHOD's & PROPERTIES)
    
    LOCAL w AS LctlCmd
      w = TabP.LTblBGet(1)                               ' Copy 1st entry to work data
    
    Results in:
    
    Error 482 in D:\Public\DOCUME~1\SPFLite\SPFLIte4.BAS(3608:011):  Data type mismatch
    Line 3608:        w = TabP.LTblBGet(1)
    I've done the almost identical conversion of another UDT array without problem. This should really have been a "change all TblA to TblB" type migration but it's not. To me, everything says the data type is LCtlCmd, what other definition is the compiler seeing?

    George

  • #2
    I believe you can not return a custom variable, afaik it must be a com-compliant variabletype.
    You can return a pointer though.

    Btw, i was trying to do this for declaration:

    Dim LTblB( 0 To 500 ) As Instance LCtlCmd
    Then you would not redim it afterwards.
    This is the same as i do like:
    Dim LTblB( 0 To 500 ) As Local LCtlCmd

    However, i can not make this instance dim to work, so this seems a two steps process after all.
    Just curious..
    hellobasic

    Comment


    • #3
      Hi,

      can you compile this? I think it does what it should:
      Code:
      TYPE LCtlCmd                                             ' Final Line Command entry (After validation)
         SrcCmd  AS STRING * 4                                 ' Source Command (C, M, CC, etc.)
         SrcFrom AS LONG                                       ' Source Start Line number
         SrcTo   AS LONG                                       ' Source End Line number
         SrcRepeat  AS LONG                                    ' Source Repeat
         DstCmd  AS STRING * 4                                 ' Dest Command (A, B, OO, etc.)
         DstFrom AS LONG                                       ' Dest Start Line number
         DstTo   AS LONG                                       ' Dest Eend Line number
         DstRepeat  AS LONG                                    ' Dest Repeat
      END TYPE
      
      class myClass
        INSTANCE LTblB()     AS LCtlCmd                       ' Complete line command list
      
        class method create()
          DIM LTblB(500)  AS INSTANCE LCtlCmd                    ' Complete line command list
          
          ' -- Some init data
          LTblB(1).SrcCmd = "AHOY"
        end method
        
        interface myInterface
          inherit iUnknown
          
          METHOD LTblBGet (BYVAL ix AS LONG) AS LCtlCmd
          
            METHOD = LTblB(ix)
            
          END METHOD
        
        end interface
      end class
      
      function pbmain
        local TabP as myInterface
        
        TabP = class "myClass"
        
        LOCAL w AS LctlCmd
        w = TabP.LTblBGet(1)
        msgbox w.SrcCmd
      end function

      Petr
      [email protected]

      Comment


      • #4
        Yes, this works, i found out my issue with dual interfaces and thus does not apply to this code:

        (25:050): Incompatible with a Dual/IDispatch interface
        Line 25: Method LTblBGet (ByVal ix As Long) As LCtlCmd

        hellobasic

        Comment


        • #5
          Petr:

          Your sample gives me the same error. Are you saying it compiles clean for you?

          Edwin:

          I had just completed an almost identical UDT table (TblA) without problems. But on checking back, the actual METHOD to return the whole entry happens to not be called by the main line, just method calls to fetch/set individual fields of the UDT. So I hadn't actually done this successfully before.

          The Help file says:

          Methods may be declared (using AS type...) to return a string, any of the types, a specific class of object variable (AS MyClass), a Variant, or a user defined Type

          So it says it should work. Petr says it works for him.

          What am I missing?

          George

          Comment


          • #6
            What am I missing?
            Telling us which version of the compiler are you using. I bet you're using PB 9.00 instead of 9.01.

            Update your compiler (it's free) or change

            Code:
            w = TabP.LTblBGet(1)
            to

            Code:
            TYPE SET w = TabP.LTblBGet(1)
            Forum: http://www.jose.it-berater.org/smfforum/index.php

            Comment


            • #7
              Jose:

              Bingo! Yes, I'm still @ 9.00. I'm afraid I've always taken the approach of not upgrading software just because a new version is available. I've been burned in the past (not PB however) with upgrades causing problems, so I have a natural reluctance and upgrade when there's a specific fix / new feature I want.

              This time it cost me. I guess there's no 'always win' condition.



              George
              (heading to Update-Land)

              Comment


              • #8
                For com programming it's good to move from 9.00 to 9.01.
                There was a typelib issue which is solved as well, i find that specific issue an important one.
                hellobasic

                Comment


                • #9
                  There were MANY good reasons to move from 9.0.0 to 9.0.1

                  After all, 9.0.0 DOES end with "0.0", right?
                  Michael Mattias
                  Tal Systems (retired)
                  Port Washington WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment

                  Working...
                  X