Mega Code Archive

 
Categories / Delphi / Files
 

Dosyalama için write ve read komutları kullanımı

//write ve read komutlarının basit kullanımı unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; Button3: TButton; OpenDialog1: TOpenDialog; Edit1: TEdit; Button4: TButton; SaveDialog1: TSaveDialog; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button3Click(Sender: TObject); procedure Button4Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; f: TextFile; satir:string; dosya:string= 'varsayilan.txt'; implementation {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); begin if OpenDialog1.Execute then begin dosya:=OpenDialog1.FileName; caption:= 'Dosya İşlemleri - '+dosya; memo1.Clear; AssignFile(f, dosya); Reset(F); while not Eof(f) do begin Readln(f, satir); memo1.Lines.Add(satir); end; CloseFile(f); end; end; procedure TForm1.Button3Click(Sender: TObject); begin close; end; procedure TForm1.Button4Click(Sender: TObject); begin if dosya <> 'varsayilan.txt' then begin AssignFile(f, dosya); Append(f); Writeln(f, edit1.text); Flush(f); CloseFile(f); memo1.Clear; AssignFile(f, dosya); Reset(F); while not Eof(f) do begin Readln(f, satir); memo1.Lines.Add(satir); end; CloseFile(f); end; end; procedure TForm1.Button2Click(Sender: TObject); var i:integer; begin if SaveDialog1.Execute then begin dosya:= SaveDialog1.FileName; caption:= 'Dosya İşlemleri - '+dosya; AssignFile(f, dosya); Rewrite(f); for i:=0 to memo1.Lines.Count-1 do begin Writeln(f, memo1.lines[i]); Flush(f); end; CloseFile(f); end; end; end.