Upload
mercink
View
405
Download
5
Embed Size (px)
DESCRIPTION
DELPHI – RASTGELE ERİŞİMLİ DOSYALAMA ÖRNEĞİ
Citation preview
DELPHI – RASTGELE ERİŞİMLİ DOSYA KULLANIMINA YÖNELİK ÖRNEK
Type
Personel_Tipi=Record
sno: String[6];
ad: String[15];
soyad: String[15];
gorev: String[20];
kderece: String[5];
dtarihi: TDateTime;
tel: String[10];
adres: String[50];
hyili: Byte;
End;
Var
Sayac, KayitNo, KayitSayisi: LongInt;
Kayit: Personel_Tipi;
Dosya: File of Personel_Tipi;
procedure TForm1.KayitGoster;
begin
AssignFile(Dosya, 'c:\Personel.txt');
Reset(Dosya);
KayitSayisi := FileSize(Dosya);
StringGrid1.RowCount := KayitSayisi + 1;
For Sayac := 1 To KayitSayisi do begin
Seek(Dosya, Sayac-1);
Read(Dosya, Kayit);
With Kayit do
with Stringgrid1 do begin
Cells[0, Sayac] := sno;
Cells[1, Sayac] := ad;
Cells[2, Sayac] := soyad;
Cells[3, Sayac] := gorev;
Cells[4, Sayac] := kderece;
Cells[5, Sayac] := datetostr(dtarihi);
Cells[6, Sayac] := tel;
Cells[7, Sayac] := adres;
Cells[8, Sayac] := inttostr(hyili);
End;
end;
CloseFile(dosya);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
with StringGrid1 do begin
ColCount :=9; RowCount :=2;
FixedCols := 0; FixedRows := 1;
Cells[0,0] := 'Sicil Nosu';
Cells[1,0] := 'Adı';
Cells[2,0] := 'Soyadı';
Cells[3,0] := 'Görevi';
Cells[4,0] := 'KD';
Cells[5,0] := 'D.Tarihi';
Cells[6,0] := 'Telefon No';
Cells[7,0] := 'Adresi';
Cells[8,0] := 'H.Yili';
end;
KayitGoster;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Edit1.Clear; Edit2.Clear; Edit3.Clear;
Edit4.Clear; Edit5.Clear; Edit6.Clear;
Edit7.Clear; Edit8.Clear; Edit9.Clear;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
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;
AssignFile(Dosya, 'c:\personel.txt');
Reset(Dosya);
KayitSayisi := FileSize(Dosya);
Seek(Dosya, KayitSayisi);
Write(Dosya, Kayit);
CloseFile(Dosya);
KayitGoster;
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;