Hallo,
diese Variante hat mir
Matti vor einiger Zeit so geschickt, näheres dazu auch
hier
Delphi-Quellcode:
type
TGetVersionsStr = Record
ShortString: String[12];
LongString: String[24];
end;
Delphi-Quellcode:
function TForm1.GetVersion: TGetVersionsStr;
var
VerInfoSize: DWORD;
VerInfo: Pointer;
VerValueSize: DWORD;
VerValue: PVSFixedFileInfo;
Dummy: DWORD;
begin
VerInfo := nil;
try
VerInfoSize := GetFileVersionInfoSize(PChar(ParamStr(0)), Dummy);
try
GetMem(VerInfo, VerInfoSize);
GetFileVersionInfo(PChar(ParamStr(0)), 0, VerInfoSize, VerInfo);
VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
with VerValue^ do
begin
Result.LongString := Format('%d.%d.%d.%d',
[dwFileVersionMS shr 16,
dwFileVersionMS and $FFFF,
dwFileVersionLS shr 16,
dwFileVersionLS and $FFFF]);
Result.ShortString := Format('%d.%d',
[dwFileVersionMS shr 16,
dwFileVersionMS and $FFFF]);
end;
finally
FreeMem(VerInfo, VerInfoSize);
end;
except
Result.ShortString := #$31#$2E#$30; // 1.0
Result.LongString := Result.ShortString;
end;
end;
Aufruf:
Label1.Caption := format('Version: %s', [GetVersion.LongString]); //oder natürlich auch 'GetVersion.ShortString'