-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFixAccess.dpr
More file actions
113 lines (97 loc) · 2.89 KB
/
FixAccess.dpr
File metadata and controls
113 lines (97 loc) · 2.89 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
107
108
109
110
111
112
113
program FixAccess;
{$APPTYPE CONSOLE}
uses
System.SysUtils,
System.Classes,
System.IOUtils;
var
FileContent: TStringList;
FilePath: string;
FixedContent: string;
SourceFile, TargetFile: string;
BackupFile: string;
i: Integer;
ClearAllDataIndex: Integer;
FoundBegin: Boolean;
InsertIndex: Integer;
begin
try
WriteLn('ConfigBuild 访问违规修复工具');
WriteLn('------------------------------');
// 检查ViewBuildConfig.pas文件
SourceFile := 'ViewBuildConfig.pas';
if not FileExists(SourceFile) then
begin
WriteLn('错误: 源文件 ' + SourceFile + ' 不存在');
Exit;
end;
// 创建备份
BackupFile := 'ViewBuildConfig.pas.bak';
if not FileExists(BackupFile) then
begin
TFile.Copy(SourceFile, BackupFile);
WriteLn('已创建备份: ' + BackupFile);
end;
// 读取文件内容
FileContent := TStringList.Create;
try
FileContent.LoadFromFile(SourceFile);
// 查找ClearAllData方法并修复
ClearAllDataIndex := -1;
for i := 0 to FileContent.Count - 1 do
begin
if Pos('procedure TFrmBuildConfig.ClearAllData', FileContent[i]) > 0 then
begin
ClearAllDataIndex := i;
Break;
end;
end;
if ClearAllDataIndex >= 0 then
begin
// 在循环开始前添加有效性检查
FoundBegin := False;
InsertIndex := -1;
for i := ClearAllDataIndex to FileContent.Count - 1 do
begin
if (not FoundBegin) and (Pos('begin', FileContent[i]) > 0) then
begin
FoundBegin := True;
continue;
end;
if FoundBegin and (Pos('for i := 0 to tvJSON.Items.Count - 1 do', FileContent[i]) > 0) then
begin
InsertIndex := i;
Break;
end;
end;
if InsertIndex > 0 then
begin
// 插入安全检查代码
FileContent.Insert(InsertIndex, ' // 添加安全检查');
FileContent.Insert(InsertIndex + 1, ' if not Assigned(tvJSON) or (tvJSON.Items.Count = 0) then Exit;');
FileContent.Insert(InsertIndex + 2, '');
WriteLn('已修复 ClearAllData 方法');
// 保存修改后的文件
FileContent.SaveToFile(SourceFile);
WriteLn('已保存修复后的文件');
end
else
begin
WriteLn('警告: 无法定位ClearAllData方法中的循环');
end;
end
else
begin
WriteLn('警告: 未找到ClearAllData方法');
end;
WriteLn('完成。请重新编译项目以应用修复。');
finally
FileContent.Free;
end;
WriteLn('按任意键退出...');
ReadLn;
except
on E: Exception do
WriteLn('错误: ', E.ClassName, ': ', E.Message);
end;
end.