Readstring flux ligne par ligne


TLineStream implémentation de la classe
Intervenant: MARTIN WALDENBURG

{ & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &
& nbsp | Classe: TLineStream
& nbsp | Créé le: 8.97
& nbsp | Auteur: Martin Waldenburg
& nbsp | Copyright 1997, tous droits réservés.
& nbsp | Description: TLineStream donne un tampon d'accès aux lignes d'un
fichier.
& nbsp | Chaque ligne doit se terminer par CRLF. N'oubliez pas de rincer le
& nbsp | Mémoire après l'avoir écrit.
& nbsp | Version: 1.2
& nbsp | Etat: FreeWare
& nbsp | Avertissement:
& nbsp | Ce est fournie qu'est expressément sans garantie d'aucune sorte.
& nbsp | Vous l'utilisez à votre propre risc.
& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & }
unité de mwLineStream
interface

& nbsp & nbsp SysUtils, Classes
type
& nbsp & nbsp TLineStream = classe(TFileStream)
& nbsp & nbsp privé
& ! & ! & ! & nbsp fLineStart: PChar
& ! & ! & ! & nbsp fMaxMemorySize:Longint
& ! & ! & ! & nbsp fMaxLineSize:Longint
& ! & ! & ! & nbsp fMemorySize: LongInt
& ! & ! & ! & nbsp fLineSize:Longint
& ! & ! & ! & nbsp fMemory:PChar
& ! & ! & ! & nbsp fLine: PChar
& ! & ! & ! & nbsp fFileEof:Boolean
& ! & ! & ! & nbsp fMemoryPos: LongInt
& ! & ! & ! & nbsp fEof:Boolean
& ! & ! & ! & nbsp fonction GetMemoryFull:Boolean
& ! & ! & ! & nbsp procédure SetMaxLineSize(NewValue:Longint)
& ! & ! & ! & nbsp procédure SetMaxMemorySize(NewValue:Longint)
& nbsp & nbsp protégé
& nbsp & nbsp public
& ! & ! & ! & nbsp constructeur créer(Const FileName: string Mode: Word)
& ! & ! & ! & nbsp destructeur de détruire remplacer
& ! & ! & ! & nbsp procédure FillMemory
& ! & ! & ! & nbsp fonction ReadLine:PChar
& ! & ! & ! & nbsp procédure WriteLine(Saut de ligne: String)
& ! & ! & ! & nbsp procédure FlushMemory
& ! & ! & ! & nbsp procédure de Réinitialisation
& ! & ! & ! & nbsp propriété MaxMemorySize:Longint lire fMaxMemorySize écrire
SetMaxMemorySize
& ! & ! & ! & nbsp propriété MaxLineSize:Longint lire fMaxLineSize écrire SetMaxLineSize
& ! & ! & ! & nbsp propriété de la Mémoire:PChar lire fMemory écrire fMemory
& ! & ! & ! & nbsp propriété MemoryFull:Boolean lire GetMemoryFull
& ! & ! & ! & nbsp propriété FileEof:Boolean lire fFileEof
& ! & ! & ! & nbsp propriété Eof:Boolean lire fEof écrire fEof
& nbsp & nbsp publié
& nbsp & nbsp end { TLineStream }
application
constructeur TLineStream.créer(Const FileName: string Mode: Word)
var
& nbsp & nbsp fHandle: Integer
begin
& nbsp & nbsp si pas FileExists(nom de fichier)
& ! & ! & ! & nbsp commencer
& ! & ! & ! & ! & ! & nbsp fHandle:= FileCreate(nom de fichier)
& ! & ! & ! & ! & ! & nbsp FileClose(fHandle)
& ! & ! & ! & nbsp fin
& nbsp & nbsp hérité de créer(FileName, Mode)
& nbsp & nbsp fEof:= False
& nbsp & nbsp fFileEof:= False
& nbsp & nbsp MaxMemorySize:= 65535
& nbsp & nbsp fMemorySize:= 0
& nbsp & nbsp fMemoryPos:= 0
& nbsp & nbsp MaxLineSize:= 4096
& nbsp & nbsp Position:= 0
end { créer }
destructeur TLineStream.détruire
begin

& nbsp & nbsp ReallocMem(fMemory, 0)
& nbsp & nbsp ReallocMem(fLine, 0)
& nbsp & nbsp hérité de détruire
end { détruire }

procédure TLineStream.SetMaxMemorySize(NewValue:Longint)
begin
& nbsp & nbsp fMaxMemorySize:= NewValue
& nbsp & nbsp ReallocMem(fMemory, fMaxMemorySize 1)
end { SetMaxMemorySize }
procédure TLineStream.SetMaxLineSize(NewValue:Longint)
begin
& nbsp & nbsp fMaxLineSize:= NewValue
& nbsp & nbsp ReallocMem(fLine, fMaxLineSize 1)
end { SetMaxLineSize }
procédure TLineStream.FillMemory
var
& nbsp & nbsp Lus: LongInt
begin
& nbsp & nbsp Lus:= Read(fMemory^, fMaxMemorySize)
& nbsp & nbsp fMemorySize:= Lus
& nbsp & nbsp si Lus = 0 alors fFileEof:= True
& nbsp & nbsp si fMemorySize > 0, alors
& nbsp & nbsp tandis que fMemory[fMemorySize -2] <> #13 déc(fMemorySize)
& nbsp & nbsp fMemory[fMemorySize]:= #0
& nbsp & nbsp Position:= Position -Lus fMemorySize 1
& nbsp & nbsp fLineStart:= fMemory
end { FillMemory }
fonction de TLineStream.GetMemoryFull:Boolean
begin
& nbsp & nbsp si fMemorySize > 0 then Result:= True else Result:= False
end { GetMemoryFull }
fonction de TLineStream.ReadLine:PChar
var
& nbsp & nbsp Exécuter: PChar
begin
& nbsp & nbsp si (fMemorySize = 0) et non FileEof puis FillMemory
& nbsp & nbsp si fMemorySize > 0, alors
& nbsp & nbsp commencer
& ! & ! & ! & nbsp Exécuter:= fLineStart
& ! & ! & ! & nbsp alors qu'^ <> #13 inc(Exécuter)
& ! & ! & ! & nbsp fLineSize:= Run - fLineStart
& ! & ! & ! & nbsp inc(Courir, 2)
& ! & ! & ! & nbsp StrLCopy(fLine, fLineStart, fLineSize)
& ! & ! & ! & nbsp fLine[fLineSize]:= #0
& ! & ! & ! & nbsp Résultat:= fLine
& ! & ! & ! & nbsp fLineStart:= Run
& ! & ! & ! & nbsp Exécution des Cas^ de #0: FillMemory fin
& nbsp & nbsp fin
& nbsp & nbsp si fMemorySize = 0 alors fEof:= True
end { ReadLine }
procédure TLineStream.WriteLine(Saut de ligne: String)
var
& nbsp & nbsp Comte, Pos: Longint
begin
& nbsp & nbsp retour à la ligne:= NewLine #13#10
& nbsp & nbsp Count:= Longueur(Saut de ligne)
& nbsp & nbsp si (fMemoryPos >= 0) et (Nombre >= 0) puis
& nbsp & nbsp commencer
& ! & ! & ! & nbsp Pos := fMemoryPos Comte
& ! & ! & ! & nbsp si Pos > 0, alors
& ! & ! & ! & nbsp commencer
& ! & ! & ! & ! & ! & nbsp si Pos > FMaxMemorySize puis
& ! & ! & ! & ! & ! & ! & ! & nbsp commencer
& ! & ! & ! & ! & ! & ! & ! & ! & ! & ! & nbsp FlushMemory
& ! & ! & ! & ! & ! & ! & ! & nbsp fin
& ! & ! & ! & ! & ! & nbsp StrECopy((fMemory fMemoryPos), PChar(NewLine))
& ! & ! & ! & ! & ! & nbsp fMemoryPos:= fMemoryPos Comte
& ! & ! & ! & ! & ! & nbsp fMemory[fMemoryPos]:= #0
& ! & ! & ! & nbsp fin
& nbsp & nbsp fin
end { WriteLine }
procédure TLineStream.FlushMemory
begin
& nbsp & nbsp Écrire(fMemory^, fMemoryPos)
& nbsp & nbsp fMemoryPos:= 0
end { FlushMemory }
procédure TLineStream.Reset
begin
& nbsp & nbsp fEof:= False
& nbsp & nbsp fFileEof:= False
& nbsp & nbsp fMemorySize:= 0
& nbsp & nbsp fMemoryPos:= 0
& nbsp & nbsp Position:= 0
end { Reset }
à la fin.









Readstring flux ligne par ligne


Readstring flux ligne par ligne : Plusieurs milliers de conseils pour vous faciliter la vie.


TLineStream implementation de la classe
Intervenant: MARTIN WALDENBURG

{ & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & &
& nbsp | Classe: TLineStream
& nbsp | Cree le: 8.97
& nbsp | Auteur: Martin Waldenburg
& nbsp | Copyright 1997, tous droits reserves.
& nbsp | Description: TLineStream donne un tampon d'acces aux lignes d'un
fichier.
& nbsp | Chaque ligne doit se terminer par CRLF. N'oubliez pas de rincer le
& nbsp | Memoire apres l'avoir ecrit.
& nbsp | Version: 1.2
& nbsp | Etat: FreeWare
& nbsp | Avertissement:
& nbsp | Ce est fournie qu'est expressement sans garantie d'aucune sorte.
& nbsp | Vous l'utilisez a votre propre risc.
& & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & & }
unite de mwLineStream
interface

& nbsp & nbsp SysUtils, Classes
type
& nbsp & nbsp TLineStream = classe(TFileStream)
& nbsp & nbsp prive
& ! & ! & ! & nbsp fLineStart: PChar
& ! & ! & ! & nbsp fMaxMemorySize:Longint
& ! & ! & ! & nbsp fMaxLineSize:Longint
& ! & ! & ! & nbsp fMemorySize: LongInt
& ! & ! & ! & nbsp fLineSize:Longint
& ! & ! & ! & nbsp fMemory:PChar
& ! & ! & ! & nbsp fLine: PChar
& ! & ! & ! & nbsp fFileEof:Boolean
& ! & ! & ! & nbsp fMemoryPos: LongInt
& ! & ! & ! & nbsp fEof:Boolean
& ! & ! & ! & nbsp fonction GetMemoryFull:Boolean
& ! & ! & ! & nbsp procedure SetMaxLineSize(NewValue:Longint)
& ! & ! & ! & nbsp procedure SetMaxMemorySize(NewValue:Longint)
& nbsp & nbsp protege
& nbsp & nbsp public
& ! & ! & ! & nbsp constructeur creer(Const FileName: string Mode: Word)
& ! & ! & ! & nbsp destructeur de detruire remplacer
& ! & ! & ! & nbsp procedure FillMemory
& ! & ! & ! & nbsp fonction ReadLine:PChar
& ! & ! & ! & nbsp procedure WriteLine(Saut de ligne: String)
& ! & ! & ! & nbsp procedure FlushMemory
& ! & ! & ! & nbsp procedure de Reinitialisation
& ! & ! & ! & nbsp propriete MaxMemorySize:Longint lire fMaxMemorySize ecrire
SetMaxMemorySize
& ! & ! & ! & nbsp propriete MaxLineSize:Longint lire fMaxLineSize ecrire SetMaxLineSize
& ! & ! & ! & nbsp propriete de la Memoire:PChar lire fMemory ecrire fMemory
& ! & ! & ! & nbsp propriete MemoryFull:Boolean lire GetMemoryFull
& ! & ! & ! & nbsp propriete FileEof:Boolean lire fFileEof
& ! & ! & ! & nbsp propriete Eof:Boolean lire fEof ecrire fEof
& nbsp & nbsp publie
& nbsp & nbsp end { TLineStream }
application
constructeur TLineStream.creer(Const FileName: string Mode: Word)
var
& nbsp & nbsp fHandle: Integer
begin
& nbsp & nbsp si pas FileExists(nom de fichier)
& ! & ! & ! & nbsp commencer
& ! & ! & ! & ! & ! & nbsp fHandle:= FileCreate(nom de fichier)
& ! & ! & ! & ! & ! & nbsp FileClose(fHandle)
& ! & ! & ! & nbsp fin
& nbsp & nbsp herite de creer(FileName, Mode)
& nbsp & nbsp fEof:= False
& nbsp & nbsp fFileEof:= False
& nbsp & nbsp MaxMemorySize:= 65535
& nbsp & nbsp fMemorySize:= 0
& nbsp & nbsp fMemoryPos:= 0
& nbsp & nbsp MaxLineSize:= 4096
& nbsp & nbsp Position:= 0
end { creer }
destructeur TLineStream.detruire
begin

& nbsp & nbsp ReallocMem(fMemory, 0)
& nbsp & nbsp ReallocMem(fLine, 0)
& nbsp & nbsp herite de detruire
end { detruire }

procedure TLineStream.SetMaxMemorySize(NewValue:Longint)
begin
& nbsp & nbsp fMaxMemorySize:= NewValue
& nbsp & nbsp ReallocMem(fMemory, fMaxMemorySize 1)
end { SetMaxMemorySize }
procedure TLineStream.SetMaxLineSize(NewValue:Longint)
begin
& nbsp & nbsp fMaxLineSize:= NewValue
& nbsp & nbsp ReallocMem(fLine, fMaxLineSize 1)
end { SetMaxLineSize }
procedure TLineStream.FillMemory
var
& nbsp & nbsp Lus: LongInt
begin
& nbsp & nbsp Lus:= Read(fMemory^, fMaxMemorySize)
& nbsp & nbsp fMemorySize:= Lus
& nbsp & nbsp si Lus = 0 alors fFileEof:= True
& nbsp & nbsp si fMemorySize > 0, alors
& nbsp & nbsp tandis que fMemory[fMemorySize -2] <> #13 dec(fMemorySize)
& nbsp & nbsp fMemory[fMemorySize]:= #0
& nbsp & nbsp Position:= Position -Lus fMemorySize 1
& nbsp & nbsp fLineStart:= fMemory
end { FillMemory }
fonction de TLineStream.GetMemoryFull:Boolean
begin
& nbsp & nbsp si fMemorySize > 0 then Result:= True else Result:= False
end { GetMemoryFull }
fonction de TLineStream.ReadLine:PChar
var
& nbsp & nbsp Executer: PChar
begin
& nbsp & nbsp si (fMemorySize = 0) et non FileEof puis FillMemory
& nbsp & nbsp si fMemorySize > 0, alors
& nbsp & nbsp commencer
& ! & ! & ! & nbsp Executer:= fLineStart
& ! & ! & ! & nbsp alors qu'^ <> #13 inc(Executer)
& ! & ! & ! & nbsp fLineSize:= Run - fLineStart
& ! & ! & ! & nbsp inc(Courir, 2)
& ! & ! & ! & nbsp StrLCopy(fLine, fLineStart, fLineSize)
& ! & ! & ! & nbsp fLine[fLineSize]:= #0
& ! & ! & ! & nbsp Resultat:= fLine
& ! & ! & ! & nbsp fLineStart:= Run
& ! & ! & ! & nbsp Execution des Cas^ de #0: FillMemory fin
& nbsp & nbsp fin
& nbsp & nbsp si fMemorySize = 0 alors fEof:= True
end { ReadLine }
procedure TLineStream.WriteLine(Saut de ligne: String)
var
& nbsp & nbsp Comte, Pos: Longint
begin
& nbsp & nbsp retour a la ligne:= NewLine #13#10
& nbsp & nbsp Count:= Longueur(Saut de ligne)
& nbsp & nbsp si (fMemoryPos >= 0) et (Nombre >= 0) puis
& nbsp & nbsp commencer
& ! & ! & ! & nbsp Pos := fMemoryPos Comte
& ! & ! & ! & nbsp si Pos > 0, alors
& ! & ! & ! & nbsp commencer
& ! & ! & ! & ! & ! & nbsp si Pos > FMaxMemorySize puis
& ! & ! & ! & ! & ! & ! & ! & nbsp commencer
& ! & ! & ! & ! & ! & ! & ! & ! & ! & ! & nbsp FlushMemory
& ! & ! & ! & ! & ! & ! & ! & nbsp fin
& ! & ! & ! & ! & ! & nbsp StrECopy((fMemory fMemoryPos), PChar(NewLine))
& ! & ! & ! & ! & ! & nbsp fMemoryPos:= fMemoryPos Comte
& ! & ! & ! & ! & ! & nbsp fMemory[fMemoryPos]:= #0
& ! & ! & ! & nbsp fin
& nbsp & nbsp fin
end { WriteLine }
procedure TLineStream.FlushMemory
begin
& nbsp & nbsp Ecrire(fMemory^, fMemoryPos)
& nbsp & nbsp fMemoryPos:= 0
end { FlushMemory }
procedure TLineStream.Reset
begin
& nbsp & nbsp fEof:= False
& nbsp & nbsp fFileEof:= False
& nbsp & nbsp fMemorySize:= 0
& nbsp & nbsp fMemoryPos:= 0
& nbsp & nbsp Position:= 0
end { Reset }
a la fin.


Readstring flux ligne par ligne

Readstring flux ligne par ligne : Plusieurs milliers de conseils pour vous faciliter la vie.
Recommander aux amis
  • gplus
  • pinterest

Messages récents

Commentaire

Laisser un commentaire

évaluation