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

Asked

Viewed 1,080 times

3

I have my generic form and I have several others who have visually inherited its components. When I delete a component in the form father and open a heir get that message:

inserir a descrição da imagem aqui

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

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

inherited dxLayoutControl1Group2: TdxLayoutAutoCreatedGroup
  Index = 0
  AutoCreated = True
end
  • What do you mean, "inherit"?

  • 1

    @Guill heritage is a feature of the POO, in this case it would be the visual heritage of the UI.

  • Display the code you are using to create the heirs forms?

  • Do you say create in terms of object? Or create the form itself?

1 answer

2


... 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):

inserir a descrição da imagem aqui

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!

  • but how I give a replace on something like a type Component inherited dxLayoutControl1Group2: TdxLayoutAutoCreatedGroup&#xA; Index = 0&#xA; AutoCreated = True&#xA; end, that is to be exactly this expression

  • 1

    @Artur_indio then... The mentioned text editor looks for and finds this expression easily.

  • It works the same way as ordinary Notepad, I can’t replace an expression of a component, please see my edition.

  • @Artur_indio So friend, following edition of the answer, let’s go to the tests!

  • I’ll look and give you an answer, right there.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.