Procedure TMOText. ConVert (const Dir: String).
Var
I, v: Integer;
A: TextFile;
S: a String;
The begin
AssignFile (A, Dir);
Try
Append (A);
Except,
Rewrite (A);
end;
The begin
Writeln (A, 'start');
end;
S:=';
For I:=0 to adodsCustomer1. Do RecordCount - 1
The begin
For v:=0 to adodsCustomer1. Fields. Do the Count - 1
The begin
S:=S + adodsCustomer1. Fields. The Fields [v]. AsString;
If v & lt; AdodsCustomer1. Fields. Then the Count - 1
S:=S + '|'.
end;
AdodsCustomer1. Next;
Writeln (A, s);
S:=';
end;
The begin
Writeln (A, 'END');
end;
CloseFile (A);
end;
Procedure TMOText. Button3click (Sender: TObject);
Var
A: TextFile;
The begin
If SaveDia. Execute then
The begin
If fileexists (SaveDia. FileName) then
The begin
Showmessage (' file already exists);
End the else
ConVert (SaveDia FileName);
end;
end;
CodePudding user response:
Didn't understand what you want to do,Is to want to save a file, if the file already exists, do not save? Or if the file already exists additional content into the file?
CodePudding user response:
Just want to put the database of the contents, according to the fixed format export text, encounter problems when exported, wanted to not create a new file, then replace, the results make a mistakeCodePudding user response:
If the file already exists, it is easy to have replace ah, how to get so complicated?
Var
F: TextFile;
Fname: string;
The begin
Fname:='c: \ 1. TXT';
The DeleteFile (fname);//regardless of whether there is performed first delete
AssignFile (f, fname);
Try
Rewrite (f);
//write content
The finally
CloseFile (f);
end;
CodePudding user response:
If the file delete not to drop, check whether the file opened by other processes has not been closed,
Var
F: TextFile;
Fname: string;
The begin
Fname:='c: \ 1. TXT';
If DeleteFile (fname) then
The begin
AssignFile (f, fname);
Try
Rewrite (f);
//write content
The finally
CloseFile (f);
end;
End
The else
Raise the Exception. CreateFmt (' delete file % s failure, [fname]);
end;