File: v3dscenewarnings.pas

package info (click to toggle)
view3dscene 4.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 13,824 kB
  • sloc: pascal: 3,961; sh: 330; xml: 261; makefile: 133
file content (78 lines) | stat: -rw-r--r-- 1,555 bytes parent folder | download | duplicates (6)
1
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
unit V3DSceneWarnings;

interface

uses Classes;

type
  { A simple wrapper around TStringList.

    Adds multiline strings (with NL inside) nicely.

    And keeps Count property separate,
    Count property reflects number of added items (as opposed to
    TStringList.Count, that reflects the number of lines, which is different
    when we added multiline strings). }
  TSceneWarnings = class
  private
    FCount: Cardinal;
  public
    constructor Create;
    destructor Destroy; override;
  public
    Items: TStringList;
    property Count: Cardinal read FCount;

    procedure Add(const S: string);
    procedure Clear;
    procedure Assign(Source: TSceneWarnings);
  end;

implementation

uses SysUtils, CastleUtils;

constructor TSceneWarnings.Create;
begin
  inherited;
  Items := TStringList.Create;
end;

destructor TSceneWarnings.Destroy;
begin
  FreeAndNil(Items);
  inherited;
end;

procedure TSceneWarnings.Add(const S: string);
var
  SWarning: TStringList;
begin
  if Pos(NL, S) <> 0 then
  begin
    { Handle multiline error msgs in S nicely (multiline error msgs may
      be generated e.g. when GLSL shader source code has errors). }
    SWarning := TStringList.Create;
    try
      SWarning.Text := S;
      Items.AddStrings(SWarning);
    finally FreeAndNil(SWarning) end;
  end else
    Items.Append(S);

  Inc(FCount);
end;

procedure TSceneWarnings.Clear;
begin
  Items.Clear;
  FCount := 0;
end;

procedure TSceneWarnings.Assign(Source: TSceneWarnings);
begin
  Items.Assign(Source.Items);
  FCount := Source.Count;
end;

end.