PROGRAM Add_PLSQL; {-- *************************************************************************** -- ** Descr. : This script shows how to add some pl/sql lines -- ** to a trigger (like when-new-form-instance). -- ** -- ** MINVERS: requires FormsAPI Master 1.0 Build 228 and up -- *************************************************************************** -- ** 28/12/01 1.001.00 Initial Creation, muellers@orcl-toolbox.com -- ***************************************************************************} {*Variable Declaration*} VAR v_filename : varchar2; i : number; frm : number; trg : number; files : TStringList; ps : TParamScreen; pb : TParamBoard; l_crenotexist: boolean; l_triggername: varchar2; l_plsql : varchar2; {*Main Program Block*} BEGIN //build together a nice parameter screen ... ps := TParamScreen.create; pb := ps.AddBoard('Modules',picModules); pb.addparam(parLabel,'MYLABEL','This script demonstrates how to add some PL/SQL to a trigger.','',''); pb.addparam(parFiles,'SRC','Source Files','','Forms Modules (*.fmb)|*.fmb'); pb.addparam(parPathname,'TRGPATH','Target Path','',''); pb := ps.AddBoard('PLSQL',picProperties); pb.addparam(parComboListBox,'TRIGGER','Trigger','WHEN-NEW-FORM-INSTANCE','WHEN-NEW-FORM-INSTANCE'+c_cr+ 'KEY-COMMIT'+c_cr+ 'PRE-FORM'+c_cr+ 'WHEN-NEW-ITEM-INSTANCE'); pb.addparam(parCheckbox,'CREATEYN','Create trigger if it does not exist','Y',''); pb.addparam(parComboListBox,'POS','Position','Start','Start'+c_cr+'End'); pb.addparam(parPLSQL,'PLSQL','PL/SQL','-- New line added on 01/01/2002'+c_cr+'NULL;',''); //show the parameter screen and wait for inputs if ps.ShowParamScreen('Add PLSQL to a trigger ...') then begin // basic parametercheck ... if ps.Paramvalue('TRGPATH') ='' then raiseException('Missing Target Path!'); //get our variables from the parameterscreen l_triggername := ps.Paramvalue('TRIGGER'); l_crenotexist := ps.Paramvalue('CREATEYN')='Y'; //get the list of fmb-modules to process files := tstringlist.create; files.text := ps.ParamValue('SRC'); //loop through all selected files for i := 0 to files.count-1 do begin v_filename := files.strings[i]; logadd('Changing ('+to_char(i+1)+'/'+to_char(files.count)+') '+v_filename); try //load the module frm := API_LoadModule(v_filename); //try to find the trigger trg := generic_findobj(frm,l_triggername,D2FFO_TRIGGER); //if no trigger found (=0) than create if so selected on the parameterscreen if (trg = 0) and (l_crenotexist=true) then begin trg := generic_create(frm,l_triggername,D2FFO_TRIGGER); logadd(' => new trigger created'); end; //only change the code if we have a valid trigger object if trg <> 0 then begin //read existing trigger sourcecode l_plsql := Generic_GetTextProp(trg,D2FP_TRG_TXT); //add the new lines at the end or beginning if ps.paramvalue('POS') = 'End' then l_plsql := l_plsql+ps.ParamValue('PLSQL') else l_plsql := ps.ParamValue('PLSQL')+C_CR+l_plsql; //write back new trigger sourcecode Generic_SetTextProp(trg,D2FP_TRG_TXT,l_plsql); //now modify the filename to point to the new location v_filename := ps.ParamValue('TRGPATH') +'\'+ extractFilename(v_filename); try API_SaveModule(frm,v_filename); except logadd('error saving file! - '+GetError,logerror); end; end else begin //output warning that we havn't done anything logadd(' => no trigger to change found',logwarning); end; //... and finally release the module from memory API_DestroyModule(frm); except // ups! an error happened, so just log it and proceed to the next module logadd(' =>'+GetError,LogError); end; end; end else begin //user must have pressed cancel on parameterscreen logadd('Canceled on parameterscreen!'); end; // free the parameter screen ps.free; END.