unit DBEditLabel;
interface
uses
SysUtils, Classes, Controls, StdCtrls, Mask, DBCtrls;
type
TDBEditLabel =
class(TDBEdit)
private
FCaption: WideString;
FLabel: TLabel;
procedure SetLabelPosition;
procedure SetCaption(Value: WideString);
protected
procedure SetParent(AParent: TWinControl);
override;
procedure SetName(
const Value: TComponentName);
override;
public
constructor Create(aOwner: TComponent);
override;
procedure SetBounds(ALeft: Integer; ATop: Integer; AWidth: Integer; AHeight: Integer);
override;
published
property DBEditCaption: WideString
read FCaption
write SetCaption;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('
Zusätzlich', [TDBEditLabel]);
end;
{ TDBEditLabel }
constructor TDBEditLabel.Create(aOwner: TComponent);
begin
inherited;
FLabel := TLabel.Create(aOwner);
end;
procedure TDBEditLabel.SetBounds(ALeft, ATop, AWidth, AHeight: Integer);
begin
inherited SetBounds(ALeft, ATop, AWidth, AHeight);
SetLabelPosition;
end;
procedure TDBEditLabel.SetCaption(Value: WideString);
begin
if Value <> FCaption
then
begin
FCaption := Value;
FLabel.Caption := Value;
end;
end;
procedure TDBEditLabel.SetLabelPosition;
begin
if FLabel <>
nil then
begin
FLabel.Top := Top - FLabel.Height - 5;
FLabel.Left := Left + 5;
end;
end;
procedure TDBEditLabel.SetName(
const Value: TComponentName);
begin
if (csDesigning
in ComponentState)
and ((FLabel.GetTextLen = 0)
or
(CompareText(FLabel.Caption,
Name) = 0))
then
FLabel.Caption := Value;
inherited SetName(Value);
if csDesigning
in ComponentState
then
Text := '
';
end;
procedure TDBEditLabel.SetParent(AParent: TWinControl);
begin
inherited;
FLabel.Parent := aParent;
end;
end.