forked from brian-scott-andrews/TurboRisk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Programs.pas
151 lines (134 loc) · 3.44 KB
/
Programs.pas
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
unit Programs;
{$MODE Delphi}
interface
uses
LCLIntf, LCLType, LMessages, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, CheckLst, Buttons;
type
TfPrograms = class(TForm)
Label1: TLabel;
txtPrgDesc: TMemo;
Label2: TLabel;
lstPrgFile: TCheckListBox;
cmdOK: TBitBtn;
cmdAnnulla: TBitBtn;
function strTran(ctext, cfor, cwith: string): string;
procedure FormShow(Sender: TObject);
procedure lstPrgFileClickCheck(Sender: TObject);
procedure lstPrgFileClick(Sender: TObject);
procedure cmdOKClick(Sender: TObject);
procedure cmdCancel(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
fPrograms: TfPrograms;
implementation
{$R *.lfm}
uses {StdPas,} Players, Globals;
{ Character by Character String Replacement }
function TfPrograms.strTran(ctext, cfor, cwith: string): string;
var
ntemp : word ;
nreplen: word ;
begin
cfor := upperCase(cfor) ;
nreplen := length(cfor) ;
for ntemp := 1 to length(ctext) do begin
if (upperCase(copy(ctext, ntemp, nreplen)) = cfor) then
begin
delete(ctext, ntemp, nreplen);
insert(cwith, ctext, ntemp);
end;
end;
result := ctext;
end;
procedure TfPrograms.FormShow(Sender: TObject);
var
rFileDesc: TSearchRec;
i: integer;
begin
// load program list
lstPrgFile.Items.Clear;
if FindFirst(sG_AppPath+'players'+PathDelim+'*.trp', faAnyFile, rFileDesc) = 0 then begin
repeat
lstPrgFile.Items.Add(rFileDesc.Name);
until FindNext(rFileDesc) <> 0;
FindClose(rFileDesc);
end;
// select current program, if any
i := lstPrgFile.Items.IndexOf(fPlayers.cboPrgFile.Text);
if i>=0 then begin
lstPrgFile.ItemIndex:=i;
lstPrgFile.Checked[i] := true;
lstPrgFileClick(Sender);
end;
end;
procedure TfPrograms.lstPrgFileClickCheck(Sender: TObject);
var
i, j: integer;
begin
// uncheck all other items
j := lstPrgFile.ItemIndex;
if lstPrgFile.Checked[j] then begin
for i:=0 to lstPrgFile.Items.Count-1 do begin
if i<>j then lstPrgFile.Checked[i] := false;
end;
end;
end;
procedure TfPrograms.lstPrgFileClick(Sender: TObject);
var
fTRP: textfile;
sLine: string;
bComment: boolean;
i: integer;
begin
if lstPrgFile.ItemIndex<0 then exit;
txtPrgDesc.Clear;
AssignFile(fTRP,sG_AppPath+'players'+PathDelim+lstPrgFile.Items[lstPrgFile.ItemIndex]);
Reset(fTRP);
try
// read initial comment delimited by { and }
bComment := false;
while not Eof(fTRP) do begin
Readln(fTRP,sLine);
// search for begin of comment
if not bComment then begin
i := pos('{',sLine);
if i>0 then begin
sLine := StrTran(sLine,'{','');
bComment := true;
if trim(sLine)='' then continue;
end;
end;
// copy comment into control
if bComment then begin
i := pos('}',sLine);
if i>0 then sLine := StrTran(sLine,'}','');
txtPrgDesc.Lines.Add(sLine);
if i>0 then break;
end;
end;
finally
CloseFile(fTRP);
end;
end;
procedure TfPrograms.cmdOKClick(Sender: TObject);
var
i: integer;
begin
for i:=0 to lstPrgFile.Items.Count-1 do begin
if lstPrgFile.Checked[i] then begin
fPlayers.cboPrgFile.Text := lstPrgFile.Items[i];
break;
end;
end;
ModalResult := mrOK;
end;
procedure TfPrograms.cmdCancel(Sender: TObject);
begin
ModalResult := mrCancel;
end;
end.