procedure CreateDynamicDetailPage(AOwner:TwinControl; ds:TDataSource; labelalignment:TAlignment);
const
XPOS_LABELS = 5;
XPOS_CONTROLS = 130;
SPACING_CONTROLS = 1;
NAME_DBCONTROL = '
DBControl_';
NAME_LABEL = '
LblField_';
var
i: Integer;
y: Integer;
c,lbl: TControl;
fd: TFieldDef;
dataset : TDataSet;
begin
Assert(Assigned(AOwner));
Assert(Assigned(ds));
// Falls die DB-Elemente schon angelegt worden sind, erst mal löschen
KillDynamicDetailPage(AOwner);
dataset := ds.DataSet;
if not Assigned(dataset)
then
Exit;
y := SPACING_CONTROLS;
for i := 0
to dataset.FieldDefs.Count-1
do
begin
c :=
nil;
fd := dataset.FieldDefs[i];
case fd.DataType
of
ftString,ftFixedChar,ftWideString,
ftSmallint,ftInteger,ftWord,
ftFloat,ftCurrency,ftBCD,
ftDate,ftTime,ftDateTime:
begin
c := TDBEdit.Create(AOwner);
with TDBEdit(c)
do
begin
Name := NAME_DBCONTROL+IntToStr(i);
DataSource := ds;
DataField := fd.
Name;
end;
if fd.DataType
in [ftSmallint,ftInteger,ftWord,ftDate,ftTime]
then
c.Width := 80
else if fd.DataType
in [ftFloat,ftCurrency,ftBCD]
then
c.Width := 80
else if fd.DataType
in [ftDateTime]
then
c.Width := 120
else
c.Width := 300;
end;
ftBoolean:
begin
c := TDBCheckBox.Create(AOwner);
with TDBCheckBox(c)
do
begin
Name := NAME_DBCONTROL+IntToStr(i);
DataSource := ds;
DataField := fd.
Name;
Caption := '
';
end;
end;
ftMemo:
begin
c := TDBMemo.Create(AOwner);
with TDBMemo(c)
do
begin
Parent := AOwner;
WordWrap := False;
ScrollBars := ssBoth;
Name := NAME_DBCONTROL+IntToStr(i);
DataSource := ds;
DataField := fd.
Name;
end;
c.Width := 300;
c.Height := 100;
end;
else
begin
c := TLabel.Create(AOwner);
with TLabel(c)
do
begin
Name := NAME_DBCONTROL+IntToStr(i);
Caption := '
??? (' + GetEnumName(TypeInfo(TFieldType),Ord(fd.DataType)) + '
)';
end;
end;
end;
if Assigned(c)
then
begin
// create a Label for the control
c.Top := y;
c.Left := XPOS_CONTROLS;
if not (c
is TDBMemo)
then
AOwner.InsertControl(c);
lbl := TLabel.Create(AOwner);
with TLabel(lbl)
do
begin
Name := NAME_LABEL+IntToStr(i);
Top := y+2;
// Labels are smaller than DB-conrols
if labelalignment= taRightJustify
then
begin
Left := 0;
Width := XPOS_CONTROLS-5;
AutoSize := False;
Alignment := labelalignment;
end
else
Left := XPOS_LABELS;
// Caption := fd.Name;
Caption := fd.DisplayName;
end;
AOwner.InsertControl(lbl);
y := y + c.Height + SPACING_CONTROLS;
end;
end;
end;
{**************************************************************************
* NAME: KillDynamicDetailPage
* DESC: Zum Abräumen der mit CreateDynamicDetailPage erstellten Controls
* PARAMS: [-]
* CREATED: 08-04-2004/shmia
* CHANGED: 00-00-2004/shmia
*************************************************************************}
procedure KillDynamicDetailPage(AOwner:TWinControl);
const
NAME_DBCONTROL = '
DBControl_';
NAME_LABEL = '
LblField_';
var
i: Integer;
c : TControl;
begin
Assert(Assigned(AOwner));
for i := AOwner.ControlCount-1
downto 0
do
begin
c := AOwner.Controls[i];
if (Pos(NAME_DBCONTROL,c.
Name) > 0)
or (Pos(NAME_LABEL,c.
Name) > 0)
then
c.Free;
end;
end;