紧急问题:怎么比较两个文件的版本新旧?(在线)(100分)

  • 主题发起人 主题发起人 fancy105
  • 开始时间 开始时间
F

fancy105

Unregistered / Unconfirmed
GUEST, unregistred user!
用Delphi5编写的程序,设置了版本号,并保存到数据库中,
变更新版本后,再将旧版本从数据库中读出进行比较,请问怎么比较两版本的新旧?
 
//如果V1>V2 返回1 ,否则返回-1 相等返回0
function TForm1.CompVer(V1, V2: string): integer;
var
tmpV1, tmpV2: TStringList;
intV1, intV2: integer;
i: integer;
begin
Result:=0;
tmpV1:=TStringList.Create;
tmpV2:=TStringList.Create;
tmpV1.Text:=StringReplace(V1,'.',#13#10,[rfReplaceAll, rfIgnoreCase]);
tmpV2.Text:=StringReplace(V2,'.',#13#10, [rfReplaceAll, rfIgnoreCase]);
FormatString(tmpV1, tmpV2);

for i:=0 to tmpV1.Count-1 do
begin
intV1:=StrToInt(tmpV1.Strings);
intV2:=StrToInt(tmpV2.Strings);

if intV1 = intV2 then continue;

if intV1 > intV2 then
Result:=1
else Result:=-1;

exit;
end;
tmpV1.Free;
tmpV2.Free;
end;

//格式化版本号,使两的‘.’相等
procedure TForm1.FormatString(var V1, V2: TStringList);
var
VCount, i: integer;
begin
VCount:=V1.Count-V2.Count;
if VCount > 0 then
for i:=1 to VCount do V2.Add('0')
else for i:=VCount to -1 do V1.Add('0');
end;

用这个则试一下
Label1.Caption:=inttostr( CompVer(Edit1.Text, Edit2.Text));

 
給你一個程式獲取文件版本的:
type
PFixedFileInfo = ^TFixedFileInfo;
TFixedFileInfo = record
dwSignature: DWORD;
dwStrucVersion: DWORD;
wFileVersionMS: WORD; // 次版本?
wFileVersionLS: WORD; // 主版本?
wProductVersionMS: WORD; // 建立次?(build)
wProductVersionLS: WORD; // ?行次?(release)
dwFileFlagsMask: DWORD;
dwFileFlags: DWORD;
dwFileOS: DWORD;
dwFileType: DWORD;
dwFileSubtype: DWORD;
dwFileDateMS: DWORD;
dwFileDateLS: DWORD;
end; // TFixedFileInfo

//下面是取版本信息函?

function FileInfo(const FileName: string): TFixedFileInfo;
var
dwHandle, dwVersionSize: DWORD;
strSubBlock: string;
pTemp: Pointer;
pData: Pointer;
begin
strSubBlock := '/';

// 取得文件版本信息的大小
dwVersionSize := GetFileVersionInfoSize(PChar(FileName), dwHandle);

if dwVersionSize <> 0 then
begin
GetMem(pTemp, dwVersionSize);
try
//取文件版本信息
if GetFileVersionInfo(PChar(FileName), dwHandle,
dwVersionSize, pTemp) then
//查?文件版本信息
if VerQueryValue(pTemp, PChar(strSubBlock),
pData, dwVersionSize) then
Result := PFixedFileInfo(pData)^;
finally
FreeMem(pTemp);
end; // try
end; // if dwVersionSize
end;
 
太麻烦了,也不太精确。有没有更精确点的?
 
看来只能将版本号分段比较了!
 
算了吧!
 
多人接受答案了。
 
后退
顶部