Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Coloboración Paypal con ClubDelphi

 
 
Herramientas Buscar en Tema Desplegado
  #3  
Antiguo 17-06-2008
Avatar de GaaK
GaaK GaaK is offline
Miembro
 
Registrado: oct 2005
Ubicación: Trujillo - Peru
Posts: 31
Poder: 0
GaaK Va por buen camino
Cita:
Empezado por coso Ver Mensaje
deberías usar recursividad...
Gracias, me inspiré en su idea y escribí el siguiente código (requiere: Form1, OpenDialog1, Button1):
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    OpenDialog1: TOpenDialog;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

function LeerArchivo(namefile: String; destino: TStringList): Boolean;

var
  Form1: TForm1;
  sPath: String;

implementation

{$R *.dfm}

procedure ParseToken(tok: String; destino: TStringList);
begin
  tok := TrimLeft(tok);
  if (Pos('INCLUDE',tok)<>0) then begin
    { tok := 'INCLUDE "Archivo2.txt"' }
    Delete(tok, 1, 7); { 'INCLUDE' contains 7 chars }
    tok := TrimLeft(tok);
    { tok := '"Archivo2.txt"' }
    tok := AnsiDequotedStr(tok, '"');
    { tok := 'Archivo2.txt' }
    LeerArchivo(sPath+tok, destino);
  end
  else destino.Add(tok);
end;

function LeerArchivo(namefile: String; destino: TStringList): Boolean;
var
  st: TStringList;
  i, r: Longint;
  tok: String;
begin
  st := TStringList.Create;

  st.LoadFromFile(namefile);
  r := st.Count;
  for i:=0 to r-1 do begin
    tok := st[i];
    ParseToken(tok, destino);
  end;

  st.Free;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  dest: TStringList;
begin
  dest := TStringList.Create;
  if OpenDialog1.Execute then begin
    sPath := ExtractFilePath(OpenDialog1.FileName);
    LeerArchivo(OpenDialog1.FileName, dest);
    dest.SaveToFile('ArchivoFinal.txt');
  end;
  dest.Free;
end;

end.
... para hacerlo funcionar, clic en el botón y elegir "Archivo1.txt" (mencionado arriba) y auto se creará "ArchivoFinal.txt" con todas las líneas de los INCLUDE.

Ahora, con esta misma idea no sería mejor hacerlo directamente con AssignFile etc etc?... Digo esto porque lo de crear StringList me parece consumo de memoria y tiempo?... (imaginando archivos de texto de tamaño medio ~200KB).

Iluminarme si me equivoco.

Gracias de antemano.

- Gaak -
__________________
L'Gaak dice
Responder Con Cita
 



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
Problema con archivos de texto. morodo Lazarus, FreePascal, Kylix, etc. 5 29-04-2011 02:07:03
XML vs archivos de texto jordan23 Varios 5 17-08-2007 19:18:06
Leer varios archivos de texto y extraer solo 2 lineas de ese texto mp3968 Internet 1 17-05-2007 20:24:09
Archivos de texto yekkita Varios 4 19-01-2007 20:06:03
archivos de texto ssanchez Varios 1 19-01-2007 15:44:34


La franja horaria es GMT +2. Ahora son las 01:41:06.


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