Page 1 of 1

Defining labels, checkboxes and so on by macro substitution

Posted: Mon Sep 26, 2016 6:38 pm
by plantenkennis
Is it possible to define labels and checkboxes with macrosubstitution. Sometimes I want to define several labels images and chackboxes in a FOR NEXT loop.

Code: Select all

    LOCAL nFoto := 1
        FOR r = 1 TO 3
        FOR k = 1 TO 5
            cImage := aFotoNaam[nFoto]
            oImgName := 'oImg' + STR(nFoto)
            IF FILE(cImage)
                @ nRow, nColumn IMAGE &oImgName FILENAME cImage OF oFld:aControls[ 3 ] SIZE 110, 110
                &oImgName:bLButtonDown = { || RK_FotoGroot( cImageGroot ) }
            ENDIF
            nColumn := nColumn + 120
            nFoto++
        NEXT
        nColumn := 10
        nRow := nRow - 120
    NEXT

 
Is this possible?

Re: Defining labels, checkboxes and so on by macro substitution

Posted: Mon Sep 26, 2016 6:46 pm
by Antonio Linares
Rene,

It seems to compile fine

Do you get an error at runtime ?

Re: Defining labels, checkboxes and so on by macro substitution

Posted: Mon Sep 26, 2016 6:51 pm
by Enrico Maria Giordano
Yes. Just move the GET command to a function passing it the index as parameter. I had a sample but I couldn't find it... :-(

EMG

Re: Defining labels, checkboxes and so on by macro substitution

Posted: Mon Sep 26, 2016 8:09 pm
by plantenkennis
Yes, I did get an error on compiling. The name of the object was not correct.

oImgName := 'oImg' + STR(nFoto) -> oImgName := 'oImg' + ALLTRIM(STR(nFoto))

But in another function can I retrieve the name of the object, this doesn't work:

Code: Select all

    FOR r = 1 TO 3
        FOR k = 1 TO 5
            cImage := aFotoNaam[nFoto]
            oImgName := 'oImg' + ALLTRIM(STR(nFoto))
            IF FILE(cImage)
                @ nRow, nColumn IMAGE &oImgName FILENAME cImage OF oFld:aControls[ 3 ] SIZE 110, 110
                &oImgName:bLButtonDown = { || RK_FotoGroot( oImgName ) }
            ENDIF
            nColumn := nColumn + 120
            nFoto++
        NEXT
        nColumn := 10
        nRow := nRow - 120
    NEXT

FUNCTION RK_FotoGroot(cImage)
*to show a big picture

LOCAL oWndFoto
LOCAL oFoto
LOCAL nWidth := 0
MsgInfo(cImage) <--this gives always oImg15
 

Re: Defining labels, checkboxes and so on by macro substitution

Posted: Mon Sep 26, 2016 9:00 pm
by Antonio Linares
You have to use a detached local:

&oImgName:bLButtonDown = CreateBlock( oImgName )

...

function CreateBlock( cName )

return { || RK_FotoGroot( cName ) }

Re: Defining labels, checkboxes and so on by macro substitution

Posted: Tue Sep 27, 2016 8:16 am
by Enrico Maria Giordano
You didn't make as I said. You have to take the GET command and move it to a separate function.

EMG

Re: Defining labels, checkboxes and so on by macro substitution

Posted: Tue Sep 27, 2016 8:40 pm
by plantenkennis
Hello Antonio,
The detached local function works perfect. Now I only want to make the image bigger or smaller. The window resizing goes well, but not the image.

Code: Select all

FUNCTION RK_FotoGroot(cImage)
*to show a big picture

LOCAL oWndFoto
LOCAL oFoto
LOCAL nFoto := VAL(SUBSTR(cImage, 5))
LOCAL cFoto := aFotoNaam[nFoto]
LOCAL nWidth := 80
LOCAL nHeight := 80

    DEFINE DIALOG oWndFoto TITLE "big picture" ;
        FROM 0, 0 TO 10, 10
        
        @ 40, 10 IMAGE oFoto FILENAME cFoto OF oWndFoto SIZE 640, 480

        nWidth := oFoto:GetWidth()    && I suppose I can get the Width and Height of the image after defining it?
        nHeight := oFoto:GetHeight()
*       oFoto:Size(nHeight, nWidth)
        oWndFoto:ChangeSize( nHeight+40, nWidth+20)
                
        @ 10, 250 BUTTON "Zoom" OF oWndFoto ACTION { || oFoto:SetScaling(1) }

    ACTIVATE DIALOG oWndFoto

RETURN NIL
 
Also I want to use the SetScaling in a button, so I can zoom the image. Any solution?

Re: Defining labels, checkboxes and so on by macro substitution

Posted: Tue Sep 27, 2016 9:00 pm
by Antonio Linares
Rene,

Try it this way:

oFoto:SetSize( nWidth, nHeight )