获取程序文件自身版本

procedure TFormLogin.FormCreate(Sender: TObject);
var
  MyVersion,: string;
  Block: ^VS_FIXEDFILEINFO;
  PDatA: pointer;
  Dsize, Dlen: Dword;
begin
  // 版本检查开关
  MYDEBUG := DebugHook = 1;

  DLen := GetFileVersioninfoSize(Pchar(ParamStr(0)), Dsize);
  GetMem(Pdata, Dlen);
  try
    if GetFileVersionInfo(pchar(ParamStr(0)), Dsize, Dlen, Pdata) then begin
      Block := nil;
      VerQueryValue(pdata,'\', pointer(Block), Dsize);
      if Block <> nil then begin
        MyVersion := Format('%d.%d.%d.%d',
         [Block^.dwFileVersionMS shr 16,Block^.dwFileVersionMS and $0000ffff,
          Block^.dwFileVersionLS shr 16,Block^.dwFileVersionLS and $0000ffff]);
      end;
    end;
  finally
    freemem(pdata, DLEN);
  end;

  lblAbout.Caption := 'V ' + MyVersion;
end;

你可能感兴趣的:(获取程序文件自身版本)