Erro com lista de string

06/10/2011

0

Está dando erro de access violation, quando vou encher minha lista. Abaixo meu código.
Pjava

Pjava

Responder

Posts

06/10/2011

Pjava

meu código
procedure TFileFinder.Start;
  procedure PathFound(const Path: string);
  var
    Dir,texto,txt1,txt2: string;
    Mask: string;
    SR: TSearchRec;
    erro,posicao,i:integer;
    Lista:TList<String>
    nome,novo_nome,s: String;
  begin
    if Assigned(Lista) then
      Lista := TList<string>.Create();

    Dir := IncludeTrailingPathDelimiter(Path);
    if not AceitarDirectory(Dir) then
      Exit;

    // Procura os arquivos
    Mask := Dir + *.*;
    if Active and (FindFirst(Mask, faAnyFile - faDirectory, SR) = 0) then
      try
        //fNextDir := false;

        repeat
          inc(cont);
          texto := -+StrZero(cont,4);
          nome := Copy(SR.Name,1,Length(SR.Name)- 4);
          //Vai copiar os arquivos do primeiro dir q encontra, q pode ser pdf,txt ou tif
          if muda = 0 then
          begin
            Lista.AddRange([nome]);
            txt1 := Dir + SR.Name;
            Insert(texto,SR.Name,21);
            txt2 := Dir + SR.Name;
          end
          else
          begin
            //passa a colocar o sequenciador de acordo com o nome do arquivo já existente na lista se é ou não igual
            for i := 0 to Lista.Count - 1 do
            begin
              novo_nome := Copy(SR.Name,1,Length(SR.Name)- 4);
              if novo_nome = Lista.Items[i] then
                txt1 := Dir + novo_nome;
                Insert(texto,novo_nome,21);
                txt2 := Dir + novo_nome;
            end;
          end;
          //Para renomear um arquivo, é necessário passar o path completo
          RenameFile(txt1,txt2);
          (*if(txt1 = txt2) then
            ShowMessage(txt1 é igual a txt2);
          if RenameFile(txt1,txt2) then
            ShowMessage(Renomeou corretemente  + txt1 +  a  + txt2)
          else
          begin
            erro := GetLastError;
            ShowMessage(Erro:  + IntToStr(erro)+   +SysErrorMessage(erro)+. Renomeando +txt2+ a +txt1);
          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);
            posicao := (Pos(PDF,SR.Name)) or (Pos(TIF,SR.Name))or (Pos(TXT,SR.Name));
            if posicao > 0 then
              cont := 0;
              inc(muda);
          end;
        until (FindNext(SR) <> 0) or (not Active);
      finally
        FindClose(SR);
      end;
  end;

begin
  PathFound(fStartPath);
  Active := false;
end;
Responder

Assista grátis a nossa aula inaugural

Assitir aula

Saiba por que programar é uma questão de
sobrevivência e como aprender sem riscos

Assistir agora

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar