Rev 1 | Rev 11 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1 | Rev 9 | ||
---|---|---|---|
1 | unit Functions; |
1 | unit Functions; |
2 | 2 | ||
3 | interface |
3 | interface |
4 | 4 | ||
5 | uses |
5 | uses |
6 | SysUtils, Dialogs, Graphics, Classes, ExtCtrls; |
6 | SysUtils, Dialogs, Graphics, Classes, ExtCtrls; |
7 | 7 | ||
8 | function ExtractFileNameWithoutExt(filename: string): string; |
8 | function ExtractFileNameWithoutExt(filename: string): string; |
9 | function SecondsToTimeString(Seconds: Integer): string; |
9 | function SecondsToTimeString(Seconds: Integer): string; |
10 | procedure ClearImage(Image: TImage; BackgroundColor: TColor); |
10 | procedure ClearImage(Image: TImage; BackgroundColor: TColor); |
11 | function Ganzzahlig(num: extended): boolean; |
11 | function Ganzzahlig(num: extended): boolean; |
12 | function Explode(Separator, Text: String): TStringList; |
12 | function Explode(Separator, Text: String): TStringList; |
13 | function Position(FullString, Search: String): Integer; |
13 | function Position(FullString, Search: String): Integer; |
14 | function ReadFile(InputFile: string): string; |
14 | function ReadFile(InputFile: string): string; |
15 | function RemoveLineBreaks(inp: string): string; |
15 | function RemoveLineBreaks(inp: string): string; |
16 | 16 | ||
17 | implementation |
17 | implementation |
18 | 18 | ||
19 | resourcestring |
19 | resourcestring |
20 | LNG_COULD_NOT_OPEN_FILE = 'Could not open file "%s".'; |
20 | LNG_COULD_NOT_OPEN_FILE = 'Could not open file "%s".'; |
21 | 21 | ||
22 | function ExtractFileNameWithoutExt(filename: string): string; |
22 | function ExtractFileNameWithoutExt(filename: string): string; |
23 | begin |
23 | begin |
24 | result := ExtractFileName(filename); |
24 | result := ExtractFileName(filename); |
25 | result := copy(result, 1, Length(result)-Length(ExtractFileExt(result))); |
25 | result := copy(result, 1, Length(result)-Length(ExtractFileExt(result))); |
26 | end; |
26 | end; |
27 | 27 | ||
28 | function SecondsToTimeString(Seconds: Integer): string; |
28 | function SecondsToTimeString(Seconds: Integer): string; |
29 | var |
29 | var |
30 | h, m, s: integer; |
30 | h, m, s: integer; |
31 | tim: TDateTime; |
31 | tim: TDateTime; |
32 | begin |
32 | begin |
33 | h := 0; |
33 | h := 0; |
34 | m := 0; |
34 | m := 0; |
35 | s := Seconds; |
35 | s := Seconds; |
36 | 36 | ||
37 | while s - 60*60 >= 0 do |
37 | while s - 60*60 >= 0 do |
38 | begin |
38 | begin |
39 | dec(s, 60*60); |
39 | dec(s, 60*60); |
40 | inc(h); |
40 | inc(h); |
41 | end; |
41 | end; |
42 | 42 | ||
43 | while s - 60 >= 0 do |
43 | while s - 60 >= 0 do |
44 | begin |
44 | begin |
45 | dec(s, 60); |
45 | dec(s, 60); |
46 | inc(m); |
46 | inc(m); |
47 | end; |
47 | end; |
48 | 48 | ||
49 | tim := EncodeTime(h, m, s, 0); |
49 | tim := EncodeTime(h, m, s, 0); |
50 | 50 | ||
51 | result := TimeToStr(tim); |
51 | result := TimeToStr(tim); |
52 | end; |
52 | end; |
53 | 53 | ||
54 | procedure ClearImage(Image: TImage; BackgroundColor: TColor); |
54 | procedure ClearImage(Image: TImage; BackgroundColor: TColor); |
55 | var |
55 | var |
56 | OldPenColor, OldBrushColor: TColor; |
56 | OldPenColor, OldBrushColor: TColor; |
57 | begin |
57 | begin |
58 | OldPenColor := Image.Canvas.Pen.Color; |
58 | OldPenColor := Image.Canvas.Pen.Color; |
59 | OldBrushColor := Image.Canvas.Brush.Color; |
59 | OldBrushColor := Image.Canvas.Brush.Color; |
60 | Image.Canvas.Pen.Color := BackgroundColor; |
60 | Image.Canvas.Pen.Color := BackgroundColor; |
61 | Image.Canvas.Brush.Color := BackgroundColor; |
61 | Image.Canvas.Brush.Color := BackgroundColor; |
62 | Image.Canvas.Rectangle(0, 0, Image.Width, Image.Height); |
62 | Image.Canvas.Rectangle(0, 0, Image.Width, Image.Height); |
63 | Image.Canvas.Pen.Color := OldPenColor; |
63 | Image.Canvas.Pen.Color := OldPenColor; |
64 | Image.Canvas.Brush.Color := OldBrushColor; |
64 | Image.Canvas.Brush.Color := OldBrushColor; |
65 | end; |
65 | end; |
66 | 66 | ||
67 | function Ganzzahlig(num: extended): boolean; |
67 | function Ganzzahlig(num: extended): boolean; |
68 | begin |
68 | begin |
69 | result := num = round(num); |
69 | result := num = round(num); |
70 | end; |
70 | end; |
71 | 71 | ||
72 | function Explode(Separator, Text: String): TStringList; |
72 | function Explode(Separator, Text: String): TStringList; |
73 | var |
73 | var |
74 | pos: integer; |
74 | pos: integer; |
75 | tmp: string; |
75 | tmp: string; |
76 | begin |
76 | begin |
77 | result := TStringList.Create; |
77 | result := TStringList.Create; |
78 | 78 | ||
79 | while Length(Text) > 0 do |
79 | while Length(Text) > 0 do |
80 | begin |
80 | begin |
81 | pos := Functions.Position(Text, Separator); |
81 | pos := Functions.Position(Text, Separator); |
82 | 82 | ||
83 | if pos = -1 then |
83 | if pos = -1 then |
84 | begin |
84 | begin |
85 | tmp := Text; |
85 | tmp := Text; |
86 | Text := ''; |
86 | Text := ''; |
87 | end |
87 | end |
88 | else |
88 | else |
89 | begin |
89 | begin |
90 | tmp := copy(Text, 1, pos-1); |
90 | tmp := copy(Text, 1, pos-1); |
91 | Text := copy(Text, pos+1, Length(Text)-pos); |
91 | Text := copy(Text, pos+1, Length(Text)-pos); |
92 | end; |
92 | end; |
93 | 93 | ||
94 | result.Add(tmp); |
94 | result.Add(tmp); |
95 | end; |
95 | end; |
96 | end; |
96 | end; |
97 | 97 | ||
98 | function Position(FullString, Search: String): Integer; |
98 | function Position(FullString, Search: String): Integer; |
99 | var |
99 | var |
100 | x: Integer; |
100 | x: Integer; |
101 | begin |
101 | begin |
102 | x := Length(StrPos(PChar(FullString), PChar(Search))); |
102 | x := Length(StrPos(PChar(FullString), PChar(Search))); |
103 | if x = 0 then |
103 | if x = 0 then |
104 | result := -1 |
104 | result := -1 |
105 | else |
105 | else |
106 | result := Length(FullString) - x + 1; |
106 | result := Length(FullString) - x + 1; |
107 | end; |
107 | end; |
108 | 108 | ||
109 | function ReadFile(InputFile: string): string; |
109 | function ReadFile(InputFile: string): string; |
110 | var |
110 | var |
111 | f: textfile; |
111 | f: textfile; |
112 | tmp: string; |
112 | tmp: string; |
113 | begin |
113 | begin |
114 | result := ''; |
114 | result := ''; |
115 | 115 | ||
116 | if not FileExists(InputFile) then |
116 | if not FileExists(InputFile) then |
117 | begin |
117 | begin |
118 | ShowMessage(Format(LNG_COULD_NOT_OPEN_FILE, [InputFile])); |
118 | MessageDlg(Format(LNG_COULD_NOT_OPEN_FILE, [InputFile]), mtError, [mbOk], 0); |
119 | Exit; |
119 | Exit; |
120 | end; |
120 | end; |
121 | 121 | ||
122 | AssignFile(f, InputFile); |
122 | AssignFile(f, InputFile); |
123 | Reset(f); |
123 | Reset(f); |
124 | while not Eof(f) do |
124 | while not Eof(f) do |
125 | begin |
125 | begin |
126 | ReadLn(f, tmp); |
126 | ReadLn(f, tmp); |
127 | result := result + tmp + #13#10; |
127 | result := result + tmp + #13#10; |
128 | end; |
128 | end; |
129 | CloseFile(f); |
129 | CloseFile(f); |
130 | end; |
130 | end; |
131 | 131 | ||
132 | function RemoveLineBreaks(inp: string): string; |
132 | function RemoveLineBreaks(inp: string): string; |
133 | begin |
133 | begin |
134 | inp := StringReplace(inp, #13, '', [rfReplaceAll]); |
134 | inp := StringReplace(inp, #13, '', [rfReplaceAll]); |
135 | inp := StringReplace(inp, #10, '', [rfReplaceAll]); |
135 | inp := StringReplace(inp, #10, '', [rfReplaceAll]); |
136 | result := inp; |
136 | result := inp; |
137 | end; |
137 | end; |
138 | 138 | ||
139 | end. |
139 | end. |
140 | 140 |