【开发工具】
1、C++Builder and Delphi 10.3.3
2、FMSoft_uniGUI_Complete_Professional_1.70.0.1514(正版)
开发项目时需要频繁执行编译和运行,但是每次编译前都得先手动停止已经运行的程序,然后重新打开浏览器输入测试地址,十分麻烦,为了提高效率最好能够执行编译时自动停止原来的程序,然后自动运行程序,设置如下:
- 自动停止
操作Project->Options菜单,在Building->BuildEvents->Pre-build events->Commands中添加命令配置,让项目在编译前执行一个命令,杀掉已有进程,命令配置如下:
taskkill /f /im $(OUTPUTFILENAME) 2>1 ||exit /B 0
- 自动启动
在项目的主文件HelloWorld.dpr里添加几行代码,引用几个头文件,并且调用shellExecute打开浏览器访问项目的URL地址,如下所示:
program HelloWorld;
uses
windows,
ShellAPI,
SysUtils,
Forms,
ServerModule in 'ServerModule.pas' {UniServerModule: TUniGUIServerModule},
MainModule in 'MainModule.pas' {UniMainModule: TUniGUIMainModule},
Main in 'Main.pas' {MainForm: TUniForm};
{$R *.res}
begin
ReportMemoryLeaksOnShutdown := True;
Application.Initialize;
TUniServerModule.Create(Application);
if extractFileExt(GetModuleName(Hinstance))='.exe' then
shellExecute(Application.Handle,
PChar('Open'),
PChar('Http://127.0.0.1:8077'),
Nil,Nil,SW_Show);
Application.Run;
end.