home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
DP Tool Club 19
/
CD_ASCQ_19_010295.iso
/
dos
/
prg
/
pas
/
ktools
/
source
/
oftext.pas
< prev
next >
Wrap
Pascal/Delphi Source File
|
1994-10-31
|
3KB
|
138 lines
Unit OFText;
{ Objet fichier texte dérivé de TBinFile }
{ KB Avril-Mai 1994 }
{
Cet objet permet les déplacements ligne à ligne vers le haut et vers le
bas dans un fichier texte.
}
{$IFDEF debug}
{$A+,B-,D+,E-,F-,I+,L+,N-,R+,S+,V-,W+,X+}
{$ELSE}
{$A+,B-,D-,E-,F-,I+,L-,N-,R-,S-,V-,W+,X+}
{$ENDIF}
INTERFACE
Uses Dos,OBinFile;
Const
MaxLigne = 255;
Type
PTextFile=^TTextFile;
TTextFile=object(TBinFile)
Constructor Init(NomDeFichier:PathStr;ABufSize:Word);
{ ouverture du fichier et attribution mémoire }
{ La fermeture et la libération mémoire se font par la méthode
Done héritée de TBinFile. }
Function GetLine:String;
{ renvoie la ligne courante }
Procedure GoToPrevLine;
{ fixe la position courante au début de la ligne précédente }
Procedure GoToNextLine;
{ fixe la position courante au début de la ligne suivante }
Procedure Append(S:String);
{ ajoute S et un retour chariot à la fin du fichier }
Function Search(S:String):Boolean;
{ cherche la chaine S et place le pointeur de fichier sur le début
de la ligne }
End;
IMPLEMENTATION
{ Objet TTextFile }
Constructor TTextFile.Init(NomDeFichier:PathStr;ABufSize:Word);
Begin
TBinFile.Init(NomDeFichier,ABufSize);
End;
Function TTextFile.GetLine:String;
{ Lit la ligne en cours et place le pointeur au début de la ligne suivante }
Var S:String;
l,p:Integer;
Begin
if EndOfFile
then begin
GetLine:='';
exit;
end;
if DataFileSize-DataFilePosit>MaxLigne
then l:=MaxLigne
else l:=DataFileSize-DataFilePosit;
S[0]:=chr(l);
ReadVar(S[1],l);
p:=pos(#13#10,S);
if p<>0
then begin
SetFilePosit(DataFilePosit-l+p+1);
S[0]:=chr(p-1);
end;
GetLine:=S;
End;
Procedure TTextFile.GoToNextLine;
{ Place le pointeur au début de la ligne suivante }
Var S:String;
Begin
S:=GetLine;
End;
Procedure TTextFile.GoToPrevLine;
{ Place le pointeur au début de la ligne précédente }
Var car:byte;
Begin
if DataFilePosit=0 then exit;
SetFilePosit(DataFilePosit-3);
car:=ReadByte;
while (DataFilePosit>1) and (car<>10) and (car<>13) do
begin
SetFilePosit(DataFilePosit-3);
car:=ReadByte;
end;
if car=13
then SetFilePosit(DataFilePosit+1);
if DataFilePosit=1 then SetFilePosit(0);
End;
Procedure TTextFile.Append(S:String);
Begin
S:=S+#13#10;
SetEndPosit;
WriteVar(S[1],length(S));
End;
Function TTextFile.Search(S:String):Boolean;
{ cherche la chaine S et place le pointeur de fichier sur le début
de la ligne }
Procedure UpStr(Var Str:String);
Var i:Byte;
Begin
for i:=1 to length(Str) do
Str[i]:=UpCase(Str[i]);
End;
Var W:String;
Begin
Search:=false;
if S='' then exit;
UpStr(S);
while not EndOfFile do
begin
W:=GetLine;
UpStr(W);
if pos(S,W)<>0
then begin
GoToPrevLine;
Search:=true;
exit;
end;
end;
End;
END.
{ Fin du fichier OFTEXT.PAS }