Autor Beitrag
Marco D.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 2750

Windows Vista
Delphi 7, Delphi 2005 PE, PHP 4 + 5 (Notepad++), Java (Eclipse), XML, XML Schema, ABAP, ABAP OO
BeitragVerfasst: Mi 07.02.07 23:03 
Buildnummer einer Anwendung bestimmen

Manchmal 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:
ausblenden volle Höhe Delphi-Quelltext
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:
//Bestimmt die Buildnummer einer Anwendung
//Parameter:
//  Filename: Der vollständige Dateiname inkl. Pfad der Anwendung, von der die Buildnummer bestimmt werden soll.
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:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
//Aufruf e.g.:
procedure TForm1.Button3Click(Sender: TObject);
begin
  showmessage(GetBuildNumber(Application.ExeName));
end;

//Anzeigen in Titelleiste:
procedure TForm1.FormCreate(Sender: TObject);
begin
  Caption := Caption + ' - Build ' + GetBuildNumber(Application.ExeName);
end;


Moderiert von user profile iconChristian 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


Zuletzt bearbeitet von Marco D. am Mo 19.02.07 21:44, insgesamt 3-mal bearbeitet