...
EDIT
So friend, I ended up seeing uses editing and actually the Notepad++ can’t do!
What’s left for us to do? I created a tool for this and will share with the community! Not only that, that solves the problem and any other similar that may appear with the same sense!
Tool Interface (I took and left the names of the components):
btnListar:
procedure TfrmRemoverReferencias.btnListarClick(Sender: TObject);
begin
mmListaArquivos.Lines.Clear;
//Chamando a função que lista os Arquivos e Subpastas
ListarArquivos(edtDiretorio.Text, chkSub.Checked);
end;
Function to assist in the search of files and identification of empty folders:
function TfrmRemoverReferencias.TemAtributo(Attr, Val: Integer): Boolean;
begin
Result := Attr and Val = Val;
end;
Function that fetches the files from the Folder edtDiretorio
note that I added the edtExtensao
so that you can choose which type will be exclusively listed, we still have the chkSub
an additional that we can use to fetch the subfolders (an extra brightness for our tool):
procedure TfrmRemoverReferencias.ListarArquivos(Diretorio: string; Sub: Boolean);
var
F: TSearchRec;
Ret: Integer;
TempNome: string;
begin
Ret := FindFirst(Diretorio + '\*.'+edtExtensao.Text, faAnyFile, F);
while Ret = 0 do
begin
if TemAtributo(F.Attr, faDirectory) then
begin
if (F.Name <> '.') and
(F.Name <> '..') then
begin
if Sub = True then
begin
TempNome := Diretorio + '\' + F.Name;
ListarArquivos(TempNome, True);
end;
end;
end
else
begin
mmListaArquivos.Lines.Add(Diretorio + '\' + F.Name);
end;
Ret := FindNext(F);
end;
FindClose(F);
end;
Now, in btnCorrigir:
procedure TfrmRemoverReferencias.btnCorrigirClick(Sender: TObject);
var
i,
x,
y,
z,
w,
vIndex,
vTamLoop,
vNLinhas : Integer;
vDados : Array of String;
vArquivoTemp : TStringList;
begin
vArquivoTemp := TStringList.Create;
vArquivoTemp.Clear;
vIndex := 0;
SetLength(vDados, mmFonteDados.Lines.Count);
for i := 0 to Pred(mmFonteDados.Lines.Count) do
vDados[i] := mmFonteDados.Lines.Strings[i];
{Para cada arquivo da Lista...}
for i := 0 to Pred(mmListaArquivos.Lines.Count) do
begin
vArquivoTemp.LoadFromFile(mmListaArquivos.Lines.Strings[i]);
vTamLoop := vArquivoTemp.Count;
for x := 0 to Pred(vTamLoop) do
begin
if (x >= vTamLoop) then
Break;
{... para cada linha da Fonte de pesquisa}
for y := 0 to Pred(mmFonteDados.Lines.Count) do
begin
for z := 0 to Pred(mmFonteDados.Lines.Count) do
begin
if (x + z >= vTamLoop) then
Break;
{... se encontrei a 1ª ocorreência...}
if (Pos(vDados[0+z],vArquivoTemp.Strings[x+z]) > 0) then
Inc(vIndex)
else
vIndex := 0;
end;
{Testando se achei todas as ocorrências}
if (vIndex = mmFonteDados.Lines.Count) then
begin
for w := 0 to Pred(vIndex) do
begin
{Deletando a Linha qie Foi encontrada 4 vezes...
...sim, para esse exemplo vamos deletar 4 linhas...
... faça as implementações necessarias caso queira deletar mais que 4 linhas!
NOTA, lembrando que a qtd de linhas são da variavel vIndex}
vArquivoTemp.Delete(x);
end;
vTamLoop := vTamLoop - vIndex;
vIndex := 0;
{Salvando as Alterações}
vArquivoTemp.SaveToFile(mmListaArquivos.Lines.Strings[i]);
Break;
end;
end;
end;
end;
end;
It is up to each of you to use as you please, observe the :
for w := 0 to Pred(vIndex)
Here I added the internal function of Delphi Delete
, that is, I will delete the entire line, if it is of your choice, just replace it with a procedure that add to that line //
and you’d be commenting on the line instead of erasing, or giving a StringReplace
to exchange information!
Along those lines: vArquivoTemp.SaveToFile(mmListaArquivos.Lines.Strings[i]);
here saved under the original file, to generate a copy just change the [i]
for [i]+'corrigido'
.
Could you have done it without so many ties? Yes, but it would be too long!
I will keep improving it over time! Even a co-worker will already use!
Note that I have not added any Fields validation, now just use your imagination!
I hope it helps!
What do you mean, "inherit"?
– Guill
@Guill heritage is a feature of the POO, in this case it would be the visual heritage of the UI.
– Artur_Indio
Display the code you are using to create the heirs forms?
– Guill
Do you say create in terms of object? Or create the form itself?
– Artur_Indio