PROGRAM ModuleMerger; {-- *************************************************************************** -- ** Descr. : Merges the objects of a template formsmodule into an existing -- ** formsmodule. This is great if you have a template with a bunch -- ** of propertyclasses/visual attributes that you want to copy/reference -- ** to all your formsmodule. -- ** This script will just copy all objects, to reference them from -- ** your original base-template just reference the objects you want to -- ** have into a dummytemplate form from where they then can be copied -- ** into all other forms (keeping their original reference to the -- ** base template) ! -- ** -- ** MINVERS: requires FormsAPI Master 1.0 Build 232 and up because of a bug -- ** in the generic_replicate function (created obj with wrong names) -- *************************************************************************** -- ** 09/01/02 1.001.00 Initial Creation, muellers@orcl-toolbox.com -- ***************************************************************************} {*Global Variable Declaration*} VAR v_filename : varchar2; i,j : number; tmp : number; frm : number; files : TStringList; items : TStringList; item : number; item_type : number; item_name : string; ps : TParamScreen; pb : TParamBoard; {*Main Program Block*} BEGIN //build together a nice parameter screen ... ps := TParamScreen.create; pb := ps.AddBoard('Modules',picModules); pb.addparam(parLabel,'MYLABEL','Merges the content of a template form into others ...','',''); pb.addparam(parFiles,'FILES','Source Files','','Forms Modules (*.fmb)|*.fmb|All Files (*.*)|*.*'); pb.addparam(parPathname,'TRGPATH','Target Path','',''); pb.addparam(parFilename,'TEMPLATEFORM','Template Form','','Forms Modules (*.fmb)|*.fmb|All Files (*.*)|*.*'); //show the parameter screen and wait for inputs if ps.ShowParamScreen('Merge Formsmodules ...') then begin //get the selected files into a list files := tstringlist.create; files.text := ps.paramvalue('FILES'); //check that target path really exist if ps.paramvalue('TRGPATH') = '' then RaiseException('Target path must be specified!'); //load the templateform tmp := api_loadmodule( ps.paramvalue('TEMPLATEFORM') ); //get all objects of the template forms into a list items := api_getallobjects(tmp); //loop through all the files for j := 0 to files.count-1 do begin v_filename := files.strings[j]; logadd('Checking '+to_char(j+1)+'/'+to_char(files.count)+' '+v_filename); try // load the forms module frm := API_LoadModule(files.strings[j]); //loop through the list of template items for i := 0 to items.count-1 do begin item := items.objects[i]; //only check items that are owned by the the formsmodule itself, //for example, we don't care about items as they will be copied // when copying the block if generic_getvalue(item, D2FP_OWNER) = tmp then begin //get the object type (vat, block, report, propertyclass, trigger, etc) item_type := generic_QueryType(item); //get the objects name item_name := API_GetObjectName(item); logadd(item_name); //check if object with same name already exists in our target module if generic_FindObj(frm, item_name , item_type) = 0 then begin //doesn't exist, so copy it from the template! generic_replicate(frm, item, item_name); end; end; end; //now modify the filename to point to the new location v_filename := ps.ParamValue('TRGPATH') + '\' + ExtractFileName(v_filename); //and save it to the new location API_SaveModule(frm,v_filename); //... 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; //free the file list from memory; files.free; //free the list of template objects from memory items.free; //free the template form from memory API_DestroyModule(tmp); end else begin //user must have pressed cancel on parameterscreen logadd('Canceled on parameterscreen!'); end; // free the parameter screen ps.free; END.