Ver Mensaje Individual
  #1  
Antiguo 06-07-2011
Paulao Paulao is offline
Miembro
 
Registrado: sep 2003
Ubicación: Rua D 31 Casa 1 - Inhoaíba - Rio de Janeiro - RJ - Brasil
Posts: 637
Reputación: 21
Paulao Va por buen camino
StringReplace no funciona

Mira, hizo una function para hacer un replace en algunos registros. Que pasa es que quando pongo un Break Point, si funciona, pero quando termina todo el proceso y me voy a la carpeta para ver los archivos, no funcionó, o sea, queda del la mismo forma como estava antes. Abajo mis codigos.

Código Delphi [-]
interface
 
uses Generics.Collections;
 
type
  TFileFoundEvent = procedure(Sender: TObject; const FileName: string) of object;
  TDirectoryFoundEvent = procedure(Sender: TObject; const FileName: string; var Aceitar: Boolean) of object;
 
  TFileFinder = class
  private
    fRecursive: Boolean;
    fOnFile: TFileFoundEvent;
    fFileMask: string;
    fOnDirectory: TDirectoryFoundEvent;
    fStartPath: string;
    fActive: Boolean;
    fNextDir: Boolean;
    fOnDir: string;
    fLista: TList<String>;
    fNomeArq: String;
  private
    procedure SetActive(const Value: Boolean);
    procedure SetStartPath(const Value: string);
  private
    function AceitarDirectory(const FileName: string): Boolean;
    procedure AceitarFile(const FileName: string);
    procedure Start;
    function TrocaNome(const texto: string):string;
  public
    constructor Create;
    procedure NextDirectory;
    property Active: Boolean read fActive write SetActive;
    property StartPath: string read fStartPath write SetStartPath;
    property Recursive: Boolean read fRecursive write fRecursive;
    property FileMask: string read fFileMask write fFileMask;
    property OnDirectory: TDirectoryFoundEvent read fOnDirectory
      write fOnDirectory;
    property OnFile: TFileFoundEvent read fOnFile write fOnFile;
    property OnDir: string read fOnDir write fOnDir;
    property ListaArquivo: TList<String> read fLista write fLista;
    property NomeArq: String read fNomeArq write fNomeArq;
  end;
 
implementation
 
uses SysUtils;
 
{ TFileFinder }
 
function TFileFinder.AceitarDirectory(const FileName: string): Boolean;
begin
  Result := Active;
  if Result and Assigned(OnDirectory) then
    OnDirectory(self, FileName, Result);
end;
 
procedure TFileFinder.AceitarFile(const FileName: string);
begin
  if Active and Assigned(OnFile) then
    OnFile(self, FileName);
end;
 
constructor TFileFinder.Create;
begin
  inherited Create;
  Recursive := true;
end;
 
procedure TFileFinder.NextDirectory;
begin
  fNextDir := true;
end;
 
procedure TFileFinder.SetActive(const Value: Boolean);
begin
  if fActive <> Value then
  begin
    fActive := Value and DirectoryExists(StartPath);
    if fActive then
      Start;
  end;
end;
 
procedure TFileFinder.SetStartPath(const Value: string);
begin
  fStartPath := IncludeTrailingPathDelimiter(Value);
end;
 
procedure TFileFinder.Start;
  procedure PathFound(const Path: string);
  var
    Dir: string;
    Mask: string;
    SR: TSearchRec;
    List: TList<String>;
    I,c: Integer;
  begin
    if Assigned(List) then
      List := TList<String>.Create();
 
    Dir := IncludeTrailingPathDelimiter(Path);
    if not AceitarDirectory(Dir) then
      Exit;
 
    // Procura os arquivos
    Mask := Dir + FileMask;
    if Active and (FindFirst(Mask, faAnyFile - faDirectory, SR) = 0) then
      try
        //fNextDir := false;
        repeat
          List.AddRange([SR.Name]);
          List.Sort;
          for I := 0 to List.Count - 1 do
          begin
            AceitarFile(Dir + List[i]{SR.Name});
          end;
        until (FindNext(SR) <> 0) or (not Active);// or fNextDir;
 
      finally
        FindClose(SR);
      end;
 
    // Percorre a arvore de diretórios
    Mask := Dir + '*.*';
    OnDir := Mask;
    if Active and Recursive and (FindFirst(Mask, faDirectory, SR) = 0) then
      try
        repeat
          if (SR.Name <> '.') and (SR.Name <> '..') then
          begin
            PathFound(Dir + SR.Name);
            if ExtractFileName(SR.Name) <> '' then
              TrocaNome(SR.Name); //LLama la funcion para renombrar
          end;
        until (FindNext(SR) <> 0) or (not Active);
      finally
        FindClose(SR);
      end;
  end;
 
begin
  PathFound(fStartPath);
  Active := false;
end;
 
function TFileFinder.TrocaNome(const texto: string): string;
var
  s:string;
begin
  s := StringReplace(Texto,'NA','NAC',[rfReplaceAll]);
  Result := StringReplace(s,'Notícia','NOT',[rfReplaceAll]);
end;
 
end.

Última edición por Casimiro Notevi fecha: 06-07-2011 a las 20:14:26.
Responder Con Cita