unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Main,
DB, ZAbstractRODataset, ZAbstractDataset, ZDataset,
StdCtrls, ExtCtrls;
type
TForm1 =
class(TForm)
ScrollBox1: TScrollBox;
Panel1: TPanel;
Query1: TZQuery;
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject;
var Action: TCloseAction);
private
{ Private-Deklarationen }
procedure LabelClick(Sender: TObject);
procedure FreeLabels;
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.LabelClick(Sender: TObject);
begin
if (Sender
is TLabel)
then
begin
with Query1
do
begin
Close;
SQL.Clear;
SQL.Add('
SELECT Nachricht FROM Nachrichten WHERE ID = :id');
ParamByName('
id').AsInteger := TLabel(Sender).Tag;
Open;
First;
ShowMessage(FieldByName('
Nachricht').AsString);
end;
end;
end;
procedure TForm1.FreeLabels;
var i: integer;
begin
for i := 0
to ScrollBox1.ComponentCount - 1
do
if ScrollBox1.Components[i]
is TLabel
then
TLabel(ScrollBox1.Components[i]).Free;
end;
procedure TForm1.FormShow(Sender: TObject);
var aLabel: TLabel;
aTop: integer;
begin
aTop := 10;
with Query1
do
begin
Close;
SQL.Clear;
SQL.Add('
SELECT ID, Betreff FROM Nachrichten ORDER BY Nachricht');
Open;
First;
while not EOF
do
begin
aLabel := TLabel.Create(self);
aLabel.Parent := ScrollBox1;
aLabel.Left := 10;
aLabel.Top := aTop;
aLabel.Tag := FieldByName('
ID').AsInteger;
aLabel.Caption := FieldByName('
Betreff').AsString;
aLabel.OnClick := LabelClick;
inc(aTop,15);
Next;
end;
end;
end;
procedure TForm1.FormClose(Sender: TObject;
var Action: TCloseAction);
begin
FreeLabels;
end;
end.