Check-in [6062443d50]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Added overloaded operators for TVersion.
Timelines: family | ancestors | descendants | both | feature/async-refresh
Files: files | file ages | folders
SHA1:6062443d50230977c81be59a19abaaa51e5264d1
User & Date: tinus 2015-11-27 21:18:23
Context
2015-11-27
21:19
Added cache class, which should be thread-safe? check-in: 3f0e26decd user: tinus tags: feature/async-refresh
21:18
Added overloaded operators for TVersion. check-in: 6062443d50 user: tinus tags: feature/async-refresh
18:35
Added a unit that provides easy access to version info -- not only a file's, but also the current module's (without accessing the file). Use that for the about box. check-in: 09db10509f user: tinus tags: feature/async-refresh
Changes

Changes to src/u_VersionInfo.pas.

2
3
4
5
6
7
8
9











10
11
12
13
14




15
16
17
18
19
20
21
...
295
296
297
298
299
300
301
302




303


















304











































305
306
307
308

interface

uses
  Windows, SysUtils, System.Classes;

type
  TVersion = record











    Major:    Word;
    Minor:    Word;
    Revision: Word;
    Build:    Word;
    function ToString(): string;




  end;

type
  TFileVersionInfo = class
  {$SCOPEDENUMS ON}
  type
    TFlag = (Debug, PreRelease, Patched, PrivateBuild, SpecialBuild);
................................................................................
    end;
  end;
end;


{ TVersion }

function TVersion.ToString: string;




begin


















  Result := Format('%d.%d.%d.%d', [Major, Minor, Revision, Build]);











































end;

end.








|
>
>
>
>
>
>
>
>
>
>
>
|
|
|
|
<
>
>
>
>







 







|
>
>
>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>




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
...
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387

interface

uses
  Windows, SysUtils, System.Classes;

type
  TVersion = packed record
    class operator Implicit(Text: string): TVersion;
    class operator Implicit(Version: TVersion): string;
    class operator Equal(A, B: TVersion): boolean; inline;
    class operator NotEqual(A, B: TVersion): boolean; inline;
    class operator GreaterThan(A, B: TVersion): boolean; inline;
    class operator GreaterThanOrEqual(A, B: TVersion): boolean; inline;
    class operator LessThan(A, B: TVersion): boolean; inline;
    class operator LessThanOrEqual(A, B: TVersion): boolean; inline;
    function CompareTo(const Other: TVersion): integer;
    case Integer of
      0: (
        Major:    Word;
        Minor:    Word;
        Revision: Word;
        Build:    Word;

      );
      1: (
        Values: packed array[0..3] of Word;
      );
  end;

type
  TFileVersionInfo = class
  {$SCOPEDENUMS ON}
  type
    TFlag = (Debug, PreRelease, Patched, PrivateBuild, SpecialBuild);
................................................................................
    end;
  end;
end;


{ TVersion }

class operator TVersion.Implicit(Text: string): TVersion;
var
  vi, ci: Integer;
  Value: Cardinal;
  Index: Integer;
begin
  Result := Default(TVersion);
  vi := Low(Result.Values);
  ci := 1;
  while (ci <= Length(Text)) and (vi <= High(Result.Values)) do begin
    Val(Copy(Text, ci), Value, Index);
    if Index = 0 then begin // the entire remainder of the string is a valid integer
      Result.Values[vi] := Value;
      Break;
    end else if Index > 1 then begin // we have an integer, followed by something non-integer
      Result.Values[vi] := Value;
      Inc(vi);
    end;
    ci := ci + Index;
  end;
end;

class operator TVersion.Implicit(Version: TVersion): string;
begin
  Result := Format('%d.%d.%d.%d', [Version.Major, Version.Minor, Version.Revision, Version.Build]);
end;

function TVersion.CompareTo(const Other: TVersion): integer;
var
  i: Integer;
begin
  for i := Low(Values) to High(Values) do begin
    if Values[i] < Other.Values[i] then
      Exit(-1)
    else if Values[i] > Other.Values[i] then
      Exit(1);
  end;
  Result := 0;
end;

class operator TVersion.Equal(A, B: TVersion): boolean;
begin
  Result := A.CompareTo(B) = 0;
end;

class operator TVersion.GreaterThan(A, B: TVersion): boolean;
begin
  Result := A.CompareTo(B) > 0;
end;

class operator TVersion.GreaterThanOrEqual(A, B: TVersion): boolean;
begin
  Result := A.CompareTo(B) >= 0;
end;

class operator TVersion.LessThan(A, B: TVersion): boolean;
begin
  Result := A.CompareTo(B) < 0;
end;

class operator TVersion.LessThanOrEqual(A, B: TVersion): boolean;
begin
  Result := A.CompareTo(B) <= 0;
end;

class operator TVersion.NotEqual(A, B: TVersion): boolean;
begin
  Result := A.CompareTo(B) <> 0;
end;

end.