Skip to content

Commit 612b60a

Browse files
author
delphidabbler
committed
Revise TVersionNumber to allow implicit casts to string
Did some refactoring to avoid duplicated code with Explicit cast to string
1 parent 7ecccf0 commit 612b60a

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Src/UVersionInfo.pas

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ interface
3030
Record representing the four fields of a version number.
3131
}
3232
TVersionNumber = record
33+
strict private
34+
/// <summary>Converts version number to a string.</summary>
35+
function ToString: string;
3336
public
3437
V1: Word; // Major version number
3538
V2: Word; // Minor version number
@@ -107,6 +110,12 @@ TVersionNumber = record
107110
@return Converted version number.
108111
@except EConvertError. raised if string in wrong format.
109112
}
113+
class operator Implicit(Ver: TVersionNumber): string;
114+
{Operator overload that performs implicit conversion of a version number
115+
to a string in dotted quad format.
116+
@param Ver [in] Version number to be converted.
117+
@return Dotted quad string.
118+
}
110119
class operator Explicit(Ver: TVersionNumber): TPJVersionNumber;
111120
{Operator overload that performs an explicit conversion of a
112121
TVersionNumber to a TPJVersionNumber (from PJVersionInfo unit).
@@ -269,7 +278,7 @@ class function TVersionInfo.SpecialBuildStr: string;
269278
@return Dotted quad string.
270279
}
271280
begin
272-
Result := Format('%d.%d.%d.%d', [Ver.V1, Ver.V2, Ver.V3, Ver.V4]);
281+
Result := Ver.ToString;
273282
end;
274283

275284
class operator TVersionNumber.GreaterThan(Ver1, Ver2: TVersionNumber): Boolean;
@@ -327,6 +336,16 @@ function TVersionNumber.IsNull: Boolean;
327336
Result.V4 := Ver.V4;
328337
end;
329338

339+
class operator TVersionNumber.Implicit(Ver: TVersionNumber): string;
340+
{Operator overload that performs implicit conversion of a version number to a
341+
string in dotted quad format.
342+
@param Ver [in] Version number to be converted.
343+
@return Dotted quad string.
344+
}
345+
begin
346+
Result := Ver.ToString;
347+
end;
348+
330349
class operator TVersionNumber.LessThan(Ver1, Ver2: TVersionNumber): Boolean;
331350
{Operator overload that compares two version numbers to check if first is
332351
less than second.
@@ -371,6 +390,11 @@ class function TVersionNumber.Nul: TVersionNumber;
371390
Result.V4 := 0;
372391
end;
373392

393+
function TVersionNumber.ToString: string;
394+
begin
395+
Result := Format('%d.%d.%d.%d', [V1, V2, V3, V4]);
396+
end;
397+
374398
class function TVersionNumber.TryStrToVersionNumber(const S: string;
375399
out V: TVersionNumber): Boolean;
376400
var

0 commit comments

Comments
 (0)