Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

DELPHI – RASTGELE ERİŞİMLİ DOSYA KULLANIMINA YÖNELİK ÖRNEK

Type procedure TForm1.FormCreate(Sender: TObject);


Personel_Tipi=Record begin
sno: String[6]; with StringGrid1 do begin
ad: String[15]; ColCount :=9; RowCount :=2;
soyad: String[15]; FixedCols := 0; FixedRows := 1;
gorev: String[20]; Cells[0,0] := 'Sicil Nosu';
kderece: String[5]; Cells[1,0] := 'Adı';
dtarihi: TDateTime; Cells[2,0] := 'Soyadı';
tel: String[10]; Cells[3,0] := 'Görevi';
adres: String[50]; Cells[4,0] := 'KD';
hyili: Byte; Cells[5,0] := 'D.Tarihi';
End; Cells[6,0] := 'Telefon No';
Cells[7,0] := 'Adresi';
Var Cells[8,0] := 'H.Yili';
Sayac, KayitNo, KayitSayisi: LongInt; end;
Kayit: Personel_Tipi; KayitGoster;
Dosya: File of Personel_Tipi; end;

procedure TForm1.KayitGoster; procedure TForm1.Button1Click(Sender: TObject);


begin begin
AssignFile(Dosya, 'c:\Personel.txt'); Edit1.Clear; Edit2.Clear; Edit3.Clear;
Reset(Dosya); Edit4.Clear; Edit5.Clear; Edit6.Clear;
KayitSayisi := FileSize(Dosya); Edit7.Clear; Edit8.Clear; Edit9.Clear;
end;
StringGrid1.RowCount := KayitSayisi + 1;
For Sayac := 1 To KayitSayisi do begin procedure TForm1.Button2Click(Sender: TObject);
Seek(Dosya, Sayac-1); begin
Read(Dosya, Kayit); With Kayit do begin
With Kayit do sno := Edit1.Text; ad := Edit2.Text; soyad := Edit3.Text;
with Stringgrid1 do begin gorev := Edit4.Text; kderece := Edit5.Text;
Cells[0, Sayac] := sno; dtarihi := StrToDate(Edit6.Text); tel := Edit7.Text;
Cells[1, Sayac] := ad; adres := Edit8.Text; hyili := strtointdef(Edit9.Text,0);
Cells[2, Sayac] := soyad; End;
Cells[3, Sayac] := gorev;
Cells[4, Sayac] := kderece; AssignFile(Dosya, 'c:\personel.txt');
Cells[5, Sayac] := datetostr(dtarihi); Reset(Dosya);
Cells[6, Sayac] := tel; KayitSayisi := FileSize(Dosya);
Cells[7, Sayac] := adres; Seek(Dosya, KayitSayisi);
Cells[8, Sayac] := inttostr(hyili); Write(Dosya, Kayit);
End; CloseFile(Dosya);
end; KayitGoster;
CloseFile(dosya); end;
end;

procedure TForm1.Button3Click(Sender: TObject);


var
aranan: String; cevap: Integer;
begin
If KayitNo = 0 Then begin
aranan := InputBox('Düzeltme İşlemi','Personelin adını giriniz:','');

AssignFile(Dosya, 'c:\personel.txt');
Reset(Dosya);
KayitSayisi := Filesize(Dosya);
For Sayac := 1 To KayitSayisi do begin
Seek(Dosya,Sayac-1);
Read(Dosya, Kayit);
With Kayit do
If Trim(ad) = Trim(aranan) Then begin
Edit1.Text := Trim(sno); Edit2.Text := Trim(ad);
Edit3.Text := Trim(soyad); Edit4.Text := Trim(gorev);
Edit5.Text := Trim(kderece); Edit6.Text := DateToStr(dtarihi);
Edit7.Text := Trim(tel); Edit8.Text := Trim(adres);
Edit9.Text := IntToStr(hyili);
cevap := MessageDlg('Düzenlenecek kayıt bu mu?', mtConfirmation, [mbYes, mbNo], 0);
If cevap = mrYes Then begin
Button3.Caption := 'Kaydet';
KayitNo := Sayac;
CloseFile(Dosya);
Exit; // Prosedürden çık
End;
End;
end;
CloseFile(Dosya);
ShowMessage('Aranan kayıt bulunamadı!');
end
Else begin
AssignFile(Dosya, 'c:\personel.txt');
Reset(Dosya);
With Kayit do begin
sno := Edit1.Text; ad := Edit2.Text; soyad := Edit3.Text;
gorev := Edit4.Text; kderece := Edit5.Text;
dtarihi := StrToDate(Edit6.Text); tel := Edit7.Text;
adres := Edit8.Text; hyili := Strtointdef(Edit9.Text,0);
End;
Seek(Dosya, KayitNo-1); Write(Dosya, Kayit);
CloseFile(Dosya);
KayitGoster;
KayitNo := 0;
Button3.Caption := 'Düzenle';
End;
Button1Click(Form1);
end;

procedure TForm1.Button4Click(Sender: TObject);


var
aranan: String; cevap: Integer;
begin
aranan := InputBox('Silme İşlemi','Personelin adını giriniz:','');

AssignFile(Dosya, 'c:\personel.txt');
Reset(Dosya);
KayitSayisi := Filesize(Dosya);
For Sayac := 1 To KayitSayisi do begin
Seek(Dosya,Sayac-1);
Read(Dosya, Kayit);
With Kayit do
If Trim(ad) = Trim(aranan) Then begin
Edit1.Text := Trim(sno); Edit2.Text := Trim(ad);
Edit3.Text := Trim(soyad); Edit4.Text := Trim(gorev);
Edit5.Text := Trim(kderece); Edit6.Text := Datetostr(dtarihi);
Edit7.Text := Trim(tel); Edit8.Text := Trim(adres); Edit9.Text := IntToStr(hyili);
cevap := MessageDlg('Silinecek kayıt bu mu?', mtConfirmation, [mbYes, mbNo], 0);
If cevap = mrYes Then begin
Seek(Dosya, KayitSayisi-1); Read(Dosya, Kayit); // Son kaydı oku
Seek(Dosya, Sayac-1); Write(Dosya, Kayit); // Aktif yani silinecek kaydın üzerine yaz
Seek(Dosya, KayitSayisi-1); Truncate(Dosya); // Son kaydı sil
CloseFile(Dosya);
KayitGoster;
Exit;
End;
End;
end;
CloseFile(Dosya);
ShowMessage('Aranan kayıt bulunamadı!');
Button1Click(Form1);
end;

procedure TForm1.Button5Click(Sender: TObject);


begin
Close;
end;

You might also like