Subject |
Re: Closing an image on a form |
From |
Mervyn Bick <invalid@invalid.invalid> |
Date |
Sat, 10 Apr 2021 12:18:19 +0200 |
Newsgroups |
dbase.getting-started |
Attachment(s) |
three_images.wfm |
On 2021/04/10 09:29, roy price wrote:
> Hello Again Mervyn / Akshat,
> After setting up a test area, with three records on the main table, each with a field "Photoyesfile" "01", "02", "03", and three image files (with one image each), and trying (very trying) the code below in various combinations, I get nowhere with selecting the second and third files images.
> The If's or Cases statements work to get to the correct line, but the statements, "this.dataSource =", or "form.testimagedatamodule1.dataSource =" do not cause the first image to be replaced with the second, or third.
Have a look at the attached example. If you open it in the form
designer you will see the same image in each image control. This is
because I've used the same table three times and each image query opens
with the first record selected. If I had use three different image
tables (I didn't because there aren't three suitable tables in the
samples database) each image would display a different image.
I've used the form's form_onOpen event handler to blank out two of the
image controls when the form opens.
The main table's onNavigate event handler only uses this.parent.parent.
in place of form. as I'm not using a datamodule for the example. With
the tables in a datamodule you will need to use
this.parent.parent.parent. instead.
I've placed some comments in the fist section of the onNavigate event
handler. They apply equally to the rest of the code in the event handler.
It is not usual to have three image controls even though one has three
image files. If you opt for one image control you won't need the
form_onOpen event handler. Simply assign the image file which holds the
image for the first record in your main file to the image control in the
image control constructor code.
The onNavigate event handler only need to select the correct record in
the correct image table and assign that table to the single image
control's datasource property. There are no other image controls to null.
function rowset_onNavigate()
if this.fields['photoyesfile'].value = '01'
this.parent.parent.fish1.rowset.applyLocate( "id = " +
this.fields['id'].value )
this.parent.parent.image1.datasource =
this.parent.parent.fish1.rowset.fields["fish image"]
elseif this.fields['photoyesfile'].value = '02'
this.parent.parent.fish2.rowset.applyLocate( "id = " +
this.fields['id'].value )
this.parent.parent.image1.datasource =
this.parent.parent.fish2.rowset.fields["fish image"]
elseif this.fields['photoyesfile'].value = '03'
this.parent.parent.fish3.rowset.applyLocate( "id = " +
this.fields['id'].value )
this.parent.parent.image1.datasource =
this.parent.parent.fish3.rowset.fields["fish image"]
endif
return
Mervyn.
| if not file('fish_demo.dbf')
copy table :dbasesamples:fish to fish_demo
alter table fish_demo add photoyesfile char(2)
use fish_demo
scan
replace photoyesfile with '0'+ltrim(str(mod(id,3)+1))
endscan
use
endif
** END HEADER -- do not remove this line
//
// Generated on 2021-04-10
//
parameter bModal
local f
f = new three_imagesForm()
if (bModal)
f.mdi = false // ensure not MDI
f.readModal()
else
f.open()
endif
class three_imagesForm of FORM
with (this)
onOpen = class::FORM_ONOPEN
height = 21.0909
left = -1.2857
top = 0.7273
width = 106.8571
text = ""
endwith
this.DBASESAMPLES1 = new DATABASE(this)
with (this.DBASESAMPLES1)
left = 13.0
width = 11.0
height = 1.0
databaseName = "DBASESAMPLES"
active = true
endwith
this.FISH1 = new QUERY(this)
with (this.FISH1)
left = 4.0
width = 3.0
height = 1.0
database = form.dbasesamples1
sql = "select * from FISH.DBF"
active = true
endwith
this.FISH2 = new QUERY(this)
with (this.FISH2)
left = 30.0
width = 3.0
height = 1.0
database = form.dbasesamples1
sql = "select * from FISH.DBF"
active = true
endwith
this.FISH_DEMO1 = new QUERY(this)
with (this.FISH_DEMO1)
left = 45.0
width = 8.0
height = 1.0
sql = 'select * from "fish_demo.DBF"'
active = true
endwith
with (this.FISH_DEMO1.rowset)
onNavigate = class::ROWSET_ONNAVIGATE
endwith
this.FISH3 = new QUERY(this)
with (this.FISH3)
left = 39.0
width = 3.0
height = 1.0
database = form.dbasesamples1
sql = "select * from FISH.DBF"
active = true
endwith
this.GRID1 = new GRID(this)
with (this.GRID1)
dataLink = form.fish_demo1.rowset
height = 12.4545
left = 2.0
top = 3.1364
width = 69.8571
endwith
this.IMAGE1 = new IMAGE(this)
with (this.IMAGE1)
height = 4.8182
left = 80.2857
top = 2.6364
width = 21.4286
dataSource = form.fish1.rowset.fields["fish image"]
endwith
this.IMAGE2 = new IMAGE(this)
with (this.IMAGE2)
height = 4.8182
left = 80.2857
top = 8.3636
width = 21.4286
dataSource = form.fish2.rowset.fields["fish image"]
endwith
this.IMAGE3 = new IMAGE(this)
with (this.IMAGE3)
height = 4.8182
left = 80.2857
top = 14.7273
width = 21.4286
dataSource = form.fish3.rowset.fields["fish image"]
endwith
this.rowset = this.fish1.rowset
function form_onOpen()
//Only one image table has the correct image so we need
//to null the datasource property for two of the image controls
mphoto = form.fish_demo1.rowset.fields["photoyesfile"].value
If mPhoto='01'
form.IMAGE2.dataSource = []
form.IMAGE3.datasource = []
elseif mPhoto='02'
form.IMAGE1.dataSource = []
form.IMAGE3.datasource = []
elseif mPhoto='03'
form.IMAGE1.dataSource = []
form.IMAGE2.datasource = []
endif
return
function rowset_onNavigate()
if this.fields['photoyesfile'].value = '01'
//Go to the correct record in the image file.
//You will need to use the correct field names.
// If the fields are character then
// this.parent.parent.fish1.rowset.applyLocate( "id = '" + this.fields['id'].value +"'" )
this.parent.parent.fish1.rowset.applyLocate( "id = " + this.fields['id'].value )
//Set the datasource property of the image control to use
this.parent.parent.image1.datasource = this.parent.parent.fish1.rowset.fields["fish image"]
//Null the datasource property for each of the other image controls
this.parent.parent.image2.datasource = [] //note: no space between the square brackets
this.parent.parent.image3.datasource = []
elseif this.fields['photoyesfile'].value = '02'
this.parent.parent.fish2.rowset.applyLocate( "id = " + this.fields['id'].value )
this.parent.parent.image2.datasource = this.parent.parent.fish2.rowset.fields["fish image"]
this.parent.parent.image1.datasource = []
this.parent.parent.image3.datasource = []
elseif this.fields['photoyesfile'].value = '03'
this.parent.parent.fish3.rowset.applyLocate( "id = " + this.fields['id'].value )
this.parent.parent.image3.datasource = this.parent.parent.fish3.rowset.fields["fish image"]
this.parent.parent.image1.datasource = []
this.parent.parent.image2.datasource = []
endif
return
endclass
|
|