Topic: SF

Hi Jeff,

There appears to be an issue with the way Appgraphics implements dlgrequesttext(). For example, if it is used to enter a text password of exactly the same length as it is dimensioned, then the password is truncated by two characters. This would be problem when trying to enter a correct password since the requested text would not equal the original password. The issue does not occur when the dimension of the entered password text is increased by two characters (dim(text(n + 2)). I've attached a simple example below which produces the following results.

    !--- Simply Fortran v3.39
    !--- OUTPUT: CHARACTER(30) :: txt
    My initial text is 123456789012345678901234567890
    My initial text length is           30
   
    Request was successful: T
    My requested text is                1234567890123456789012345678
    My requested ADJUSTL(text) is 1234567890123456789012345678
    My requested TRIM(text) is      1234567890123456789012345678
    My requested text length is              28
   
    Initial text does not equal requested text: Failure!

Regards,
Frank

SF Code:
PROGRAM REQUEST_TEXT
    USE APPGRAPHICS, ONLY: dlgrequesttext, dlgrequestpassword

    IMPLICIT NONE
    INTEGER, PARAMETER :: n = 30  !-- if set to 32, cTXT len_trim = 30
    CHARACTER(n) :: cTXT, cTEXT
    CHARACTER(n) :: cTITLE, cLBL
    LOGICAL       :: bYN

    cTITLE = "My Title:"
    cLBL = "Enter text:"

    cTXT = &
        "123456789012345678901234567890"

    cTEXT = TRIM(ADJUSTL( cTXT ))

    PRINT *, 'My initial text is ', TRIM( cTXT )
    PRINT *, 'My initial text length is ', LEN_TRIM( cTXT )
    PRINT *

    bYN = dlgrequesttext( cTXT, cTITLE, cLBL, .FALSE. )
    !bYN = dlgrequestpassword( cTXT, cTITLE, cLBL )

    IF (bYN) THEN
        PRINT *, 'Request was successful:', bYN
        PRINT *, 'My requested text is ', REPEAT(' ',9), cTXT
        PRINT *, 'My requested ADJUSTL(text) is ', ADJUSTL( cTXT )
        PRINT *, 'My requested TRIM(text) is ', REPEAT(' ',3), TRIM( cTXT )
        PRINT *, 'My requested text length is ', REPEAT(' ',3), LEN_TRIM( cTXT )
    ELSE
        PRINT *, 'Request was unsuccessful:', bYN
        PRINT *, 'My requested text is unchanged: ', ADJUSTL( cTXT )
        PRINT *, 'My text length is:', LEN_TRIM( cTXT )
    END IF

    PRINT *
    IF (ADJUSTL(cTXT) /= ADJUSTL(cTEXT)) THEN
        PRINT *, 'Initial text does not equal requested text: Failure!'
    ELSE
        PRINT *, 'Initial text equals requested text: Success!'
    END IF

    RETURN

    !--- OUTPUT:
    !    My initial text is 123456789012345678901234567890
    !    My initial text length is           30
    !
    !    Request was successful: T
    !    My requested text is          1234567890123456789012345678
    !    My requested ADJUSTL(text) is 1234567890123456789012345678
    !    My requested TRIM(text) is    1234567890123456789012345678
    !    My requested text length is              28
    !
    !    Initial text does not equal requested text: Failure!
    !
END PROGRAM REQUEST_TEXT

Re: SF

There are some bugs in AppGraphics here, but I can at least explain the reasoning.  The initial text string is immediately trimmed, and a c_null_char is appended to the trimmed string all within the original text string.  So in your example, your string was:

123456789012345678901234567890

but the box would show only 29 characters:

"12345678901234567890123456789

Now for some reason, the string is shortened again when retrieving the string.  This issue is caused by an off-by-one issue when determining the string's length, causing the retrieved string to only contain 28 characters:

"1234567890123456789012345678

The bug is two-fold:

1. The retrieval should remain, in theory, at 29 characters and
2. The documentation should point out that a c_null_char would be added to the string within the string's size.

However, fixing both still wouldn't truly fix the expected behavior where a Fortran user would expect the full 30 characters to be available and usable.  I'll try to get a fix in today that retrieves the full 30 characters.

Jeff Armstrong
Approximatrix, LLC

Re: SF

Frank,

Build 4415 should fix this problem entirely.

Jeff Armstrong
Approximatrix, LLC

Re: SF

Jeff,

After installing SF 3.40 build 4415 and doing a fresh clean of the old build, the above example Appgraphics dlgrequesttext() function worked perfectly.

Thank you again for your effort to detail.

Frank