PROGRAM IconUsage; {-- *************************************************************************** -- ** Descr. : Extracts all iconfile usages (from buttons and sourcode in -- ** calls to set_item_property('???',icon_name,'???') ) from a forms -- ** application. Great to see which icons are really used and which -- ** you can get rid of! -- ** -- ** MINVERS: requires FormsAPI Master 1.0 Build 228 and up -- *************************************************************************** -- ** 31/12/01 1.001.00 Initial Creation, muellers@orcl-toolbox.com -- ***************************************************************************} // global variables VAR frm : number; files : TStringList; items : TStringList; filename : varchar2; ps : TParamScreen; pb : TParamBoard; i,j : number; out_filename : varchar2; iconlist : tstringlist; src : varchar2; findpos : number; iconname : varchar2; x : number; s : varchar2; BEGIN //build a nice parameterscreen ps := TParamScreen.create; pb := ps.AddBoard('Modules',picModules); pb.addparam(parLabel,'MYLABEL','This script will report all used Icons in your application','',''); pb.addparam(parFiles,'MYFILES','Forms Modules','','Forms Files (*.fmb)|*.fmb'); pb.addparam(parSaveFilename,'MYOUTPUT','Output Filename','c:\iconreport.txt','Text File (*.txt)|*.txt|All Files (*.*)|*.*'); if ps.ShowParamScreen('Icon Usage Reporter ...') then begin //get the values specified on the parameterscreen out_filename := ps.Paramvalue('MYOUTPUT'); if out_filename ='' then raiseexception('Output filename needs to be specified!'); //get all selected *.mmb files in an array(stringlist) files := tstringlist.create; files.text := ps.ParamValue('MYFILES'); //create a list for getting the icons. set the list to ignore duplicates //as we don't want same icons multiple times iconlist := tstringlist.create; iconlist.sorted := true; iconlist.duplicates := dupIgnore; //loop through all selected files and extract the icons for j := 0 to files.count-1 do begin //get the filename from the filelist filename := files.strings[j]; logadd('Extracting '+to_char(j+1)+'/'+to_char(files.count)+' '+filename); // try to load the form try frm := Menu_Load(filename); //first get all icons from pushbuttons items := API_GetAllItemObjects(frm); for i := 0 to items.count-1 do begin //only check items of type push-button if generic_GetValue(items.objects[i],D2FP_ITM_TYP) = D2FC_ITTY_PB then begin //get the icon file name iconname := lower(Generic_GetValue(items.objects[i],D2FP_ICON_FLNAM)); if iconname <> '' then begin //can we already find the icon name in our list ?! x := iconlist.indexof(iconname); if x <0 then begin //not found in list, add new one and set counter to 1 iconlist.addobject(iconname,1); end else begin //icon already found in list, so just increment counter by one! iconlist.objects[x] := iconlist.objects[x] + 1; end; end; end; end; //remove the list of items from memory items.free; //now also get all icons from the sourcecode in //set_item_property('???',icon_name,'???') calls! items := API_GetAllSourceObjects(frm); for i := 0 to items.count-1 do begin src := lower(API_GetPLSQL(items.objects[i])); findpos := 0; repeat //search for our set_item_property call findpos := instr(src,'set_item_property',findpos+1); if findpos>0 then begin if ctrim( Get_PLSQL_Param(src,findpos,1,'xxxx') ) = 'icon_name' then begin //we found one! iconname := lower(Get_PLSQL_Param(src,findpos,2,'xxxx')); //is the first character an apostrophe ?! if iconname[1] = '''' then begin //the name is a constant, so remove the single quotes arround it iconname := ctrim(iconname,''''); end else begin //it was not an appostroph - so he used a variable to set the iconname iconname := '??? variable <'+iconname+'>'; end; //try to find the index of this iconname in the list x := iconlist.indexof(iconname); if x <0 then begin //not found in list, add new one and set counter to 1 iconlist.addobject(iconname,1); end else begin //icon already found in list, just increment counter then! iconlist.objects[x] := iconlist.objects[x]+1; end; end; end; until findpos=0; // loop until string not anymore found! end; //remove the list of items from memory items.free; //free the forms module from memory API_DestroyModule(frm); except //output the error if something happened logadd(' =>'+GetError , LogError); end; end; //delete the ouput file deletefile(out_filename); //loop through the list of icons and append them to the report file for i := 0 to iconlist.count-1 do begin //report number of occurences, the name, and a cr/lf to add a new line s := rpad(to_char(iconlist.objects[i]),7) + iconlist.strings[i] + C_CR; saveappendstring(s,out_filename); end; //display our report in notepad host('notepad '+out_filename,false); end; //free the parameterscreen from memory ps.free; END.