Delphi 如何从 exe 中的 dfm 中删除已删除的属性
Delphi how to remove deleted properties from dfm in exe
我有很多dfms。我正在使用从此站点 Delphi DFM properties remover 删除不需要的属性 exe 来删除不再需要的已删除属性。下面的代码工作正常,除了一些属性,比如如果我想删除名称为 Prop
的 属性,然后它会删除名称为 SecondProp
的另一个 属性 和 Prop
。 mPropList 在新行中包含每个 属性,例如
提案1
提案2
第二道具
支持
我怀疑以下代码:
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;
我们确定:
- 您的
mPropList.Lines
每个都包含类似 Prop =[...]
或 SecondProp =[...]
的内容,并且 属性 名称始终作为行首。
LResult
保留应保留的行。因此,如果字符串匹配,您不想添加,但如果它们 不. ,您 do
将这些放在一起,你想做 LResult.Add()
只有 StrIPos(...) <> 1
。这样,您添加
- 行不包含 属性 名称(
StrIPos() == 0
,即 < 1
)和
- 包含它作为子字符串但不在开头的行,即仅在 另一个 属性 名称 (
StrIPos > 1
).[=35= 中]
固定代码如下所示:
if StrIPos(mPropList.Lines[K] + ' =', S) <> 1 then
begin
LResult.Add(LSource[J]);
continue;
end;
我有很多dfms。我正在使用从此站点 Delphi DFM properties remover 删除不需要的属性 exe 来删除不再需要的已删除属性。下面的代码工作正常,除了一些属性,比如如果我想删除名称为 Prop
的 属性,然后它会删除名称为 SecondProp
的另一个 属性 和 Prop
。 mPropList 在新行中包含每个 属性,例如
提案1
提案2
第二道具
支持
我怀疑以下代码:
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;
我们确定:
- 您的
mPropList.Lines
每个都包含类似Prop =[...]
或SecondProp =[...]
的内容,并且 属性 名称始终作为行首。 LResult
保留应保留的行。因此,如果字符串匹配,您不想添加,但如果它们 不. ,您 do
将这些放在一起,你想做 LResult.Add()
只有 StrIPos(...) <> 1
。这样,您添加
- 行不包含 属性 名称(
StrIPos() == 0
,即< 1
)和 - 包含它作为子字符串但不在开头的行,即仅在 另一个 属性 名称 (
StrIPos > 1
).[=35= 中]
固定代码如下所示:
if StrIPos(mPropList.Lines[K] + ' =', S) <> 1 then
begin
LResult.Add(LSource[J]);
continue;
end;