Project version within IDE package? lazarus / 9-Editor ---------------------------------------------------------------------- CCRDude · 2021-08-30 15:36 Background: I've got these package that checks if an installer script (InnoSetup, NSIS, WiX) is part of the project, and if so, compiles the setup upon a successful compile. Question: how do I access the version resource information of the current project (LazarusIDE.ActiveProject)?  I checked that it has a property Resources, which is TObject, but probably TAbstractProjectResources. But to get the version number this way, I guess I would need TProjectVersionInfo. TLazProject has a ProjectInfoFile property, but manually reading it there wouldn't be the best approach if there was something more direct available. How would I best access the project version number from the version resource from within an IDE package? ---------------------------------------------------------------------- CCRDude · 2021-08-30 15:52 Thanks, but that's not what I was asking for ParamStr(0) within the Lazarus IDE would be lazarus.exe. I don't want the file version of the IDE, I want the file version (or better project version) the IDE has for the currently open project.  This might be another workaround - retrieving the version from the finished compiled file. Since I have that for codesigning it anyway, I could use it to read the file, using IDEMacros.SubstituteMacros('$(TargetFile)'). This was buggy though for DLLs if I remember correctly. Or  LazarusIDE.ActiveProject.LazBuildMod es.BuildModes[LazarusIDE.ActiveProject.LazBuildModes.IndexOf(LazarusID E.ActiveProject.ActiveBuildModeID)].LazCompilerOptions.TargetFileName ---------------------------------------------------------------------- CCRDude · 2021-08-30 16:05 I haven't attached any resource to my package - I'm speaking about the IDE project version properties! Take a look at any projects .lpi file - they're stored in an XML file there, for example, which is fundamentally different from PE's version resource either as .rc or .res. And they're surely stored in memory somewhere, where the resource compiler takes them from while linking the file. Taking the version from the compilers output works in this case, but think of IDE packages that want to access the version number without compiling first. ---------------------------------------------------------------------- balazsszekely · 2021-08-30 16:25 Hi CCRDude, The version info is stored in the *.lpi. Just loop through the project files, then parse the lpi to get the version: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   for I := 0 to LazarusIDE.ActiveProject.FileCount - 1 do  begin    if LowerCase(ExtractFileExt(LazarusIDE.ActiveProject.Files[I].Filename)) = '.lpi' then    begin       ParseLPI(LazarusIDE.ActiveProject.Files[I].Filename);       Break;  end;  end;  PS: ParseLPI is not implemented in the above example, but it shouldn't be to difficult to get the values from the xml file. ---------------------------------------------------------------------- CCRDude · 2021-08-30 16:44 I probably posted in the wrong subforum What it’s about: the IDE can be enhanced by custom packages. I’ve created a few. This question does is about accessing information from within the IDE, about the current project. The “ParseLPI” approach is nice, but might not reflect changes made but not yet saved, and needs a lot of error handling already implemented in the code the IDE uses to parse it. Might implement both, one as a fallback, but direct access through the LazarusIDE.ActiveProject.Resources would of course be better ---------------------------------------------------------------------- balazsszekely · 2021-08-30 17:14 @CCRDude Quotedirect access through the LazarusIDE.ActiveProject.Resources would of course be betterI don't think ProjectIntf is ripe enough for that, it can be extended though. QuoteThe “ParseLPI” approach is nice, but might not reflect changes made but not yet saved, and needs a lot of error handling already implemented in the code the IDE uses to parse it. Before you run the project, the lpi is saved. Until then the temporary modification of the version info is meaningless. You can try something like this(not tested): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses Laz2_XMLCfg; function ParseLPI(const APath: String): String;   function VersionBound(const AVersion: Integer): Integer;  begin    if AVersion > 9999 then      Result := 9999    else if AVersion < 0 then      Result := 0    else      Result := AVersion;  end; var  XML: TXMLConfig;  UseVersionInfo: Boolean;  Major, Minor, Release, Build: Integer;  BasePath: String;begin  Result := '';   XML := TXMLConfig.Create(APath);  try    BasePath := 'ProjectOptions/VersionInfo/';    UseVersionInfo := XML.GetValue(BasePath + 'UseVersionInfo/Value', False);    if UseVersionInfo then    begin      Major := VersionBound(XML.GetValue(BasePath + 'MajorVersionNr/Value', 0));    Minor := VersionBound(XML.GetValue(BasePath + 'MinorVersionNr/Value', 0));      Release := VersionBound(XML.GetValue(BasePath + 'RevisionNr/Value', 0));      Build := VersionBound(XML.GetValue(BasePath + 'BuildNr/Value', 0));      Result := IntToStr(Major) + '.' + IntToStr(Minor) + '.' + IntToStr(Release) + '.' + IntToStr(Build);    end;  finally    XML.Free;  end;end; ---------------------------------------------------------------------- balazsszekely · 2021-08-30 20:36 @cdesim QuoteThe nodes you are referring to from the .lpi file are constain the information that is designated in the resource - the very same information that is returned by TFileVersionInfo class.OK, but you must realize that you're inside a package and the only way to communicate with the IDE is the package/project editing interface(limited communication). QuoteAnd you don't want to read it from a file becuase it may change while the project is actively being developed.It may change until you save or run the project. Until then is just a hanging information. More over, if necessary, you can catch the changed version info on project close: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i LazarusIDE.AddHandlerOnProjectClose(@OnProjectClose); ---------------------------------------------------------------------- CCRDude · 2021-08-31 09:46 Quote from: GetMem on August 30, 2021, 06:25:11 pmHi CCRDude, The version info is stored in the *.lpi. Just loop through the project files, then parse the lpi to get the version: Since the LPI kind of is the project, it is not listed as a file. But it's available as LazarusIDE.ActiveProject.ProjectInfoFile I'm now using GetMems .lpi method, with a fallback to cdesims binary method, and it works like a charm, thanks a lot! https://gitlab.com/ccrdude/lazinstallerhelper/- /commit/0669878fffa95d59827ca5f56ed113229dfa7b00 Next question will go into packages subforum I guess