TFileStream/fr
Deutsch · English · Français · Polski
Description
Un TFileStream est un descendant de TStream qui lit/écrit ses données depuis/vers un fichier sur disque. Un TFileStream charge l'entièreté des données d'un fichier en mémoire, et vice versa.
Constantes de création
| Constante | Décimal | Description |
|---|---|---|
| fmCreate | 65280 | Crée un nouveau fichier |
| fmOpenRead | 0 | Ouvre un fichier en lecture |
| fmOpenWrite | 1 | Ouvre un fichier en écriture |
| fmOpenReadWrite | 2 | Ouvre un fichier en lecture/écriture |
| fmShareDenyWrite | 32 | Empêche l'écriture si le fichier est déjà ouvert |
Lecture de données
Lecture du fichier fnam :
function readstream( fnam: string ): string;
var
strm: TFileStream;
n: longint;
txt: string;
begin
txt := '';
strm := TFileStream.Create( fnam, fmOpenRead or fmShareDenyWrite );
try
n := strm.Size;
SetLength( txt, n );
strm.Read( txt[1], n );
finally
FreeAndNil( strm );
end;
result := txt;
end;Ecriture de données
Ecriture de txt dans le fichier fnam :
procedure writestream( fnam: string; txt: string );
var
strm: TFileStream;
n: longint;
begin
strm := TFileStream.Create( fnam, fmCreate );
n := Length( txt );
try
strm.Position := 0;
strm.Write( txt[1], n );
finally
FreeAndNil( strm );
end;
end;Voir aussi
From the Free Pascal wiki, page "TFileStream/fr", as it stood on 2020-03-01 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.
Talk about this page
Nobody has opened a bench for this page yet. Sign in to open one.
