unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, Buttons, ExtCtrls;
type
TForm2 =
class(TForm)
Panel1: TPanel;
GroupBox1: TGroupBox;
Panel3: TPanel;
Panel4: TPanel;
Panel5: TPanel;
Panel6: TPanel;
Label1: TLabel;
Edit1: TEdit;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Edit4: TEdit;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Edit5: TEdit;
BitBtn1: TBitBtn;
StringGrid1: TStringGrid;
BitBtn2: TBitBtn;
SaveDialog1: TSaveDialog;
OpenDialog1: TOpenDialog;
Label7: TLabel;
Label8: TLabel;
BitBtn3: TBitBtn;
procedure FormCreate(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
// procedure Button1Click(Sender: TObject);
procedure Panel4Click(Sender: TObject);
procedure Panel5Click(Sender: TObject);
procedure savedialog();
procedure BitBtn2Click(Sender: TObject);
procedure Panel6Click(Sender: TObject);
procedure StringGrid1Click(Sender: TObject);
procedure addhistory();
procedure updatehistory();
// procedure BitBtn3Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form2: TForm2;
implementation
uses Unit1;
{$R *.dfm}
type TData =
record
Id :
string[20];
fremd :
string[20];
bed1 :
string[20];
bed2 :
string[20];
bed3 :
string[20];
bed4 :
string[20];
end;
type PData =
record
pfad :
string[100];
name :
string[20];
end;
var
filep, title :
string;
procedure TForm2.BitBtn1Click(Sender: TObject);
var
fremdwort, bed1, bed2, bed3, bed4 :
string;
i : integer;
begin
fremdwort := edit1.text;
bed1 := edit2.text;
bed2 := edit3.text;
bed3 := edit4.text;
bed4 := edit5.text;
i := StringGrid1.RowCount-1;
if StringGrid1.RowCount = 2
then begin
With StringGrid1
do begin
Cells[0,1] := inttostr(i);
Cells[1,1] := fremdwort;
Cells[2,1] := bed1;
Cells[3,1] := bed2;
Cells[4,1] := bed3;
Cells[5,1] := bed4;
end;
Stringgrid1.RowCount := StringGrid1.RowCount + 1;
end else
With StringGrid1
do begin
Cells[0,StringGrid1.RowCount-1] := inttostr(i);
Cells[1,StringGrid1.RowCount-1] := fremdwort;
Cells[2,StringGrid1.RowCount-1] := bed1;
Cells[3,StringGrid1.RowCount-1] := bed2;
Cells[4,StringGrid1.RowCount-1] := bed3;
Cells[5,StringGrid1.RowCount-1] := bed4;
Stringgrid1.RowCount := StringGrid1.RowCount + 1;
end;
fremdwort := '
';
bed1 := '
';
bed2 := '
';
bed3 := '
';
bed4 := '
';
edit1.text := '
';
edit2.text := '
';
edit3.text := '
';
edit4.text := '
';
edit5.text := '
';
Edit1.SetFocus;
if filep <> '
'
then Form2.Caption := '
Vokabelliste verwalten '+filep+'
*';
end;
procedure TForm2.BitBtn2Click(Sender: TObject);
var
sel, i : integer;
warning : PChar;
begin
sel := Stringgrid1.Selection.TopLeft.Y;
warning := '
Soll dieser Datensatz wirklich gelöscht werden?';
if Application.MessageBox(PChar(warning), '
Löschen bestätigen', 52) = 6
then begin
for i := sel
To StringGrid1.RowCount - 1
do
begin
StringGrid1.Rows[i] := StringGrid1.Rows[i+ 1];
end;
StringGrid1.RowCount := StringGrid1.RowCount - 1;
for i := 0
to StringGrid1.RowCount - 1
do
begin
StringGrid1.Cells[0,I+1] := inttostr(I+1);
end;
end;
end;
{
procedure TForm2.BitBtn3Click(Sender: TObject);
begin
if StringGrid1.Selection.TopLeft.Y <> -1 then
begin
end else
ShowMessage('Es muss ein Datensatz ausgewählt werden!');
end;
}
procedure TForm2.FormCreate(Sender: TObject);
begin
Form2.Caption := '
Vokabelliste verwalten';
With StringGrid1
do begin
width := 530;
ColWidths[0] := 30;
ColWidths[1] := 100;
ColWidths[2] := 100;
ColWidths[3] := 100;
ColWidths[4] := 100;
ColWidths[5] := 100;
Cells[0,0] := '
Nr.';
Cells[1,0] := '
Fremdwort';
Cells[2,0] := '
Bedeutung 1';
Cells[3,0] := '
Bedeutung 2';
Cells[4,0] := '
Bedeutung 3';
Cells[5,0] := '
Bedeutung 4';
end;
end;
procedure TForm2.savedialog;
var
f :
file of TData;
data : TData;
x: integer;
begin
if SaveDialog1.Execute
then begin
filep := SaveDialog1.FileName;
end;
AssignFile(f,filep);
{$I-}
Rewrite(f);
x := 0;
while x <> StringGrid1.RowCount -1
do begin
inc(x);
seek(f,Filesize(f));
with data
do begin
Id := StringGrid1.Cells[0,x];
fremd := StringGrid1.Cells[1,x];
bed1 := StringGrid1.Cells[2,x];
bed2 := StringGrid1.Cells[3,x];
bed3 := StringGrid1.Cells[4,x];
bed4 := StringGrid1.Cells[5,x];
end;
write(f,data);
end;
closefile(f);
{$I+}
end;
procedure TForm2.StringGrid1Click(Sender: TObject);
begin
label7.caption := inttostr(Stringgrid1.Selection.TopLeft.X);
label8.Caption := inttostr(Stringgrid1.Selection.TopLeft.Y);
end;
procedure TForm2.Panel4Click(Sender: TObject);
begin
savedialog();
updatehistory;
addhistory;
end;
procedure TForm2.Panel5Click(Sender: TObject);
var
f :
file of TData;
fh :
file of PData;
datap : PData;
data : TData;
x, y, posi,rows,seekk : integer;
gefunden : boolean;
fname :
string;
begin
if filep = '
'
then begin
savedialog();
end else
AssignFile(f,filep);
{$I-}
Rewrite(f);
{$I-}
x := 0;
while x <> StringGrid1.RowCount -1
do begin
inc(x);
{$I-}
seek(f,Filesize(f));
{$I-}
with data
do begin
Id := StringGrid1.Cells[0,x];
fremd := StringGrid1.Cells[1,x];
bed1 := StringGrid1.Cells[2,x];
bed2 := StringGrid1.Cells[3,x];
bed3 := StringGrid1.Cells[4,x];
bed4 := StringGrid1.Cells[5,x];
end;
write(f,data);
end;
closefile(f);
Form2.Caption := '
Vokabelliste verwalten '+filep+'
';
updatehistory;
addhistory;
end;
procedure TForm2.Panel6Click(Sender: TObject);
var
f :
file of TData;
data : TData;
x,rows: integer;
endid :
string;
begin
if OpenDialog1.Execute
then begin
filep := OpenDialog1.FileName;
AssignFile(f,filep);
{$I-}
reset(f);
//Zeileanzahl auslesen
seek(f,FileSize(f)-2);
read(f,data);
rows := strtoint(data.ID);
x := 0;
while x <> rows
do begin
Stringgrid1.RowCount := StringGrid1.RowCount + 1;
inc(x);
end;
x := 0;
repeat
seek(f,x);
read(f,data);
StringGrid1.Cells[0,x+1] := data.Id;
StringGrid1.Cells[1,x+1] := data.fremd;
StringGrid1.Cells[2,x+1] := data.bed1;
StringGrid1.Cells[3,x+1] := data.bed2;
StringGrid1.Cells[4,x+1] := data.bed3;
StringGrid1.Cells[5,x+1] := data.bed4;
inc(x);
until x = 100;
{$I+}
end;
end;
procedure TForm2.updatehistory;
var
fh :
file of PData;
datap : PData;
x : integer;
begin
AssignFile(fh,'
C:\WINDOWS\voka_history.dat');
{$I-}
reset(fh);
x := 0;
repeat
seek(fh,x);
read(fh,datap);
inc(x);
until eof(fh);
label2.caption := inttostr(x);
{$I+}
end;
procedure TForm2.addhistory;
var
fh :
file of PData;
datap : PData;
y, posi,seekk : integer;
gefunden : boolean;
fname, filep :
string[100];
begin
filep := OpenDialog1.FileName;
//Name der ausgewählten Datei auslesen
pos('
.txt',filep);
y := 0;
repeat
inc(y);
posi := pos('
.txt',filep)-y;
until filep[posi] = '
\';
fname := copy(filep,length(filep)-y-2,y-1);
//copy(filep,)
gefunden := false;
seekk := 0;
AssignFile(fh,'
C:\WINDOWS\Voka_history.dat');
{$I-}
reset(fh);
repeat
seek(fh,seekk);
read(fh,datap);
if (POS(fname,Datap.
name) <> 0)
then begin
gefunden := true;
end;
inc(seekk);
until eof(fh)
or gefunden;
if not gefunden
then begin
seek(fh,FileSize(fh)-1);
with datap
do begin
pfad := filep;
name := fname;
end;
write(fh,datap);
closefile(fh);
end;
end;
end.