function GetVersion(sFile: string; bIncludeBuild: boolean): string;<br>var<br> dwfvw,dwZero,dwvsf
WORD;<br> Major,Minor,Release,Build
Word;<br> pfvw
Char;<br> pvsf
VSFixedFileInfo;<br> s:string;<br>begin<br> Result:='';<br> // attempt to read version info size<br> dwfvw:=GetFileVersionInfoSize(PChar(sFile),dwZero);// exit on error<br> if dwfvw <> 0 then begin<br> GetMem(pfvw, dwfvw);<br> try // exit if unable to retrieve version info<br> if (GetFileVersionInfo(PChar(sFile), dwZero, dwfvw, pfvw)) then begin // get the build value<br> if (VerQueryValue(pfvw, '/', Pointer(pvsf), dwvsf)) then begin<br> if ((pvsf^.dwFileFlags and VS_FF_PRERELEASE) > 0) then begin<br> s := 'beta; '<br> end<br> else begin<br> s := '';<br> end;<br> // For clarity store in temporary variables<br> Major := HIWORD(pvsf^.dwFileVersionMS);<br> Minor := LOWORD(pvsf^.dwFileVersionMS);<br> Release := HIWORD(pvsf^.dwFileVersionLS);<br> Build := LOWORD(pvsf^.dwFileVersionLS);<br> // Always show full Build Numbers from now GN.. 2/9/03<br> Result := Format('Version %d.%d.%d Build %d', [Major, Minor, Release,<br> Build]);<br> if bIncludeBuild then begin<br> if Release > 0 then begin<br> Result := Format('Version %d.%d.%d Build %d', [Major, Minor,<br> Release, Build])<br> end<br> else begin<br> Result := Format('Version %d.%d Build %d', [Major, Minor, Build])<br> end;<br> end<br> else begin<br> if Release > 0 then begin<br> Result := Format('Version %d.%d.%d', [Major, Minor, Release])<br> end<br> else begin<br> Result := Format('Version %d.%d', [Major, Minor])<br> end;<br> end;<br> end;<br> end;<br> finally<br> FreeMem(pfvw);<br> end;<br> end;<br>end;