Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: SizeOfWString

  1. #1

    Default SizeOfWString

    Hi,

    Reading the doc, so figured to install as I was curious about something in there.
    Some interesting design decisions that have been made. Certainly within the spirit of the DataFlex language.

    It mentions SizeOfWString

    So I'm thinking .. hey earlier it was mentioned that length would work with all our strings.. so what is the difference?

    Here's my first program in DF20

    Code:
    Use Windows.pkg
    
    WString wsTest
    
    Move (Repeat(Character(0),540)) to wsTest
    
    Showln (SizeOfWString(wsTest))
    
    Showln (Length(wsTest))
    
    winput "test" windowindex
    That didn't compile because
    Code:
    ----Compiling testWString.src----
    - Compiling Program: C:\DataFlex Projects\testing20\AppSrc\testWString.src
    - Memory Available: 1195442176
    - Using pre-compiled package WINDOWS.PKG
    - Including file: windows.x64.pkd    (C:\Program Files\DataFlex 20.0\Pkg\windows.x64.pkd)
    - Warning 4533: C:\DataFlex Projects\testing20\AppSrc\testWString.src (ln 11) Obsolete command: Winput. Use Message_Box
    -- Warning 4533: Obsolete command: GetAddress. Use AddressOf Function
    -- Error 4539: Conversion from 64-bit pointer to integer is not allowed, use Longptr instead of Integer.
    -- Error 4539: Illegal datatype conversion (would lead to a runtime error if not corrected)
    - Summary
    - Memory Available: 1192370176
    - Total Warnings : 2
    - Total Errors   : 2
    - Total Symbols  : 9444
    - Total Resources: 0
    - Total Commands : 7973
    - Total Windows  : 0
    - Total Pages    : 0
    - Static Data    : 93735
    - Message area   : 44399
    - Total Blocks   : 5219
    - 2 ERRORS HAVE BEEN FOUND.
    ----Compile Finished (with Errors and Warnings) ----
    ----Compiler Warning Summary----
    - Warning 4533: C:\DataFlex Projects\testing20\AppSrc\testWString.src (ln 11) Obsolete command: Winput. Use Message_Box
    -- Warning 4533: Obsolete command: GetAddress. Use AddressOf Function
    ----Compiler Error Summary----
    - Error 4539: Conversion from 64-bit pointer to integer is not allowed, use Longptr instead of Integer.
    -- Error 4539: Illegal datatype conversion (would lead to a runtime error if not corrected)
    Hmm.. this works:

    Code:
    Use Windows.pkg
    
    WString wsTest
    
    Move (Repeat(Character(0),540)) to wsTest
    
    Showln (SizeOfWString(wsTest))
    
    Showln (Length(wsTest))
    
    winput windowindex
    The output is.....
    Code:
    80
    80
    Uhhh...

    Moving all that global code over to a method gives:
    Code:
    Use Windows.pkg
    
    
    Procedure test
        WString wsTest
        
        Move (Repeat(Character(0),540)) to wsTest
        
        Showln (SizeOfWString(wsTest))
        
        Showln (Length(wsTest))
    End_Procedure
    
    Send Test
    winput windowindex
    output is:
    Code:
    540
    540
    That's all very interesting...
    1. globals are still causing trouble
    2. Winput doesn't like the string prompts
    3. Still not sure what the difference is between SizeOfWString and length except that the former is more explicit and will not trigger any implicit conversions to UTF-8

    Now I guess that 3. is what answers my question after thinking about it, but it was an interesting test with surprising results, so figured to post it here.
    --
    Wil

  2. #2
    Join Date
    Feb 2009
    Location
    Stuart, FL
    Posts
    5,322

    Default Re: SizeOfWString

    length is number of characters. size is number of bytes
    Michael Salzlechner
    StarZen Technologies, Inc
    http.://www.starzen.com

    IT Director at Balloons Everywhere

    Development Blog
    http://www.salzlechner.com/dev

    DataFlex Package Manager (aka Nuget for DataFlex)
    http://windowsdeveloper.com/dfPackage

  3. #3
    Join Date
    Feb 2009
    Posts
    5,468

    Default Re: SizeOfWString

    One counts characters and the other counts bytes which with unicode are no longer the same thing once you get past the first ASCII 127 characters
    Success consists of going from failure to failure without loss of enthusiasm - Winston Churchill

  4. #4
    Join Date
    Feb 2009
    Location
    Stuart, FL
    Posts
    5,322

    Default Re: SizeOfWString

    in case of sizeofwstring count of wchars
    Michael Salzlechner
    StarZen Technologies, Inc
    http.://www.starzen.com

    IT Director at Balloons Everywhere

    Development Blog
    http://www.salzlechner.com/dev

    DataFlex Package Manager (aka Nuget for DataFlex)
    http://windowsdeveloper.com/dfPackage

  5. #5

    Default Re: SizeOfWString

    Quote Originally Posted by starzen View Post
    in case of sizeofwstring count of wchars
    Yeah.. not bytes and that's why the output on both is the same.
    It's not strange to expect an output in bytes on a "SizeOf..." function though.
    But length does an implicit conversion to UTF-8 to get to that same result.

    --
    Wil

  6. #6

    Default Re: SizeOfWString

    The doc says about SizeOfWString:

    This returns the number of WChars (codeunits / double-bytes) of a WString.
    Yet WChar is not a supported type.
    So I guess that there's also not a WChar array we can make unless we do something like a UChar[][] ?
    --
    Wil

  7. #7
    Join Date
    Feb 2009
    Location
    Stuart, FL
    Posts
    5,322

    Default Re: SizeOfWString

    seems kind of odd. would think it would be better to have the ability to get the number of bytes but of course you can easily calculate that
    Michael Salzlechner
    StarZen Technologies, Inc
    http.://www.starzen.com

    IT Director at Balloons Everywhere

    Development Blog
    http://www.salzlechner.com/dev

    DataFlex Package Manager (aka Nuget for DataFlex)
    http://windowsdeveloper.com/dfPackage

  8. #8

    Default Re: SizeOfWString

    Quote Originally Posted by starzen View Post
    seems kind of odd. would think it would be better to have the ability to get the number of bytes but of course you can easily calculate that
    Sure.

    Now where is my like button?
    Ah

    --
    Wil

  9. #9
    Join Date
    Feb 2009
    Location
    The Netherlands
    Posts
    4,674

    Default Re: SizeOfWString

    There is no WChar type and I would not recommend making it a two dimensional UChar array. I'd recommend using a UChar array and doubling the result of SizeOfWString. Alternatively you could use a UShort array.

    The reason why SizeOfWString exists and returns the number of WChar entities is because that is what you need in a most cases when calling windows API's.

  10. #10

    Default Re: SizeOfWString

    Quote Originally Posted by Harm Wibier View Post
    There is no WChar type and I would not recommend making it a two dimensional UChar array. I'd recommend using a UChar array and doubling the result of SizeOfWString. Alternatively you could use a UShort array.

    The reason why SizeOfWString exists and returns the number of WChar entities is because that is what you need in a most cases when calling windows API's.
    Thanks Harm,

    Yeah I was shuddering when writing UChar[][] and already thought "not going to use that, but a UChar[] array double the size".

    I think a WChar type would make sense though.
    If only to be consistent and make code easier to read and see the output in the debugger.
    A "UChar array double the size" is kind of hackish.

    Then again, perhaps DataFlex is fine without.
    --
    Wil

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •