How to remove all references from deleted forms of the parent form?

3

I have my generic form and I have several others that visually inherit their components. When I delete a component in the parent form and open an heir I get this message:

I can click OK and confirm that the component has been deleted, but I will have to do it in more than 50 forms.

Is there any way to give a clean on all other forms automatically? It would have a batch editor that could replace or remove the expression, for example:

inherited dxLayoutControl1Group2: TdxLayoutAutoCreatedGroup
  Index = 0
  AutoCreated = True
end
    
asked by anonymous 14.01.2016 / 04:37

1 answer

2

... EDIT

So, my friend, I ended up using editing and really NotePad ++ can not do it!

What is left for us to do? I've created a tool for this and I'll share it with the community ! Not only that, it solves the problem and any other similar that can appear with the same sense!

Tool Interface (I took advantage of 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 searching for files and identifying empty folders:

function TfrmRemoverReferencias.TemAtributo(Attr, Val: Integer): Boolean;
begin
  Result := Attr and Val = Val;
end;

Function that will fetch the files of the folder Informed in edtDiretorio Note that I have added the edtExtensao so that you can choose which type will be exclusively listed, we still have the chkSub an additional one that we can use to search 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, do not btnCorrect:

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 you to use as you see fit, note the following:

for w := 0 to Pred(vIndex)

Here I added the internal function of Delphi Delete , that is, I will delete the whole line, if it is of your choice, just replace it with a procedure that adds to that line // and you would be commenting the line to instead of deleting, or giving StringReplace to exchange information!

In this line: vArquivoTemp.SaveToFile(mmListaArquivos.Lines.Strings[i]); here saved under the original file, to generate a copy just change [i] to [i]+'corrigido' .

Could you have done it without so many ties? Yes, but it would be too long! I will continue to improve it with passing of time! Even a co-worker will already use it!

Please note that I have not added any Fields validation, now just use your imagination!

I hope it helps!

    
14.01.2016 / 23:44