PROGRAM LinesOfSource; {-- *************************************************************************** -- ** Descr. : Extracts the number of source lines for the given modules. -- ** See also the AppStatistic.p2s -- ** -- ** MINVERS: -- *************************************************************************** -- ** 07/04/02 1.001.00 Initial Creation, muellers@orcl-toolbox.com -- ***************************************************************************} {*Global Variable Declaration*} VAR filename : varchar2; s : varchar2; i,j : number; frm : number; linecnt : number; //holds the number of lines per module totlinecnt : number; //holds the total of all modules files : TStringList; //holds a list of all files selected srcobjects : TStringList; //holds the list of sourcecode objects (triggers,program units, menuitems, recordgroups,etc) src : TStringList; //holds the sourcecode of the given object ps : TParamScreen; pb : TParamBoard; {*Main Program Block*} BEGIN //build together a nice parameter screen ... ps := TParamScreen.create; pb := ps.AddBoard('Modules',picModules); pb.addparam(parFiles,'SRC','Source Files','','Oracle Source Modules (*.fmb;*.mmb;*.pll;*.olb)|*.fmb;*.mmb;*.pll|'+ 'Forms Modules (*.fmb)|*.fmb|'+ 'Menu Modules (*.mmb)|*.mmb|'+ 'Library Modules (*.pll)|*.pll'); pb.addparam(parDatabaseLogon,'MYDATABASE','DB Connection','scott/tiger',''); //show the parameter screen and wait for inputs if ps.ShowParamScreen('Application Statistics ...') then begin //initialize the total number of lines totlinecnt := 0; //try to logon to the database try api_Connect(ps.ParamValue('MYDATABASE')); except logadd('DB Connection failed, proceeding anyway ...'); end; //get the selected files from the parameter screen files := tstringlist.create; files.text := ps.ParamValue('SRC'); //create the list that will hold the sourcecode lines (easiest way of //counting the number of lines because the list object has a property //called COUNT that will contain this information) src := tstringlist.create; //now loop through the file list for j := 0 to files.count-1 do begin linecnt := 0; filename := files.strings[j]; try //load the formsmodule frm := API_LoadModule(filename); //get all objects of the module that contain sourcecode in a list srcobjects := API_GetAllSourceObjects(frm); //loop trough the list of source code objects for i := 0 to srcobjects.count-1 do begin //get the source code of the object src.text := Api_GetPLSQL(srcobjects.objects[i]); //and count it up linecnt := linecnt + src.count; end; //free the list of objects we extracted from memory srcobjects.free; //now release the module from the API memory API_DestroyModule(frm); except // ups! an error happened, so just log it and proceed to the next module logadd(' =>'+GetError,LogError); end; //display the number of lines in a nice way (number right aligned,etc) s := substr(ExtractFileName(filename)+' : ',1,25); s := s + rightstring(' '+to_char(linecnt),10); logadd(s); //increment our total number of lines (for all modules) totlinecnt := totlinecnt + linecnt; end; //free the lists from memory, we don't need them anymore src.free; files.free; //output the total of all modules s := ' Total: '; s := s + rightstring(' '+to_char(totlinecnt),10); logadd(s); end else begin //user must have pressed cancel on parameterscreen logadd('Canceled on parameterscreen!'); end; // free the parameter screen ps.free; END.