Get Image Button...
Creating a button to set a image field is as easy as using the script genie.

However, you may want to point to a specific folder, a default image and or you may want to import the file name.
.



By converting your action scripting to xbasic ( right click, select convert to xbasic) you can have the get image command default to folders you specify, this is quite handy when you have folders where images particular to specific tables are stored.

 

Our image field is named (Image) and the field that displays the image's name is (iname), modify the code below to reflect your Image field names and the folder and image you would like to default to. Paste this into a inline xbasic action on your buttons on push event .

'Set file name for Image field + set a default folder & image.

ImageFilename = ui_get_image_filename(a5.get_path()+"\Photos\Products\small\default.jpg")
If ImageFilename = ""
then
'user selected cancel, so end script
end
end if

Dim TempObj as p
dim readonly_flag as l

'Get a pointer to the Object on the Form/Browse that has the image file ref field.
TempObj = obj(topparent.name(16)+":"+"Image")

'Check if the image field is readonly
readonly_flag = TempObj.field.readonly
if readonly_flag = .t.
then
ui_msg_box("Error","Cannot change image in Image field '"+"Image"+"' because it is read-only",UI_STOP_SYMBOL)
end
else
dim Tbl as p
'Get a pointer to the table for the image field
Tbl = tempobj.Field_Get().table_get()
dim Fld as p
'Get a pointer to the image field
Fld = tempobj.field_get()

'If the table is in View mode, put it in change mode
If tbl.mode_get() = 0 then
tbl.change_begin()
fld.value_put(image_filename_encode(ImageFileName))
tbl.change_end(.t.)
else
fld.value_put(image_filename_encode(ImageFileName))
end if


'now refresh the object
tempObj.refresh() end if

'Get the full path and set images name in the field iname

DIM vfile as C
vfile=a5_eval_expression(parentform.image)

'Now just get the file name with extension
DIM vfile2 as C
vfile2=file.filename_parse(vfile,"ne")

parentform:iname.value=vfile2

end if

 

     

 

Suggest a topic:

E-mail :
Topic :

 
Product Search :  
Resources:
Dzine Articles :

 

Article Search :