Subject Re: Display Images on the form from a local imagefolder
From AGOSTINHO <AGOSTINHOTEIXEIRA@YAHOO.COM>
Date Mon, 02 Oct 2023 00:08:53 -0400
Newsgroups dbase.getting-started

Dear  Mervyn Bick it works perfect, thank you very much for your assistance.
Agostinho

Mervyn Bick Wrote


> On 2023/10/01 07:51, AGOSTINHO wrote:
> > I've been working around with the method of displaying images on a separate
> >   image-folder and it works much better than placing the images direct on the DBF files.
> > Thanks for that.
> >
> > Now I'm trying to change/replace the images on each record but can't get it to work.
> > I've tried with the following routine but it don't works.
> > Thanks
> >
> >   function PUSHBUTTON7_onClick()
> >       local cFile
> >         cFile = getfile( "*.*", "Import mugshot image" )
> >       if "" # cFile
> >         form.imagepotret1.dataSource = 'FILENAME  "'+trim(this.fields['jpg_path'].value)+'\'+this.fields['jpg_name'].value+'"'
> >       endif
> >     return
>
> It doesn't work (and should be giving an error) because "this" in the
> code refers to the pushbutton and the pushbutton doesn't have any
> fields.  A very common error in OODML programming.
>
> You can change the folder that the dialogue looks at initially as well
> as the type of file by changing the file skeleton passed to getfile()
>
>     cFile = getfile("d:\folder1\folder2\*.jpg","Import mugshot image")
>
> The user can still change the folder and the type of file displayed if
> necessary.
>
> I assume (my favourite exercise - jumping to conclusions :-) ) that,
> before the user left-clicks on the pushbutton, the rowset's onNavigate
> event handler has ensured that the image object is displaying the image
> saved in the table or is blank because no value has been saved yet.  In
> other words, the table's rowpointer is already on the record where the
> image details are to be saved when the pushbutton is clicked.
>
> The code below will save the selected image details to the table for
> future display and will replace the existing (if any) image in the image
> object immediately.
>
> If the user selects an image from the dialogue, cFile will contain
> something like  C:\folder1\folder2\whatever.jpg   As you are saving the
> path and the filename in separate fields in the table you will need to
> split the string at the last backslash.  RAT() to the rescue. :-)
>
>
>   function PUSHBUTTON7_onClick()
>      local cFile,cPath,cImage
>      cFile = getfile( "*.jpg", "Import mugshot image" )
>        //Change the skeleton to include the path if necessary.
>      if "" # cFile
>         //Save image details to table for future display.
>         //This will replace an exiting image's details without warning.
>       cPath = substr(cfile,1,rat('\',cFile)-1) //Remove last \
>       cImage = substr(cFile,rat('\',cFile)+1)  //Remove last \
>       form.rowset.fields['jpg_path'].value = cPath
>       form.rowset.fields['jpg_name'].value = cImage
>       form.rowset.save() //Not really necessary but an explicit save is
>                          //preferable to relying on an implicit save.
>         //Display selected image
>       form.imagepotret1.dataSource = 'FILENAME '+ cPath+'\'+cImage
>     endif
>     return
>
> Note that if the rowset you want to write the details to is not the
> rowset that has been assigned to the form's rowset property you will
> need to include the query name in the commands.
>
> Mervyn.
>
>