Subject Re: Closing an image on a form
From Mervyn Bick <invalid@invalid.invalid>
Date Sun, 11 Apr 2021 12:36:56 +0200
Newsgroups dbase.getting-started

On 2021/04/11 10:06, roy price wrote:

> Hello Mervyn,
> Well at last I have a (mostly) working example of using three image controls on my tables. As I've added an ID field to my tables so as not to disturb the OnNavigate example ((I've never come across ApplyLocate before, at least long ago when I could remember the commands)

ApplyLocate() is a method of a rowset object.  It is the equivalent of
the LOCATE command in "old" dBASE.  It searches from the top of the the
image file each time until it finds the required record. It is very
simple to include it in one's code but it can introduce a delay in
selecting the correct record from a very long table.  There are
alternatives but let's worry about this later if it does prove to be  a
problem.

> I have a couple of problem areas to work through....
> the opening photo is not correct if the main table and the photo01 file do not start with the same record.... I guess thats an indexing solution.
> and the ID  autoincrement fields on each file will soon be out of sequence as more photos are added (currently changing the photo file to character produces an error, even if the line is changed as suggested).

In the example I posted I used four copies of the same table.  The
autoinc ID field in the main table was therefore the same as the ID file
in each of the three image tables.  The example did, however, show the
concept of finding the correct record in the correct image file.

To keep your main file and three image files in step you need two
dedicated fields in the main table.  You already have the photoyesfile
field in the main table to indicate which of the three tables to use.
You also need a field to indicate which record to select in the image
file.  Call it, say, photo_no and make it type LONG.  If you have an
autoinc ID field in each image file you store that number in the
photo_no field.  It doesn't matter that the same number occurs in each
image file.  The value in the photoyesfile makes sure you are looking at
the correct table.

The code to locate the correct record would then be the following
assuming ID is the autoinc field in the image file and photo_no is the
field in the main table.

    ....rowset.applyLocate( "id = " + this.fields['photo_no'].value  )

You've put quite a lot of work into this but it's not the usual approach
(nor is it the recommended approach) to displaying images on a form.

If you already have all your photos on the hard drive keeping a second
copy in one of your image tables is simply a waste of disk space.  The
preferred way of dealing with this situation is to have a field in your
main table which contains the path and file name of the relevant photo.
  Let's call the field photo_path.  It needs to be a character field and
it must be wide enough to accept the longest path.  50 characters will
probably be overkill but rather too wide than not big enough.

If you have stored your photos in the Windows pictures file then save
something like c:\userName\pictures\2020_01\img_1234.jpg  to photo_path.
I have a second harddrive which is used only for data so I would save
something like d:\pictures\2020_01\img_1234.jpg to photo_path.

Don't assign a value to the image control's datasource property in its
constructor code.  To ensure that the form opens with an image displayed
use the form's form_onOpen event handler.

    function form_onOpen()
        form.image1.datasource = 'filename ' +
form.datamodulename.queryname.rowset.fields['photo_path'].value
       return


To update the image control as the user navigates the table use the
onNavigate event handler.


   function rowset_onNavigate(type, nRows)
       this.parent.parent.parent.image1.datasource = 'filename ' +
this.parent.parent.parent.datamodulename.queryname.rowset.fields['photo_path'].value

       return


As you can see, this code is significantly simpler than having to deal
with images stored in a table.

Mervyn.