-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMisc.pas
More file actions
106 lines (90 loc) · 2.68 KB
/
Copy pathMisc.pas
File metadata and controls
106 lines (90 loc) · 2.68 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
unit Misc;
interface
uses SysUtils, VCL.Forms;
function GetSetting(FieldName, Settings: String): String;
function GetBooleanSetting(FieldName, Settings: String): Boolean;
function MyStrToFloat(Value: String; Default: Double = 0.0): Double;
function GetCommandLineParameter(ParameterName: String; var Value: String): Boolean;
procedure WriteToLogFile(Section, Item, Msg: String; Suffix: String = ': ');
const
MAX_PAYLOADS = 100;
HAB_BASE = 'HAB Base';
HAB_BASE_VERSION = 'V1.7.10';
implementation
function GetSetting(FieldName, Settings: String): String;
var
Position: Integer;
Temp: String;
begin
Settings := ';' + Settings;
Position := Pos(';' + FieldName + '=', Settings);
if Position > 0 then begin
Temp := Copy(Settings, Position + Length(FieldName) + 2, 99);
Position := Pos(';', Temp);
if Position > 0 then begin
Result := Copy(Temp, 1, Position-1);
end else begin
Result := Temp;
end;
end else begin
Result := '';
end;
end;
function GetBooleanSetting(FieldName, Settings: String): Boolean;
var
Temp: String;
begin
Temp := GetSetting(FieldName, Settings);
Result := Pos('T', Temp) > 0;
end;
function MyStrToFloat(Value: String; Default: Double = 0.0): Double;
begin
if FormatSettings.DecimalSeparator <> '.' then begin
Value := StringReplace(Value, '.', FormatSettings.DecimalSeparator, []);
end;
try
Result := StrToFloat(Value); // , LFormat);
except
Result := Default;
end;
end;
function GetCommandLineParameter(ParameterName: String; var Value: String): Boolean;
var
i, Len: Integer;
begin
Value := '';
Len := Length(ParameterName) + 1;
ParameterName := UpperCase(ParameterName);
for i := 1 to ParamCount do begin
if ParameterName = UpperCase(ParamStr(i)) then begin
Result := True;
Exit;
end else if Copy(ParamStr(i), 1, Len) = (ParameterName + '=') then begin
Result := True;
Value := Copy(ParamStr(i), Len+1, 99);
Exit;
end;
end;
Result := False;
end;
procedure WriteToLogFile(Section, Item, Msg: String; Suffix: String = ': ');
var
F: TextFile;
Folder, FileName: String;
begin
Folder := ExtractFilePath(Application.ExeName) + '\' + Section;
FileName := Folder + '\' + Item + '.log';
try
AssignFile(F, FileName);
if FileExists(FileName) then begin
Append(F);
end else begin
ForceDirectories(Folder);
ReWrite(F);
end;
WriteLn(F, FormatDateTime('yyyy-mm-dd hh:nn:ss', Now), Suffix, Msg);
CloseFile(F);
except
end;
end;
end.