1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
Procedure WriteMemo(ALst : TStrings;ASaveFile : String; AEraseFile : Boolean);
var
MemoStream : TFileStream;
i : Integer;
// Si delphi XE et +
{$IFDEF D15}
Buffer : TBytes;
Encoding : TEncoding;
{$ENDIF}
begin
if ALst.count = 0 then
Exit;
// Suppression du ficheir
if AEraseFile then
DeleteFile(ASaveFile);
if not AEraseFile and FileExists(ASaveFile) then
begin
// Update du fichier
MemoStream := TFileStream.Create(ASaveFile, fmOpenReadWrite);
MemoStream.Seek(0,soFromEnd);
end else
// Création du fichier
MemoStream := TFileStream.Create(ASaveFile, fmCreate);
try
For i := 0 to Alst.count -1 do
begin
{$IFDEF D15}
// Pour dephi XE et +
Encoding := TEncoding.Default;
Buffer := Encoding.GetBytes(Alst[i]);
FFile.Write(Buffer[0],Length(Buffer));
{$ELSE}
FFile.Write(Alst[i][0],Length(Alst[i]));
{$ENDIF}
end;
finally
memoStream.Free;
end;
end; |
Partager