Forum > FPC development
[Solved] Exception in TFileVersionInfo.ReadFileInfo
OLLI_S:
Hello,
I get some exceptions when I read the file info from some applications and the method I am using is provided by Lazarus.
I use Lazarus 1.8.4 in Windows 10 Pro German.
My programming skills I would estimate between beginner and intermediate.
I programmed a little tool that reads all information (like copyright, version info, etc) from applications.
I used the following code example: http://wiki.freepascal.org/Show_Application_Title,_Version,_and_Company
I created a new project in Lazarus, added a button and for the Button1Click event I pasted some code from the WIKI article above.
Here is the complete source of my unit:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, fileinfo, winpeimagereader; {need this for reading exe info} type { TForm1 } TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private public end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject); var FileVerInfo: TFileVersionInfo; begin FileVerInfo := TFileVersionInfo.Create(nil); try FileVerInfo.FileName := 'C:\lazarus\lazarus.exe'; FileVerInfo.ReadFileInfo; ShowMessage(FileVerInfo.VersionStrings.Text); finally FileVerInfo.Free; end; end; end.
This works perfectly for most applications.
But some applications raise exceptions at the line FileVerInfo.ReadFileInfo; (line 47).
Examples:
* C:\Program Files\FreeCommander XE\FreeCommander.exe
Exception Message: Cannot find resource: Type = 1, Name = 17, Lang ID = 0800)
* C:\Program Files (x86)\System Explorer\SystemExplorer.exe
Exception Message: Cannot find resource: Type = 1, Name = 12, Lang ID = 0000)
* D:\PortableApps\PortableApps\FirefoxPortable\App\Firefox\firefox.exe
Exception Message: Duplicate key '0'
* D:\PortableApps\PortableApps\_ToDoList\ToDoList.exe
Exception Message: Duplicate key 'oList'
As I wrote above I am not a good programmer.
But in FileVerInfo.ReadFileInfo I see no exception handling (the block "except").
Could that be the problem?
Is this a problem that can be fixed from your side (Lazarus Developers) or do I have to do anything?
I also can not set a breakpoint in FileVerInfo.ReadFileInfo to see what line causes the problems (the debugger does not stop, no matter where I set the breakpoint).
If you have any tips how I can make the breakpoint working, this would be fantastic.
I have in Lazarus the two additional packages anchordockingdsgn and sparta_DockedFormEditor.
I hope that this is not the reason for my problems (but I think not).
Thank you for your help!
Best regards
OLLI
ASerge:
--- Quote from: OLLI_S on July 11, 2018, 09:45:08 pm ---I get some exceptions when I read the file info from some applications and the method I am using is provided by Lazarus.
--- End quote ---
Please, give a link to the "some applications" exe file (without setup), for testing.
OLLI_S:
Hello ASerge,
--- Quote from: ASerge on July 12, 2018, 06:34:19 am ---Please, give a link to the "some applications" exe file (without setup), for testing.
--- End quote ---
I posted the names of some of these applications (Firefox, System Explorer, etc) in my first posting.
I suppose you have Linux because you asked for the EXE without installers?
So I will upload the EXE files to OneDrive tonight and send the links.
OLLI
ASerge:
--- Quote from: OLLI_S on July 12, 2018, 11:04:18 am ---I posted the names of some of these applications (Firefox, System Explorer, etc) in my first posting.
--- End quote ---
Oops, missed FireFox.
Yeah, it looks like a bug. If you need only under Windows, here's a quick made module (attached), it seems to work.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---uses VerInfo; procedure TForm1.Button1Click(Sender: TObject);var VerInfo: TVersionInfo; procedure AppendInfo(const Value: string); begin Memo1.Append(Value + '=' + VerInfo[Value]); end; var LV: TLongVersion;begin VerInfo := TVersionInfo.Create('c:\Program Files (x86)\Mozilla Firefox\firefox.exe'); try Memo1.Clear; AppendInfo(CviFileVersion); AppendInfo(CviFileDescription); AppendInfo(CviLegalCopyright); AppendInfo(CviOriginalFilename); AppendInfo(CviProductName); AppendInfo('BuildID'); LV := VerInfo.FileLongVersion; Memo1.Append(Format('FileLongVersion=%d.%d.%d.%d', [LV.Words[3], LV.Words[2], LV.Words[1], LV.Words[0]])); finally VerInfo.Free; end;end;
OLLI_S:
Hello,
I copied your VerInfo.pp into the folder of my project and use it like you did in your source code.
It is working, all apps are now shown without any exceptions!
Fantastic work!
Is this a fix that will be included in Lazarus in the future?
So I don't need your code in my project folder?
Thank you again and best regards
OLLI
Navigation
[0] Message Index
[#] Next page