Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-10-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
Poder: 21
Paulao Va por buen camino
Problemas con TList<String>

Señores, buenos dias. El que poasa es que mi aplicacion me lo da error de Access Violation quando yo intento llenar la lista con archivo. Vea abajo mi unit y mi codigo.

Código Delphi [-]
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]);//Acá me lo da el error
            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 Con Cita
  #2  
Antiguo 06-10-2011
Avatar de newtron
[newtron] newtron is offline
Membrillo Premium
 
Registrado: abr 2007
Ubicación: Motril, Granada
Posts: 3.471
Poder: 21
newtron Va camino a la fama
Hola.

Si no me equivoco el problema que estás teniendo es que no estás inicializando la lista, así que tendrías que cambiar esto:

Código Delphi [-]
if Assigned(Lista) then
   Lista := TList<string>.Create();

por esto:

Código Delphi [-]
if not Assigned(Lista) then
    Lista := TList<string>.Create();

y ya puestos, al final deberías liberarla con un free:

Código Delphi [-]
Lista.free;

Saludos
__________________
Be water my friend.
Responder Con Cita
  #3  
Antiguo 09-10-2011
Avatar de Ñuño Martínez
Ñuño Martínez Ñuño Martínez is offline
Moderador
 
Registrado: jul 2006
Ubicación: Ciudad Catedral, Españistán
Posts: 6.000
Poder: 25
Ñuño Martínez Tiene un aura espectacularÑuño Martínez Tiene un aura espectacular
Y digo yo, ¿Por qué no usas TStringList?
__________________
Proyectos actuales --> Allegro 5 Pascal ¡y Delphi!|MinGRo Game Engine
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Problemas con el Ampersand en un String cslbcn OOP 2 22-07-2010 22:25:06
Problemas con TList air_erik OOP 9 09-02-2008 22:49:27
Problemas con String y BORLNDMM nax Varios 4 26-08-2005 12:31:26
Problemas con TList arantzal .NET 2 09-12-2004 09:14:37
TList HERNAN Varios 2 10-10-2003 03:47:59


La franja horaria es GMT +2. Ahora son las 02:56:58.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi