xImage question

Post Reply
ellano
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am

xImage question

Post by ellano »

When I change from Image to Ximage (trying not to use freeimage.dll anymore) I get a "cannot create Dialog Box" error.

My code is fairly simple (the IMAGE version worked perfectly):

Code: Select all

   LOCAL aPath:={}, oDlg, oImages, oGet, CText[3]

   IF Fill_Images( aPath)  //Search all user images "JPG"
     cText[1]:=1
     cText[2]:=LEN(aPath)
     cText[3]:=""
     DEFINE DIALOG oDlg RESOURCE "diaporama" ;
      TITLE "Exa Pedigree: Photo album Bulls"
         REDEFINE XIMAGE oImages ID 101 OF oDlg
         REDEFINE GET oGet VAR cText[3] ID 102 OF oDlg UPDATE READONLY
         REDEFINE BUTTON ID 504 OF oDlg ACTION Next_Img( @oImages, @cText, @oDlg, @oGet, aPath )
         REDEFINE BUTTON ID 503 OF oDlg ACTION Prev_Img( @oImages, @cText, @oDlg, @oGet, aPath )
         REDEFINE BUTTON ID 501 OF oDlg ACTION oDlg:End()
      ACTIVATE DIALOG oDlg CENTER ON INIT (HB_SYMBOL_UNUSED(self), ;
                                           Img_Update( @oImages, @cText, @oDlg, @oGet, aPath))
   ELSE
     MsgStop("No available photos","No photos")
   ENDIF

...

STATIC FUNCTION Img_Update( oImages, cText, oDlg, oGet, aPath )
  oImages:SetSource( aPath[cText[1]] )
  oImages:Refresh()
  cText[3]:=cFileName( aPath[cText[1]] )
  oGet:REFRESH()
  oDlg:UPDATE()
RETURN NIL
Something simple that I am doing wrong here?

Thanks
Emiliano Llano Díaz
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: xImage question

Post by nageswaragunupudi »

Can you please post your rc file?
Regards

G. N. Rao.
Hyderabad, India
ellano
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am

Re: xImage question

Post by ellano »

Code: Select all

...

DIAPORAMA DIALOG 22, 26, 311, 205
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Pedigree BullFight Photos"
FONT 12, "MS Sans Serif"
{
    PUSHBUTTON  "Close", 501, 246,  84, 45, 15
    PUSHBUTTON  "->", 503, 269, 53, 16, 17
    PUSHBUTTON  "<-", 504, 247, 53, 16, 17
    EDITTEXT    102, 10, 172, 225, 13
    CONTROL     "", 101, "TImage", 0 | WS_CHILD | WS_VISIBLE, 10, 14, 225, 150
}
The same control (Timage) works correctly in other dialog when using xImage :?:
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: xImage question

Post by nageswaragunupudi »

The same control (Timage) works correctly in other dialog when using xImage :?:
Even then, please change TImage as TXImage in this rc file. Your sample should work with this change.
Regards

G. N. Rao.
Hyderabad, India
ellano
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am

Re: xImage question

Post by ellano »

The other image (else where in the program in a more elaborated and complex code) continues to work nicely with the change, but this one refuses to do the work.

Error occurred at: 27/09/2018, 07:52:01
Error description: Error BASE/1004 No exported method: EVAL
Args:
[ 1] = U

Stack Calls
===========
Called from: => (b)EVAL( 0 )
Called from: .\source\classes\XIMAGE.PRG => TXIMAGE:DEFAULT( 204 )
Called from: .\source\classes\XIMAGE.PRG => TXIMAGE:INITIATE( 189 )
Called from: => __OBJSENDMSG( 0 )
Called from: .\source\function\HARBOUR.PRG => OSEND( 291 )
Called from: .\source\function\HARBOUR.PRG => ASEND( 259 )
Called from: .\source\classes\DIALOG.PRG => TDIALOG:INITIATE( 781 )
Called from: .\source\classes\DIALOG.PRG => TDIALOG:HANDLEEVENT( 1036 )
Called from: => DIALOGBOX( 0 )
Called from: .\source\classes\DIALOG.PRG => TDIALOG:ACTIVATE( 287 )
User avatar
nageswaragunupudi
Posts: 8017
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Contact:

Re: xImage question

Post by nageswaragunupudi »

Complex? Actually it is very simple to program with XImage. I simplified your program to demonstrate the simplicity in dealing with ximage.

Code: Select all

#include "fivewin.ch"

function Main()

   local oDlg, oImage, oSay
   local cPath    := "c:\\fwh\\bitmaps\\pngs\\"
   local aImages  := DIRECTORY( cPath + "*.png" )
   local nImage   := 1

   AEval( aImages, { |a,i| aImages[ i ] := cPath + a[ 1 ] } )

   DEFINE DIALOG oDlg RESOURCE "diaporama" ;
      TITLE "Exa Pedigree: Photo album Bulls"

   REDEFINE XIMAGE oImage SOURCE aImages[ nImage ] ID 101 OF oDlg UPDATE
   REDEFINE SAY oSay PROMPT { || cFileName( aImages[ nImage ] ) } ID 102 OF oDlg UPDATE COLOR CLR_BLACK,CLR_WHITE
   REDEFINE BUTTON ID 504 OF oDlg WHEN nImage > 1 ACTION ( nImage--, oDlg:Update() )
   REDEFINE BUTTON ID 503 OF oDlg WHEN nImage < Len( aImages ) ACTION ( nImage++, oDlg:Update() )
   REDEFINE BUTTON ID 501 OF oDlg ACTION oDlg:End()

   oDlg:bPainted := { || oDlg:Box( oSay:nTop-1, oSay:nLeft-1, oSay:nTop + oSay:nHeight, ;
                         oSay:nLeft + oSay:nWidth, CLR_GRAY ) }

   ACTIVATE DIALOG oDlg CENTER

return nil
Simple nImage++ or nImage-- switches images without any additional code.

rc file (minor changes)

Code: Select all

DIAPORAMA DIALOG 22, 26, 311, 205
STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
CAPTION "Pedigree BullFight Photos"
FONT 12, "MS Sans Serif"
{
    PUSHBUTTON  "Close", 501, 246,  84, 45, 15
    PUSHBUTTON  "->", 503, 269, 53, 16, 17
    PUSHBUTTON  "<-", 504, 247, 53, 16, 17
    CTEXT  ""  102, 10, 172, 225, 13, SS_CENTERIMAGE
    CONTROL     "", 101, "TXImage", 0 | WS_CHILD | WS_VISIBLE, 10, 14, 225, 150
}
Image
Regards

G. N. Rao.
Hyderabad, India
ellano
Posts: 107
Joined: Tue Sep 15, 2009 7:52 am

Re: xImage question

Post by ellano »

Indeed, simpler (ahaha the answer was in the SOURCE key word).

Nevertheless, it refused to work until I did this slight change to your otherwise elegant code:

Code: Select all

       REDEFINE BUTTON ID 504 OF oDlg WHEN nImage > 1 ACTION ( nImage--, oImage:REFRESH() )
       REDEFINE BUTTON ID 503 OF oDlg WHEN nImage < Len( aDirectorio ) ACTION ( nImage++, oImage:REFRESH() )
 
Thanks for your time and interest in the question
Emiliano Llano Díaz
Post Reply