-
Notifications
You must be signed in to change notification settings - Fork 1
/
sbaprogramu.pas
159 lines (138 loc) · 4.05 KB
/
sbaprogramu.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
152
153
154
155
156
157
158
unit SBAProgramU;
{$mode objfpc}{$H+}
interface
uses
LCLVersion, Dialogs, Classes, SysUtils, SBAProgContrlrU, ListViewFilterEdit, FileUtil,
LazFileUtils;
const
cSBADefaultPrgName='NewProgram.prg';
cSBADefPrgTemplate='PrgTemplate.prg';
cSBAAdvPrgTemplate='AdvPrgTemplate.prg';
type
{ TSBAProgram }
{ TODO : Mover Variables, propiedades y métodos comunes de TSBAProgram y TSBASnippet al Objeto Ancestro TSBAContrlrProg o bien crear un ancestro intermedio que resuma lo común }
TSBAProgram = class(TSBAContrlrProg)
private
FData: TStrings;
FCode: Tstrings;
FDescription: Tstrings;
FRegisters: Tstrings;
FFilter:TListViewFilterEdit;
procedure AddItemToProgramsFilter(FileIterator: TFileIterator);
procedure Setfilename(AValue: string);
public
constructor Create;
destructor Destroy; override;
function CpyProgDetails(Prog,Src:TStrings):boolean;
function CpyUserProg(Prog,Src:TStrings):boolean;
function CpyProgUReg(Prog,Src:TStrings):boolean;
procedure UpdateProgramsFilter(Filter: TListViewFilterEdit);
published
property Filename:string read Ffilename write Setfilename;
property Code:Tstrings read Fcode;
property Description: Tstrings read Fdescription;
property Registers: Tstrings read FRegisters;
end;
implementation
uses ConfigFormU,UtilsU;
{ TSBAProgram }
procedure TSBAProgram.Setfilename(AValue: string);
begin
if Ffilename=AValue then Exit;
try
FData.LoadFromFile(AValue);
except
showmessage('Code Program could not be loaded');
exit;
end;
CpyUserProg(FData,FCode);
CpyProgDetails(FData,FDescription);
CpyProgUReg(FData,FRegisters);
Ffilename:=AValue;
end;
constructor TSBAProgram.Create;
begin
inherited Create;
FFileName:=cSBADefaultPrgName;
FData:=TStringList.Create;
FCode:=TStringList.Create;
FDescription:=TStringList.Create;
FRegisters:=TStringList.Create;
end;
destructor TSBAProgram.Destroy;
begin
if assigned(FData) then FreeAndNil(FData);
if assigned(FCode) then FreeAndNil(FCode);
if assigned(FRegisters) then FreeAndNil(FRegisters);
if assigned(FDescription) then FreeAndNil(FDescription);
inherited Destroy;
end;
function TSBAProgram.CpyProgDetails(Prog, Src: TStrings): boolean;
Var I:Integer;
begin
Src.Clear;
Src.Add(cSBAStartProgDetails);
Src.Add(cSBAEndProgDetails);
Result:=inherited CpyProgDetails(Prog, Src);
If Src.Count>1 then
begin
Src.Delete(0);
Src.Delete(Src.Count-1);
for I:=0 to Src.count-1 do Src[i]:=Trim(Copy(Src[i],3,1000)); //remove extra comments "--"
end;
end;
function TSBAProgram.CpyUserProg(Prog, Src: TStrings): boolean;
begin
Src.Clear;
Src.Add(cSBAStartUserProg);
Src.Add(cSBAEndUserProg);
Result:=inherited CpyUserProg(Prog, Src);
If Src.Count>1 then
begin
Src.Delete(0);
Src.Delete(Src.Count-1);
end;
end;
function TSBAProgram.CpyProgUReg(Prog, Src: TStrings): boolean;
begin
Src.Clear;
Src.Add(cSBAStartProgUReg);
Src.Add(cSBAEndProgUReg);
Result:=inherited CpyProgUReg(Prog, Src);
If Src.Count>1 then
begin
Src.Delete(0);
Src.Delete(Src.Count-1);
end;
end;
{$if (lcl_fullversion >= 1070000)}
procedure TSBAProgram.AddItemToProgramsFilter(FileIterator: TFileIterator);
var
Data:TListViewDataItem;
begin
Data.Data := nil;
SetLength(Data.StringArray,2);
Data.StringArray[0]:=ExtractFileNameWithoutExt(FileIterator.FileInfo.Name);
Data.StringArray[1]:=AppendPathDelim(FileIterator.Path)+FileIterator.FileInfo.Name;
FFilter.Items.Add(Data);
end;
{$ELSE}
procedure TSBAProgram.AddItemToProgramsFilter(FileIterator: TFileIterator);
var
Data:TStringArray;
begin
SetLength(Data,2);
Data[0]:=ExtractFileNameWithoutExt(FileIterator.FileInfo.Name);
Data[1]:=AppendPathDelim(FileIterator.Path)+FileIterator.FileInfo.Name;
FFilter.Items.Add(Data);
end;
{$ENDIF}
procedure TSBAProgram.UpdateProgramsFilter(Filter:TListViewFilterEdit);
begin
FFilter:=Filter;
FFilter.Items.Clear;
SearchForFiles(ProgramsDir,'*.prg',@AddItemToProgramsFilter);
SearchForFiles(LibraryDir,'*.prg',@AddItemToProgramsFilter);
FFilter.InvalidateFilter;
end;
end.