Upload
waldemar-solis
View
16
Download
2
Embed Size (px)
Citation preview
Oracle Forms
Additional techniques
• Using a form called 'Art Pictures' to show the use of images.
• Also, how to set the colour of a form dynamically depending on the mode it is in.
Download the artpictures.fmb form from the module website and you can look at it
carefully so see how it works. These lecture notes are an overview of that. You can apply the
techniques to your own forms if you want.
Create a table to hold the images...
Créate the following table:
create table pics(pic1 long raw, pic_label varchar2(3 0)); Table
created.
'Long Raw' is the data type used to hold the image. When you look at it in SQL it will just show some spurious
characters.
The same folder viewed as a list...
Steps to import a file.
1 Enter file name e.g. 'Clock'
2. Enter file path e.g. 'X\Gary Budgen\images\ (there is a list in the form)
3. Enter file type (there is a list of valid types in the form)
Step 4. Press the 'Get' button...
Pressing the save button will save the picture to the database. The
name specified in the 'Name of Picture' will be what is saved in the database
table along with the picture.
-
PROCEDURE get_imageIS
/* Define the local variables*/ This is the procedure that gets thel_filename VARCHAR2(60); l_type VARCHAR2(10);
l_item_nameVARCHAR2(60);
variables the values specified inLpathVARCHAR2(60); the form and then calls a built-in
BEGIN
/* Assign the values of the fields to the variables*/ procedure calledl_filename:= :PICS.file_image; 'read_image_file' l_type:= :PICS.type; read_image_file
l_path := :PICS.file_path; which retrieves the files.
/* Assign the variable of the item where the picture will be put in the form*/ l_item_name :=
'PICS.pic1';
/* Define the filename as the path, actual name of the file and the type of file, but concatenating
the various elements from the variables*/
l_filename := l_path||l_filename||'.'||l_type;
/*Use the build in procedure READ_IMAGE_FILE to retrieve the image from
the file*/
READ_IMAGE_FILE(l_filename,l_type,l_item_name); EXCEPTION
WHEN VALUE_ERROR THENmessage('Value Error');
WHEN OTHERS THEN message('Other error');
END;
image. Basically it assigns some
rl t ti i ■ j MrJ H^t^ti- ► a-
Fill in the Destination File, i.e. create a name here for a file where the picture will be saved.
Saving a picture already in your database to a file.
1. Fill in the File Path
2. Fill in the File Type
9S3SB3B3930BD3
Check it is in the file system, you can check the time and date...
"SI
PROCEDURE write_image S /* Define the variables*/ l_filename VARCHAR2(50); l_path VARCHAR2(30);l_compression VARCHAR2(30);l_type VARCHAR2(5);l_image_depth VARCHAR2(30);BEGIN
/* Assign the values in the form to the variables*/ l_filename := :PICS.destination_file; l_path := :PICS.file_path l_type := :PICS.type;l_filename := l_path||l_filename||'.'||l_type;l_compression := :PICS.compression; l_image_depth := :PICS.image_depth;/* Check the image depth, if none specified then just use the default*/ IF l_image_depth = 'MONOCHROME THENWRITEJMAGE_FILE(l_filename,:PICS.type/PICS.PIC1\NO_COMPRESSION,MONOCHROME);ELSIF l_compression = 'MAXIMIZE_COMPRESSION' THEN WRITEJMAGE_FILE(Lfilename,:PICS.type/PICS.PIC1',MAXIMIZE_COMPRESSION,MONOCHROME);ELSE/* Use the default*/ END IF;
WRITE_IMAGE_FILE(l_filename,:PICS.type,'PICS.PIC1');
EXCEPTION
END;
WHEN NO_DATA_FOUND THENmessage('no data found');WHEN VALUE_ERROR THENmessage('Value error');WHEN OTHERS THENmessage('other error');
The 'If statement just
check for different
image depths. Don't
worry about it.
This works by assigning values from the form to
variables and then using the 'write_image_file' built in to
write to a file
We can use the 'Zoom' buttons to zoom in or out of a picture.
Trigger to Zoom Out
IMAGE_ZOOM('PICS.pic1',zoom_out_factor,2);
Form in 'Normal' mode e.g. for data entry or open queries.
Form in 'Query mode'
How to set the colour of the form depending on the mode.
• Create a timer in the when-new-form-instance Trigger. This just counts down and when it expires fires an event which can then fire the...
• when-time-expired trigger, which we use to call a program unit to check the mode
• the program unit checks the mode and sets the colour accordingly
when-new-form-instance DECLARE
Trigger timer_id TIMER;BEGIN
timer_id :='create_timer('COLOUR_SET',100,REPEAT);
END;
when-timer-expired Trigger
show_mode;
The when-timer-expired Trigger calls this program unit which checks the mode and sets the
colour. The visual attributes have already been setup in the form.
PROCEDURE show_mode IS
BEGINIF :SYSTEM.mode = 'NORMAL' THEN
set_canvas_property('CANVAS2',VISUAL_ATTRIBUTE,'BLUE'); ELSIF :SYSTEM.mode = 'ENTER-QUERY' THEN
set_canvas_property('CANVAS2',VISUAL_ATTRIBUTE,'GREEN');
ELSE
null;
END I
4 Fruí___HvTiinhuiiui
, ' »-r**«ii*.j.'.i.i
F; END;