Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Coloboración Paypal con ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 12-02-2008
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.142
Poder: 36
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

Propongo algo así, aunque, no sé si te servirá o qué.

Código Delphi [-]
function FileToStr(
 path: string): string;
var
  aFile: TextFile;
begin
  AssignFile(aFile, path);
  Reset(aFile);
  while not Eof(aFile) do
    ReadLn(aFile, result);
  CloseFile(aFile);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  s: string;
  sr: TSearchRec;
begin
  SetCurrentDir(ExtractFileDir(ParamStr(0)));
  if FindFirst('.\*.csv', faAnyFile, sr) = 0 then
  begin
    try
      repeat
        s :=  s + FileToStr('.\' + sr.Name)
      until (FindNext(sr) <> 0);
    finally
      FindClose(sr);
    end;
  end;

  ShowMessage(s);
end;
__________________
David Esperalta
www.decsoftutils.com

Última edición por dec fecha: 12-02-2008 a las 18:59:21.
Responder Con Cita
  #2  
Antiguo 12-02-2008
keyboy keyboy is offline
Miembro
 
Registrado: oct 2004
Posts: 367
Poder: 22
keyboy Va por buen camino
Cita:
Empezado por Albertito
El LoadFromFile o LoadFroamStream del Memo, te machaca el anterior.
Bueno, sí, pero puedes usar un TStringList auxiliar para leer cada archivo (LoadFromFile) y luego usar Memo1.Lines.AddStrings para agregar al memo sin machacar nada.

Bye
Responder Con Cita
  #3  
Antiguo 12-02-2008
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.142
Poder: 36
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

Yo sigo a lo mío...

Código Delphi [-]
function ReadTextFiles(path,
 extension: string): string;

  function FileToStr(
   path: string): string;
  var
    aFile: TextFile;
  begin
    AssignFile(aFile, path);
    Reset(aFile);
    while not Eof(aFile) do
      ReadLn(aFile, result);
    CloseFile(aFile);
  end;

var
  sr: TSearchRec;
begin
  result := EmptyStr;
  path := ExtractFilePath(path);
  if FindFirst(path + extension,
   faAnyFile, sr) = 0 then begin
     try
       repeat
         result := Concat(
           result, FileToStr(path + sr.Name)
         );
       until (FindNext(sr) <> 0);
     finally
       FindClose(sr);
     end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage(
    ReadTextFiles('.\', '*.csv')
  );
end;
__________________
David Esperalta
www.decsoftutils.com

Última edición por dec fecha: 12-02-2008 a las 19:12:33.
Responder Con Cita
  #4  
Antiguo 12-02-2008
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.142
Poder: 36
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

He descubierto que no estaba leyendo de los archivos sino una línea.

Código Delphi [-]
function ReadTextFiles(
 path, mask: string): string;

  function FileToStr(
   path: string): string;
  var
    line: string;
    aFile: TextFile;
  begin
    AssignFile(aFile, path);
    Reset(aFile);
    while not Eof(aFile) do
    begin
      ReadLn(aFile, line);
      result := result + line;
    end;
    CloseFile(aFile);
  end;

var
  sr: TSearchRec;
begin
  result := EmptyStr;
  path := ExtractFilePath(path);
  if FindFirst(path + mask,
   faAnyFile, sr) = 0 then begin
     try
       repeat
         result := result +
          FileToStr(path + sr.Name);
       until (FindNext(sr) <> 0);
     finally
       FindClose(sr);
     end;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Memo1.Text := ReadTextFiles('.\', '*.csv');
end;
__________________
David Esperalta
www.decsoftutils.com

Última edición por dec fecha: 12-02-2008 a las 19:26:09.
Responder Con Cita
  #5  
Antiguo 12-02-2008
keyboy keyboy is offline
Miembro
 
Registrado: oct 2004
Posts: 367
Poder: 22
keyboy Va por buen camino
Cita:
Empezado por dec
Yo sigo a lo mío...
Podemos combinar ideas:

Código Delphi [-]
procedure ReadFiles(Path, Mask: String; Lines: TStrings);
var
  SearchRec: TSearchRec;
  SomeLines: TStringList;
  Result: Integer;

begin
  Path := ExtractFilePath(Path);
  Result := FindFirst(Path + Mask, faAnyFile, SearchRec);

  try
    if Result = 0 then
    begin
      SomeLines := TStringList.Create;

      try
        repeat
          SomeLines.LoadFromFile(Path + SearchRec.Name);
          Lines.AddStrings(SomeLines);

          Result := FindNext(SearchRec);
        until Result <> 0;
      finally
        SomeLines.Free;
      end;
    end;
  finally
    FindClose(SearchRec);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ReadFiles('.\', '*.csv', Memo1.Lines);
end;

Bye
Responder Con Cita
  #6  
Antiguo 12-02-2008
Avatar de dec
dec dec is offline
Moderador
 
Registrado: dic 2004
Ubicación: Alcobendas, Madrid, España
Posts: 13.142
Poder: 36
dec Tiene un aura espectaculardec Tiene un aura espectacular
Hola,

Pues claro que podemos combinar ideas, no faltaba más.

Código Delphi [-]

begin
  Result := _CopyObject('.\', '*.csv');
end;

Je, je, je... No he podido evitarlo.
__________________
David Esperalta
www.decsoftutils.com
Responder Con Cita
  #7  
Antiguo 12-02-2008
[egostar] egostar is offline
Registrado
 
Registrado: feb 2006
Posts: 6.572
Poder: 27
egostar Va camino a la fama
Cita:
Empezado por dec Ver Mensaje
Hola,

Pues claro que podemos combinar ideas, no faltaba más.

Código Delphi [-]
 
begin
   Result := _CopyObject('.\', '*.csv');
end;

Je, je, je... No he podido evitarlo.
Cuidaditoo con esa función, a ver si un día de estos se devela el misterio

Salud OS
__________________
"La forma de empezar es dejar de hablar y empezar a hacerlo." - Walt Disney
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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
Cargar Linea En Varios Items De Un ListBox ZayDun Varios 1 06-06-2007 12:54:13
Cargar la misma imagen en varios QRImage molina669 Gráficos 0 03-11-2006 11:50:17
Cargar texto en un memo pablo OOP 1 03-05-2005 02:20:34
Varios colores en memo? unko! OOP 4 25-03-2005 05:42:55
cargar tabla en varios combos Delphos Conexión con bases de datos 2 04-10-2003 19:09:11


La franja horaria es GMT +2. Ahora son las 19:19:36.


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