mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-12 22:19:18 +02:00
CodeTools example AddFpprofCalls: show help if no filename is given. Fix memory leak.
git-svn-id: branches/fixes_1_8@56305 -
This commit is contained in:
parent
c1961125f0
commit
2dd75ec29d
@ -64,6 +64,43 @@ var
|
|||||||
FromPos: objpas.Integer;
|
FromPos: objpas.Integer;
|
||||||
ToPos: objpas.Integer;
|
ToPos: objpas.Integer;
|
||||||
|
|
||||||
|
procedure ShowHelp;
|
||||||
|
begin
|
||||||
|
writeln('addfpprofcalls');
|
||||||
|
writeln;
|
||||||
|
writeln('List function signatures, or add or remove fpprofiler calls to selected functions.');
|
||||||
|
writeln;
|
||||||
|
writeln('Usage: <options> <unit file name> <function signature> <function signature> ...');
|
||||||
|
writeln(' -h : write this help');
|
||||||
|
writeln(' -r : remove calls instead of list');
|
||||||
|
writeln(' -a : add calls instead of list');
|
||||||
|
writeln;
|
||||||
|
writeln('Example');
|
||||||
|
writeln(' List all function signatures of unit1.pas');
|
||||||
|
writeln(' ',ParamStrUTF8(0),' unit1.pas');
|
||||||
|
writeln(' Add fpprofiler calls to TForm.Button1Click:');
|
||||||
|
writeln(' ',ParamStrUTF8(0),' -a unit1.pas TForm1.Button1Click(:TObject)');
|
||||||
|
writeln(' Remove fpprofiler calls from TForm.Button1Click:');
|
||||||
|
writeln(' ',ParamStrUTF8(0),' -r unit1.pas TForm1.Button1Click(:TObject)');
|
||||||
|
writeln;
|
||||||
|
writeln('Before:');
|
||||||
|
writeln('=======');
|
||||||
|
writeln('procedure TMainForm.Button1Clicked(...)');
|
||||||
|
writeln('begin');
|
||||||
|
writeln(' // do something here');
|
||||||
|
writeln('end;');
|
||||||
|
writeln;
|
||||||
|
writeln('After:');
|
||||||
|
writeln('======');
|
||||||
|
writeln('procedure TMainForm.Button1Clicked(...)');
|
||||||
|
writeln('begin');
|
||||||
|
writeln(' SendMethodEnter(''TMainForm.Button1Clicked'');');
|
||||||
|
writeln(' // do something here');
|
||||||
|
writeln(' SendMethodExit(''TMainForm.Button1Clicked'');');
|
||||||
|
writeln('end;');
|
||||||
|
writeln;
|
||||||
|
end;
|
||||||
|
|
||||||
procedure RemoveCall;
|
procedure RemoveCall;
|
||||||
begin
|
begin
|
||||||
FromPos:=Tool.CurPos.StartPos;
|
FromPos:=Tool.CurPos.StartPos;
|
||||||
@ -98,39 +135,8 @@ begin
|
|||||||
for i:=1 to ParamCount do begin
|
for i:=1 to ParamCount do begin
|
||||||
Param:=ParamStrUTF8(i);
|
Param:=ParamStrUTF8(i);
|
||||||
if (Param='-h') or (Param='-?') then begin
|
if (Param='-h') or (Param='-?') then begin
|
||||||
writeln('addfpprofcalls');
|
ShowHelp;
|
||||||
writeln;
|
exit;
|
||||||
writeln('List function signatures, or add or remove fpprofiler calls to selected functions.');
|
|
||||||
writeln;
|
|
||||||
writeln('Usage: <options> <unit file name> <function signature> <function signature> ...');
|
|
||||||
writeln(' -h : write this help');
|
|
||||||
writeln(' -r : remove calls instead of list');
|
|
||||||
writeln(' -a : add calls instead of list');
|
|
||||||
writeln;
|
|
||||||
writeln('Example');
|
|
||||||
writeln(' List all function signatures of unit1.pas');
|
|
||||||
writeln(' ',ParamStrUTF8(0),' unit1.pas');
|
|
||||||
writeln(' Add fpprofiler calls to TForm.Button1Click:');
|
|
||||||
writeln(' ',ParamStrUTF8(0),' -a unit1.pas TForm1.Button1Click(:TObject)');
|
|
||||||
writeln(' Remove fpprofiler calls from TForm.Button1Click:');
|
|
||||||
writeln(' ',ParamStrUTF8(0),' -r unit1.pas TForm1.Button1Click(:TObject)');
|
|
||||||
writeln;
|
|
||||||
writeln('Before:');
|
|
||||||
writeln('=======');
|
|
||||||
writeln('procedure TMainForm.Button1Clicked(...)');
|
|
||||||
writeln('begin');
|
|
||||||
writeln(' // do something here');
|
|
||||||
writeln('end;');
|
|
||||||
writeln;
|
|
||||||
writeln('After:');
|
|
||||||
writeln('======');
|
|
||||||
writeln('procedure TMainForm.Button1Clicked(...)');
|
|
||||||
writeln('begin');
|
|
||||||
writeln(' SendMethodEnter(''TMainForm.Button1Clicked'');');
|
|
||||||
writeln(' // do something here');
|
|
||||||
writeln(' SendMethodExit(''TMainForm.Button1Clicked'');');
|
|
||||||
writeln('end;');
|
|
||||||
Halt;
|
|
||||||
end else if Param='-r' then
|
end else if Param='-r' then
|
||||||
Mode:=mRemove
|
Mode:=mRemove
|
||||||
else if Param='-a' then
|
else if Param='-a' then
|
||||||
@ -146,6 +152,11 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
if Filename='' then begin
|
||||||
|
ShowHelp;
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
// load the file
|
// load the file
|
||||||
Code:=CodeToolBoss.LoadFile(Filename,false,false);
|
Code:=CodeToolBoss.LoadFile(Filename,false,false);
|
||||||
if Code=nil then
|
if Code=nil then
|
||||||
|
Loading…
Reference in New Issue
Block a user