AssignFile(f,fname);
6.3.
write writeln. :
write ( , );
writeln ( , );
:
, , ;
, . .
, f TextFiie, x1 2 :
write(f, ' ', x1, 2);
³ write writeln , writeln , , " ".
6.4. ³
. , , , , . , : . .
:
( , );
.
, , Rewrite(f), f TextFile.
, , , Append(f), f TextFile.
. 6.1 , .
. 6.1. ij -
6.1 , . , Memo1.
' Edit1. ' . , data.txt, Edit1.Text.
˳ 6.1.
procedure TForm1.Button1Click(Sender: TObject);
Var
f: TextFile; //
fName: String[80]; // '
i: integer;
Begin
fName:= Edit1.Text;
AssignFile(f, fName);
Rewrite(f); //
//
for i:= 0 to Memo1.Lines.Count do //
writeln(f, Memo1.Lines[i]);
CloseFile(f); //
MessageDlg(' Ͳ ',mtInformation,[mbOk],0);
End;
6.2 , . , ' Edit1, Memo1.
|
|
˳ 6.2.
procedure TForm1.Button2Click(Sender: TObject);
Var
f: TextFile; //
fName: String[80];// '
i: integer;
Begin
fName:= Edit1.Text;
AssignFile(f, fName);
Append(f); //
//
for i:=0 to Memo1.Lines.Count do //
writeln(f, Memo1.Lines[i]);
CloseFile(f); //
MessageDlg(' Ͳ ', mtInformation, [mbOk], 0);
End;
6.5.
. . , , ( , ). , ( e ).
Delphi , ' (. 6.2).
. 6.2. ( Delphi)
Windows, (. 6.3).
. 6.3. . ( Windows)
. , IOResult (input-Output Result /). IOResuit 0, / ; ( ).
, /, . {$I-}, /. , . ϳ {$I+}, /.
. 6.4 - , ( , ) , , , .
. 6.4.
, .
AssignFile (f,filename);
{$I-}
Append(f) //
{$I+}
if IOResult<> 0 //
then Rewrite(f); //
//
. close. close ' . :
Close(f);
. ' (. 7.5), .
|
|
. 6.5. ij "-"
Edit1, Edit2. 7.3.
˳ 6.3, ( )
unit pogoda_;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls;
Type
TForm1 = class(TForm)
Edit1: TEdit; //
Edit2: TEdit; //
Button1: TButton; //
Label1: TLabe1;
Label2: TLabe1;
procedure FormActivate(Sender: TObject);
procedure ButtonlClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction); private
{Private declarations }
public
{Public declarations }
end;
Var
Form1: TForm1;
Implementation
{$R *.dfm}
Const
DBNAME = 'c:\Test\ListofPeople.db';
var
db: TextFile; //
procedure TForm1.FormActivate(Sender: TObject);
Begin
AssignFile(db, DBNAME);.
{$I-}
Append(db);
if IOResult = 0 then
Begin
Edit1.Text:= DateToStr(Date); //
Edit2.SetFocus; // Edit2
End
Else begin
Rewrite(db);
if IOResult <>0 then begin
// //
Edit1.Enabled:= False;
Edit2.Enabled:= False;
Button1.Enabled:= False;
ShowMessage(' '+DBNAME);
End;
End;
End;
//
procedure Tform1.Button1Click(Sender: TObject);
Begin
if (Length(Edit1.text)=0) or (Length(Edit2.text)=0)
Then
ShowMessage(' .' +#13+'Bce
.')
else writeln(db, Edit1.text, , ',Edit2.text);
End;
// OnClose
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
Begin
CloseFile(db); //
End;
End.
procedure TForm1.Button2Click(Sender: TObject); var i:integer; // st:string; // begin for i:=1 to SZL do if list[i] <> NIL then st:=st + list[i].info + #13; // ShowMessage(''+#13+st); writeln(db, '' + st); end; |
FormActivate, onActivate. OnActivate , , . , Edit1 . Date. Date ( Double) Dateiostr. ϳ Editi 䳿 onActivate setFocus . , .
TForm1.Button1Click ( 䳿 onclick) (Button1). pogoda.db. , , , , .
pogoda.db , (, , ) .
writein, write, , .
, writein . ϳ (Edit1.text) , (dit2.txt). , , , .
|
|
TFormi.Formciose, enclose, .
ϳ pogoda.db , , :
9.05.2001 10 10.05.2001 12 11.05.2001 10 12.05.2001 7
, . , , TextFile, AssignFile ' , , () () , read readln.
³
³ () Reset, . Reset AssignFile ' .
, :
AssignFile(f, 'c:\data.txt');
Reset(f);
' , ' , . , , , , , .
.
, , IOResult.
, 6.4, lOResult . , .
˳ 6.4. ( )
Var
fname: string[80]; // '
f: TextFile; //
res: integer; // ( lOResult)
answ: word; //
Begin
fname:= 'a:\test.txt';
AssignFile (f, fname);
Repeat
{$I-}
Reset(f); //
{$I+}
res:=IOResult;
if res <> 0 then
answ:= MessageDlg(' '+ fname+#13 +'
?',mtWarning, [mbYes, mbNo],0); until (res= 0) OR
(answ = mrNo);
if res <> 0
then exit; //
// ,
//
End;
read readln, :
read( , );
readln( , );
:
TextFile;
, .
, , . ij, read readln, : ( ), , , , , , ' read readln.
|
|
, :\data. txt :
23 15 45 28 56 71
:
AssignFile(f, 'a:\data.txt');
Reset(f); //
read(f, ); read(f, b, c); read(f, d);
: = 23, b = 15, = 45, d = 28.
³ readin read , , ' readin, , , .
AssignFile(f,'a:\data.txt');
Reset(f);
Readln(f, );
Readln(f, b, c);
Readln(f, d);
: = 23, b = 45, = 28, d = 56.
, .
.
:
strichka1:string[10];
strichka2:string;
, , , , , .
, , , . , , , , .
readln , , , , , , . , , , , ( ).
, f - reads.txt :
. 6.1 , freinds.txt .
6.1.
fnam: string[15] | Readln (f, fnam, name) | fnam= ' | ||||
name: string[10] | name= ' | |||||
fnam, name: string; | Readln (f, fnam, name) | fam= ' ' | ||||
name= ' ' | ||||||
drug: string[80] | Readln (f, drug) | drug =' ' | ||||
6.9. ̳
. . г : , , , , . , , ?
EOF (End of File ). EOF . EOF False, , . , EOF True.
EOF . True, , , ( ).
6.5 , . , ' , Memo. ³ . 6.6.
. 6.6. ³
˳ 6.5.
unit rd_;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes
Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons;
Type
TForm1 = class(TForm)
Button2: TButton;
Edit1: TEdit;
Memo1: TMemo;
Button1: TButton;
procedure Button2Click(Sender: TObject);
procedure ButtonlClick(Sender: TObject); private
|
|
{ Private declarations) public
{ Public declarations } end;
Var
Form1: Tform1;
Implementation
{$R *.dfm}
// ³
procedure TForm1.Button1Click(Sender: TObject);
var
f: TextFile; //
fName: String[80]; // '
buf: String[80]; //
Begin
fName:= Edit1.Text;
AssignFile(f, fName);
{$I-}
Reset(f); //
{$I+}
if IOResult<> 0 then
Begin
MessageDlg(' ' + fName mtError,[mbOk],0);
exit;
end;
//
while not EOF(f) do begin
readln(f, buf); //
Memo1.Lines.Add(buf); // Memo1
End;
CloseFile(f); //
End;
//
procedure Tform1.Button2Click(Sender: TObject);
Var
f: TextFile; //
fName: String[80]; // '
i: integer;
Begin
fName:= Edit1.Text; AssignFile(f, fName);
Rewrite(f); //
//
for i:=0 to Memo1.Lines.Count do //
writeln(f, Memo1.Lines[i]);
CloseFile(f); //
MessageDlg(' ', mtlnformation,[mbOk],0);
End;
End.
while, EOF , .
Memo , .
Memo Add Lines.
:
1. ?
2.
3.
4.
5. lOResult
6. ̳
˳: