Buildnummer einer Anwendung bestimmenManchmal sieht man ja in anderen Programmen oder sogar in Windows die Build-Nummer des Produkts. ;)
Basierend auf
dieser hier eine Funktion, mit der man aus Dateien diesen Wert ermitteln kann:
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50:
| function GetBuildNumber(Filename: string): string; type thilo=record case integer of 0: (all:dword); 1: (lo:word;hi:word); end;
var buffer:pointer; dummy:cardinal; size:cardinal; p:pointer; data:^vs_FIXEDFILEINFO; hilo:thilo; lastpointindex:integer; begin result:=''; size:=GetFileVersionInfoSize(pchar(filename),dummy); GetMem(buffer,size); try if not GetFileVersionInfo(pchar(application.exename),0,size,buffer) then begin result := ''; exit; end; p:=nil; if not VerQueryValue(buffer,pchar(''),p,size) then begin result := ''; exit; end; data:=p; hilo.all:=data^.dwFileVersionms; result:=IntToStr(hilo.hi); result:=result+'.'+IntToStr(hilo.lo); hilo.all:=data^.dwFileVersionls; result:=result+'.'+IntToStr(hilo.hi); result:=result+'.'+IntToStr(hilo.lo); finally FreeMem(buffer); end;
result := ReverseString(result); lastpointindex := Length(result) - Pos('.',result) + 1; result := ReverseString(result); result := Copy(result,lastpointindex + 1,Length(result) - lastpointindex); end; |
Es muss noch die Unit
StrUtils eingebunden werden.
Zwei Beispiel-Aufrufe:
Delphi-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
| procedure TForm1.Button3Click(Sender: TObject); begin showmessage(GetBuildNumber(Application.ExeName)); end;
procedure TForm1.FormCreate(Sender: TObject); begin Caption := Caption + ' - Build ' + GetBuildNumber(Application.ExeName); end; |
Moderiert von Christian S: Parametererklärung eingefügt und Formatierung überarbeitet.
Pascal keeps your hand tied. C gives you enough rope to hang yourself. C++ gives you enough rope to shoot yourself in the foot