Announcement

Collapse
No announcement yet.

Oop

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

  • #21
    Why bother with variants if they are not needed?

    From my snippet in post #1 (PB6.x code)

    Code:
    #COMPILE EXE
    #DEBUG ERROR ON
    #DEBUG DISPLAY ON
    #BREAK ON
    
    DEFLNG I - N
    
    FUNCTION PBMAIN () AS LONG
    
    LOCAL CfgStr() AS STRING
    
    LOCAL NumRecs AS LONG
    
    LOCAL Fetch AS CFG
    
    Fetch = CLASS "GSDATA"
    
    Fetch.Recs("diploactions.cfg", NumRecs)
    DIM CfgStr$(1 TO NumRecs)
    
    Fetch.CFG("diploactions.cfg", VARPTR(CfgStr$(1)))
    
    FOR I = 1 TO NumRecs
    PRINT CfgStr$(I)
    NEXT I
    
    WAITKEY$
    END FUNCTION
    
    '/===========================================================================================/'
    ' CLASSES
    '/===========================================================================================/'
    
    CLASS GSDATA
    
    INSTANCE NumRecs AS LONG
    
    INTERFACE CFG
    INHERIT IUNKNOWN
    
    '--------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------
    
    METHOD Recs(BYVAL Fname AS STRING, Recs AS LONG)
    
    Recs = 0
    IF DIR$(Fname$) = "" THEN EXIT METHOD
    
    OPEN Fname FOR INPUT AS #1
    FILESCAN #1, RECORDS TO Recs
    CLOSE #1
    
    Me.NumLines = Recs
    END METHOD
    
    '--------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------
    
    METHOD CFG(BYVAL Fname AS STRING, BYVAL AryAddr AS DWORD)
    
    LOCAL Recs AS LONG
    
    LOCAL CfgStr() AS STRING
    
    Recs = Me.NumLines
    DIM CfgStr$(1 TO Recs) AT AryAddr
    
    OPEN Fname$ FOR INPUT AS #1
    LINE INPUT #1, CfgStr$() TO Recs
    CLOSE #1
    
    END METHOD
    
    '--------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------
    
    PROPERTY GET Numlines() AS LONG
    PROPERTY = NumRecs
    END PROPERTY
    
    '--------------------------------------------------------------------------------------------
    '--------------------------------------------------------------------------------------------
    
    PROPERTY SET NumLines(BYVAL Recs AS LONG)
    NumRecs = Recs
    END PROPERTY
    
    END INTERFACE
    END CLASS
    The data file:
    Code:
    <GERMANY>
      TRADE
      DIPLOMACY
    <END GERMANY>
    <USSR>
      TRADE
      DIPLOMACY
    <END USSR>
    <ITALY>
      TRADE
      DIPLOMACY
    <END ITALY>
    <JAPAN>
      TRADE
      DIPLOMACY
    <END JAPAN>
    <USA>
    <END USA>
    <ENGLAND>
      TRADE
      DIPLOMACY
      GIFT
      COLLABORATE
    <END ENGLAND>
    <FRANCE>
      TRADE
      DIPLOMACY
    <END FRANCE>
    Walt Decker

    Comment


    • #22
      Originally posted by José Roca View Post
      Code:
      'PB 10.04
      'using Jose's includes
      #COMPILE EXE
      #DIM ALL
      #INCLUDE "win32api.inc"
      
      FUNCTION PBMAIN () AS LONG
      
      LOCAL v AS VARIANT
      LOCAL pv AS tagVariant PTR
      LOCAL psa AS DWORD
      DIM strA(1 TO 10) AS STRING
      DIM LB AS LONG
      DIM UB AS LONG
      strA(3) = "Test"
      v = strA()
      pv = VARPTR(v)
      psa = @pv.parray
      SafeArrayGetLBound psa, 1, LB
      SafeArrayGetUBound psa, 1, UB
      ? USING$("# # ",LB,UB)
      
      END FUNCTION
      Thank you José!

      Comment


      • #23
        [QUOTE=Walt Decker;n770575]Why bother with variants if they are not needed?

        [/QUOTE}

        Because your original query was about passing an Array to Method,
        "It appears that a method in pb objects can't accept an array as an imput parameter. Is this correct?"
        and wrapping the Array in a Variant is a simple solution.

        Comment

        Working...
        X