'V1.R2.12'및 'V0.R15.42'와 같은 버전을 올바르게 처리하려는 경우 조금 더 까다 롭습니다. 다른 대답에서 간단한 변환을 사용하면 1212와 1542를 얻을 수 있습니다. , 그것은 당신이 기대하는 방식을 비교하지 않을 것입니다.
버전 번호의 각 부분의 크기를 결정하고 해당 값을 곱하여 올바른 끝 번호를 가져와야합니다. 이런 식으로 뭔가 :
[Code]
function string_to_numerical_value(AString: string; AMaxVersion: LongWord): LongWord;
var
InsidePart: boolean;
NewPart: LongWord;
CharIndex: integer;
c: char;
begin
Result := 0;
InsidePart := FALSE;
// this assumes decimal version numbers !!!
for CharIndex := 1 to Length(AString) do begin
c := AString[CharIndex];
if (c >= '0') and (c <= '9') then begin
// new digit found
if not InsidePart then begin
Result := Result * AMaxVersion + NewPart;
NewPart := 0;
InsidePart := TRUE;
end;
NewPart := NewPart * 10 + Ord(c) - Ord('0');
end else
InsidePart := FALSE;
end;
// if last char was a digit the last part hasn't been added yet
if InsidePart then
Result := Result * AMaxVersion + NewPart;
end;
는 다음과 같은 코드를 사용하여이 문제를 테스트 할 수 있습니다 : 당신이 AMaxVersion
10, 100 또는 1000를 전달하는
function InitializeSetup(): Boolean;
begin
if string_to_numerical_value('V1.R2.12', 1) < string_to_numerical_value('V0.R15.42', 1) then
MsgBox('Version ''V1.R2.12'' is not as recent as version ''V0.R15.42'' (false)', mbConfirmation, MB_OK);
if string_to_numerical_value('V1.R2.12', 100) > string_to_numerical_value('V0.R15.42', 100) then
MsgBox('Version ''V1.R2.12'' is more recent than version ''V0.R15.42'' (true)', mbConfirmation, MB_OK);
Result := FALSE;
end;
는 버전 번호 부품의 수와 범위에 따라 달라집니다. 최대 값이 2^32 - 1 인 LongWord
결과 변수를 오버플로해서는 안됩니다.
마지막으로 비교 한 번호 (.12)가 있습니까? 'R'은 릴리스를 의미한다고 가정하면 하나의 빌드 번호 만 연결되므로 솔리드 릴리스 프로세스가있는 경우이를 무시할 수 있습니다. – Treb