我有很多 dfms。我正在使用此站点Delphi DFM properties remover中删除不需要的属性 exe来删除不再需要的已删除属性。以下代码可以正常工作,除了某些属性,例如如果我想删除带有名称的属性,Prop
那么它会删除另一个带有名称的属性SecondProp
以及Prop
. mPropList 包含新行上的每个属性,例如 Prop1 Prop2 SecondProp Propn
我怀疑以下代码:
if StrIPos(mPropList.Lines[K] + ' =', S) = 0 then
begin
LResult.Add(LSource[J]);
continue;
end;
SecondProp
在这种情况下如何跳过?
我试过这个
if mPropList.Lines[K] = S then
begin
LResult.Add(LSource[J]);
continue;
end;
匹配精确的字符串,但它不起作用。
这是删除按钮代码
procedure TfrmDeleteProp_MainForm.Button2Click(Sender: TObject);
var
LFile, LSource, LResult: TStringList;
I, J, K, Processed, WasError, Removed: Integer;
SkipPropData: Boolean;
FLOpt: TFileListOptions;
S: String;
begin
LFile := TStringList.Create;
LSource := TStringList.Create;
LResult := TStringList.Create;
try
if chbxSubFolders.Checked then
FLOpt := [flFullNames, flRecursive]
else
FLOpt := [flFullNames];
if not AdvBuildFileList(IncludeTrailingBackslash(edPath.Text) + '*.DFM', faAnyFile, LFile, FLOpt) then
begin
MessageBox(Handle,
'Invalid path specified. Can not process.',
'Warning',
MB_OK or MB_ICONEXCLAMATION);
exit;
end;
Processed := 0;
WasError := 0;
for I := 0 to LFile.Count - 1 do
begin
LSource.LoadFromFile(LFile[I]);
Removed := 0;
for K := 0 to mPropList.Lines.Count - 1 do
begin
if K > 0 then
LSource.Assign(LResult);
if Trim(mPropList.Lines[K]) = '' then
continue;
LResult.Clear;
SkipPropData := False;
for J := 0 to LSource.Count - 1 do
begin
S := Trim(LSource[J]);
if SkipPropData then
begin
if (S > '') and (S[Length(S)] in [')', '}']) then
SkipPropData := False;
continue;
end;
if StrIPos(mPropList.Lines[K] + ' =', S) = 0 then
begin
LResult.Add(LSource[J]);
continue;
end;
if (S > '') and (S[Length(S)] in ['(', '{']) then
SkipPropData := True;
Removed := Removed + 1;
end;
end;
if Removed > 0 then
begin
if RenameFile(LFile[I], ChangeFileExt(LFile[I], '.BAK')) then
begin
LResult.SaveToFile(LFile[I]);
Processed := Processed + 1;
end else
begin
MessageBox(Handle,
PChar('Can not create back up copy for file: ' + LFile[I] + #13#10'File is not processed.'),
'Warning',
MB_OK or MB_ICONEXCLAMATION);
WasError := WasError + 1;
end;
end;
end;
MessageBox(Handle,
PChar(Format('Total files found: %d'#13#10'Properties were removed from: %d'#13#10'Error files: %d',
[LFile.Count, Processed, WasError])),
'Statistics',
MB_OK or MB_ICONINFORMATION);
finally
LFile.Free;
LSource.Free;
LResult.Free;
end;
end;