Announcement

Collapse
No announcement yet.

STRPTR functionality wish

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

  • Aldo Cavini
    replied
    Peter,

    good idea. I also had the idea to assign the string equate to a static/global string, but didn't thought about using an array

    Aldo

    ------------------

    Leave a comment:


  • Peter P Stephensen
    replied
    Hi Aldo,

    I use the following inc-file:
    Code:
    #if not %def(%TEXT_INC)
    %TEXT_INC = 1
     
    %TEXT = 1
    %FreeTEXT = 2
     
    global TEXTMemory() as string   ' Would be better as static inside MainTEXTfunc. Not safe in current version of PB.
    function MainTEXTfunc(byval func_id as long, byval s as string) as dword
     
        static n as long
         
        select case func_id
        case %TEXT
            redim preserve TEXTMemory(n)
            TEXTMemory(n) = s
            incr n
            function = strptr(TEXTMemory(n-1)) : exit function
     
        case %FreeTEXT
            n = 0
            redim TEXTMemory(0)
         
        end select
     
    end function
     
    function TEXT(byval s as string) as dword
        function = MainTEXTfunc(%TEXT, s)
    end function
     
    sub FreeTEXT()
        MainTEXTfunc %FreeTEXT, ""
    end sub
     
    #endif '%TEXT_INC
    If you use this as header-file, you can use any of the following
    alternatives:
    Code:
        wc.lpszClassName = TEXT( AsciizVariable )
        wc.lpszClassName = TEXT( StringVariable )
        wc.lpszClassName = TEXT( $StringEquate )
        wc.lpszClassName = TEXT( "MyClassName" )
    Regards
    Peter

    P.S.

    If you like you can free memory using FreeTEXT (you dont have to)

    ------------------
    [email protected]

    Leave a comment:


  • Lance Edmonds
    replied
    Cute... using a function means you can pass string equates BYCOPY/BYVAL and register your window.

    I'm sure there are plenty of places this approach could be used, except when you want the code in line.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Aldo Cavini
    replied
    posted http://www.powerbasic.com/support/pb...ad.php?t=23155

    ------------------

    Leave a comment:


  • Aldo Cavini
    replied
    Edwin, Lance,

    thanks for the replies. Of course I do know how to pass a string by value. What I would like do is the following:
    Code:
    LOCAL wc as WndClassEx 
      ...
      wc.lpszClassName = VARPTR( AsciizVariable )
      ...
      RegisterClassEx wc
    or
    Code:
      wc.lpszClassName = STRPTR( StringVariable )
    without having to use a variable. I mean:
    Code:
      wc.lpszClassName = VARPTR( $StringEquate )
    I thought, since the string equate value is stored somewhere inside the executable file, its address could be retreived at run-time. Never mind...


    ------------------

    Leave a comment:


  • Lance Edmonds
    replied
    It is not possible to obtain a VARPTR or a STRPTR to a String Equate. Think of them as mini-macro's - they are "used" during compile-time, not run-time.

    However, depending on how the API you are calling is declared, you may be able to pass the string equate BYCOPY (which is what Edwin's example above is doing).
    Code:
    ' These all pass bycopy:
    CALL apifunction(BYCOPY $MyString) ' Explicit BYCOPY
    CALL apifunction($MyString + "")   ' Expressions passed BYCOPY
    CALL apifunction(($MyString))      ' Parentheses force evaluation as an expression, hence BYCOPY
    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>

    Leave a comment:


  • Edwin Knoppert
    replied
    I think not but:

    Control Add "" & $HELLO works fine..

    ------------------
    http://www.hellobasic.com

    Leave a comment:


  • Aldo Cavini
    started a topic STRPTR functionality wish

    STRPTR functionality wish

    Is it possible to make STRPTR work on string equates? Something like:
    Code:
    $a = "Aldo Cavini"
    b  = STRPTR( $a )
    This could be useful, for instance, on registering a Window Class. The only way I know to assign the lpszClassName value is via a string or asciiz variable. Am I wrong?

    Aldo

    ------------------
Working...
X