BCS Mass Links (Global Changes)


There are those time when source code files require changes of a specific occurrence of datum from one value to a new value.
This component accomplishes that goal by employing sub directory selection and file specification via a specified extension.
Once the file for modification are identifies simple click on the Update Files menu item and the designated changes are applied in every occurrence.
The files selection is made by the following code.
[codesyntax lang=”delphi”]

{*-----------------------------------------------------------------------------
 Procedure: LoadFiles1Click
 Date:      29-Dec-2013
 @Param     Sender: TObject
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSMassLinkC.LoadFiles1Click(Sender: TObject);
begin
  BCSXE3UtilsCmp1.PopulateListBox
    (BCSXE3UtilsCmp1.GetFileNames(BCSXE3UtilsCmp1.SelADir, '*.htm'),
    BCSXE3UtilsCmp1.FilLen, ListBox1);
end;

[/codesyntax]
Of course the above procedure is executed when the Load Files menu item is clicked.
The global or mass changes are invoked by the snippet below.
[codesyntax lang=”delphi”]

{*-----------------------------------------------------------------------------
 Procedure: UpdateFiles1Click
 Date:      29-Dec-2013
 @Param     Sender: TObject
 @Return    None
 -----------------------------------------------------------------------------}
procedure TBCSMassLinkC.UpdateFiles1Click(Sender: TObject);
var
  j: Integer;
begin
  i := 0;
  repeat
    sc.LoadFromFile(ListBox1.Items[i]);
    j := 0;
    repeat
      buf := sc[j];
      buf := StringReplace(buf,
        'Created with DelphiCodeToDoc. To obtain the latest revision, please visit ',
        'Please Visit The Brooks Computing Systems, LLC Web Site. ',
        [rfreplaceAll]);
      buf := StringReplace(buf, 'http://dephicodetodoc.sourceforge.net',
        'http://bcsjava.com', [rfreplaceAll]);
      sc[j] := buf;
      Inc(j);
    until j > sc.Count - 1;
    sc.SaveToFile(ListBox1.Items[i]);
    Inc(i);
  until i > ListBox1.Items.Count - 1;
  // ModalResult := mrOk;
  Close;
end;

[/codesyntax]
Any possible combination of changes are available simply by including or modifying StringReplace statements.  As always there are many variations of how to make things work more efficiently but in our example I intended to use the KISS methodology.
The component documentation for this component may be found here.  http://archbrooks.com/compdoc/BCSMassLink/html/BCS%20Mass%20Link%20Global%20Changes.htm
The source code for this project may be located here.  http://cc.embarcadero.com/item/29680
Mr. Arch Brooks, Software Engineer, Brooks Computing Systems, LLC authored this article.

Leave a Reply

Your email address will not be published. Required fields are marked *