

























lazarus IDE宏在BuildManager.pas这个单元管理,现以添加projVer宏,获取当前project的版本号为例:
1、TBuildManager的private添加类似的:
function MacroFuncProjVer(const {%H-}Param: string; const {%H-}Data: PtrInt; var {%H-}Abort: boolean): string;
2、在procedure TBuildManager.SetupTransferMacros添加:
GlobalMacroList.Add(TTransferMacro.Create('ProjVer','', lisProjectVer,@MacroFuncProjVer,[]));
3、在procedure TBuildManager.TranslateMacros添加:
tr('ProjVer',lisProjectVer);
4、在initialization添加MacroFuncProjVer代码(实现读取project的版本号):
function TBuildManager.MacroFuncProjVer(const Param: string; const Data: PtrInt; var Abort: boolean): string; const cParamNames: array of string = ('', 'major', 'minor', 'rev', 'build'); cParamDefVals: array of string = ('0.0', '0', '0', '0', '0'); var i: integer; begin for i := 0 to high(cParamNames) do if CompareText(Param, cParamNames[i]) = 0 then begin // check the project and whether the version is used result := cParamDefVals[i]; if Project1 = nil then exit; if Project1.ProjResources = nil then exit; if Project1.ProjResources.VersionInfo = nil then exit; if Project1.ProjResources.VersionInfo.UseVersionInfo = false then exit; // return version or specified number with Project1.ProjResources.VersionInfo do case i of 1: exit(IntToStr(MajorVersionNr)); 2: exit(IntToStr(MinorVersionNr)); 3: exit(IntToStr(RevisionNr )); 4: exit(IntToStr(BuildNr )); else // return the full version number, discarding the zero revision and build if BuildNr <> 0 then exit(Format('%d.%d.%d.%d', [MajorVersionNr, MinorVersionNr, RevisionNr, BuildNr])) else if RevisionNr <> 0 then exit(Format('%d.%d.%d' , [MajorVersionNr, MinorVersionNr, RevisionNr])) else exit(Format('%d.%d' , [MajorVersionNr, MinorVersionNr])); end; end; result := ''; // invalid parameter end;
5、在LazarusIDEStrConsts.pas单元添加lisProjectVer
lisProjectVer = 'Project version';
修改后重构lazarus。
使用方法:
比如在目标文件名添加版本号,当完成编译后,生成的程序就会带上版本号:


此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。