unit Seite1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls, jpeg, ExtCtrls, ComCtrls, TabNotBk,
Buttons, iniFiles, Printers;
type
TForm1 =
class(TForm)
Hintergrund: TImage;
ueberschrift: TLabel;
eigenschaften: TGroupBox;
ltitel: TLabel;
tinterpret: TLabel;
tgroesse: TLabel;
tlaenge: TLabel;
titel: TEdit;
interpret: TEdit;
album: TEdit;
groesse: TEdit;
laenge: TEdit;
grid: TStringGrid;
operatoren: TGroupBox;
ein: TButton;
close: TBitBtn;
spei: TButton;
loeschen: TButton;
laden: TButton;
feld: TEdit;
Label1: TLabel;
talbum: TLabel;
sort: TComboBoxEx;
such: TEdit;
Suchen: TButton;
drucken: TButton;
procedure sortChange(Sender: TObject);
procedure druckenClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure einClick(Sender: TObject);
procedure speiClick(Sender: TObject);
procedure ladenClick(Sender: TObject);
procedure gridClick(Sender: TObject);
procedure feldChange(Sender: TObject);
procedure loeschenClick(Sender: TObject);
procedure SuchenClick(Sender: TObject);
procedure suchClick(Sender: TObject);
procedure GridCanSort(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1 : TForm1;
ini : TiniFile;
a,b,n,i,j,l : Integer;
t,z :
String;
sl,f1 : TStringlist;
ar :
array[0..1000]
of string;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
grid.Cells[0,0]:='
Titel';
grid.Cells[1,0]:='
Interpret';
grid.Cells[2,0]:='
Album';
grid.Cells[3,0]:='
Größe in mB';
grid.Cells[4,0]:='
Länge in min';
sort.Items.Add('
Titel');
sort.Items.Add('
Interpret');
sort.Items.Add('
Album');
sort.Items.Add('
Größe');
sort.Items.Add('
Länge');
end;
procedure TForm1.einClick(Sender: TObject);
begin
if grid.Cells[0,grid.RowCount-1]>'
'
then
begin
grid.RowCount:=grid.RowCount+1;
a:=grid.RowCount-1;
grid.Cells[0,a]:=titel.Text;
grid.Cells[1,a]:=interpret.Text;
grid.Cells[2,a]:=album.Text;
grid.Cells[3,a]:=groesse.Text;
grid.Cells[4,a]:=laenge.Text;
titel.SetFocus;
end
else
begin
a:=grid.RowCount-1;
grid.Cells[0,a]:=titel.Text;
grid.Cells[1,a]:=interpret.Text;
grid.Cells[2,a]:=album.Text;
grid.Cells[3,a]:=groesse.Text;
grid.Cells[4,a]:=laenge.Text;
grid.RowCount:=a+1;
titel.SetFocus;
end
end;
procedure TForm1.speiClick(Sender: TObject);
begin
a:=1;
n:=0;
b:=grid.RowCount-2;
t:='
t';
for n:=0
to 4
do
ini.EraseSection(t+IntToStr(n));
for a:=1
to b+1
do
for n:=0
to 4
do
ini.WriteString(t+IntToStr(n), IntToStr(a), grid.Cells[n,a]);
ShowMessage('
Speichervorgang war erfolgreich!');
end;
procedure TForm1.ladenClick(Sender: TObject);
begin
a:=1;
n:=0;
t:='
t';
begin
sl := TStringList.Create;
try
Ini.ReadSectionValues(t+IntToStr(0),sl);
b := sl.Count;
finally
FreeAndNil(sl);
end;
grid.RowCount:=b+1;
for a:=1
to b
do
for n:=0
to 4
do
grid.Cells[n,a]:=ini.ReadString(t+IntToStr(n), IntToStr(a), '
');
end;
ShowMessage('
Ladevorgang war erfolgreich!');
end;
procedure TForm1.GridCanSort(Sender: TObject);
var aCol: Integer;
dosort: Boolean;
begin
DoSort := ACol > 0;
end;
procedure TForm1.gridClick(Sender: TObject);
begin
feld.Text:=Grid.Cells[Grid.col, Grid.Row];
if (grid.Col=0)
or (grid.Col=1)
or (grid.Col=2)
or (grid.Col=3)
or (grid.Col=4)
then
GridCanSort;
end;
procedure TForm1.feldChange(Sender: TObject);
begin
grid.EditorMode:=true;
Grid.Cells[Grid.col, Grid.Row]:=feld.Text;
end;
procedure TForm1.loeschenClick(Sender: TObject);
begin
a:=0;
b:=0;
if grid.RowCount>2
then
begin
for b:=0
to grid.RowCount-2
do
for a:=0
to 4
do
grid.Cells[Grid.Col+a, Grid.Row+b]:=grid.Cells[Grid.Col+a, Grid.Row+1+b];
grid.RowCount:=grid.RowCount-1;
end
else
for a:=0
to 4
do
grid.Cells[0+a,1]:='
';
end;
procedure TForm1.SuchenClick(Sender: TObject);
begin
i:=0;
j:=0;
for i:=0
to 5
do
for j:=0
to grid.RowCount-1
do
if grid.Cells[i,j]=such.Text
then
begin
grid.Col:=i;
grid.Row:=j;
grid.SetFocus;
end;
if feld.Text=such.Text
then
such.Text:='
Gefunden!'
else
such.Text:='
kein Eintrag';
such.SetFocus;
end;
procedure TForm1.suchClick(Sender: TObject);
begin
such.SelectAll;
end;
(* Druckalgorithmus von capo (Benutzer von Delphi-PRAXiS Forum)
Web-Link: [url]http://www.delphipraxis.net/topic113547.html[/url] *)
procedure PrintStringGrid(Grid: TStringGrid; Title:
string;
Orientation: TPrinterOrientation);
var
P, I, J, YPos, XPos, HorzSize, VertSize: Integer;
AnzSeiten, Seite, Zeilen, HeaderSize, FooterSize, ZeilenSize, FontHeight: Integer;
mmx, mmy: Extended;
Footer:
string;
begin
//Kopfzeile, Fußzeile, Zeilenabstand, Schriftgröße festlegen
HeaderSize := 100;
FooterSize := 200;
ZeilenSize := 50;
FontHeight := 31;
//Printer initializieren
Printer.Orientation := Orientation;
Printer.Title := Title;
Printer.BeginDoc;
//Druck auf mm einstellen
mmx := GetDeviceCaps(Printer.Canvas.Handle, PHYSICALWIDTH) /
GetDeviceCaps(Printer.Canvas.Handle, LOGPIXELSX) * 25.4;
mmy := GetDeviceCaps(Printer.Canvas.Handle, PHYSICALHEIGHT) /
GetDeviceCaps(Printer.Canvas.Handle, LOGPIXELSY) * 25.4;
VertSize := Trunc(mmy) * 10;
HorzSize := Trunc(mmx) * 10;
SetMapMode(Printer.Canvas.Handle, MM_LOMETRIC);
//Zeilenanzahl festlegen
Zeilen := (VertSize - HeaderSize - FooterSize)
div ZeilenSize;
//Seitenanzahl ermitteln
if Grid.RowCount
mod Zeilen <> 0
then
AnzSeiten := Grid.RowCount
div Zeilen + 1
else
AnzSeiten := Grid.RowCount
div Zeilen;
Seite := 1;
//Grid Drucken
for P := 1
to AnzSeiten
do
begin
//Kopfzeile
Printer.Canvas.Font.Height := 50;
Printer.Canvas.TextOut((HorzSize
div 2 - (Printer.Canvas.TextWidth(Title)
div 2)),
- 20,Title);
Printer.Canvas.Pen.Width := 3;
Printer.Canvas.MoveTo(0, - HeaderSize);
Printer.Canvas.LineTo(HorzSize, - HeaderSize);
//Fußzeile
Printer.Canvas.Pen.Width := 0;
Printer.Canvas.Pen.Style := psclear;
Printer.Canvas.MoveTo(0, - VertSize + FooterSize);
Printer.Canvas.LineTo(HorzSize, - VertSize + FooterSize);
Printer.Canvas.Font.Height := 36;
Footer := '
Seite: ' + IntToStr(Seite) + '
von ' + IntToStr(AnzSeiten);
Printer.Canvas.TextOut((HorzSize
div 2 - (Printer.Canvas.TextWidth(Footer)
div 2)),
- VertSize + 150,Footer);
//Zeilen drucken
Printer.Canvas.Font.Height := FontHeight;
YPos := HeaderSize + 50;
for I := 1
to Zeilen
do
begin
if Grid.RowCount >= I + (Seite - 1) * Zeilen
then
begin
XPos := 280;
for J := 0
to Grid.ColCount - 1
do
begin
Printer.Canvas.TextOut(XPos, - YPos,
Grid.Cells[J, I + (Seite - 1) * Zeilen - 1]);
XPos := XPos + Grid.ColWidths[J] * 3;
end;
YPos := YPos + ZeilenSize;
end;
end;
//Seite hinzufügen
Inc(Seite);
if Seite <= AnzSeiten
then Printer.NewPage;
end;
Printer.EndDoc;
end;
// <-- Print Procedure
procedure TForm1.druckenClick(Sender: TObject);
var i:integer ;
begin
i:=0;
if i>0
then
begin
grid.RowCount:=grid.rowcount+1;
end;
i:=i+1;
PrintStringGrid(grid, '
Musik-Datenbank', poPortrait);
end;
procedure TForm1.sortChange(Sender: TObject);
begin
if sort.ItemIndex=1
then
end;
initialization
ini := TIniFile.Create(ExtractFilePath( ParamStr(0))+'
data.ini');
finalization
ini.Free;
end.