so, hab geschaut. TCustomEdit hat die Methode "Change". Diese also überschreiben (darin die Farbe setzen) und dann inherited.
@mkinzler: Wie ich gerade sehe hast du auch vergessen die Farben zu initialisieren mit standardwerten.
Delphi-Quellcode:
type
TEdit = class(StdCtrls.TEdit)
protected
fCheckEmpty: Boolean;
fEmptyColor: TColor;
fNonEmptyColor: TColor;
procedure Change; override;
procedure FSetCheckEmpty(AValue: Boolean);
procedure FSetColor(AType: Integer; AColor: TColor);
public
constructor Create(AOwner: TComponent); override;
published
property CheckEmpty: Boolean read fCheckEmpty write fSetCheckEmpty default True;
property ColorEmpty: TColor Index 0 read fEmptyColor write FSetColor;
property ColorNonEmpty: TColor Index 1 read fNonEmptyColor write FSetColor;
end;
[...]
constructor TEdit.Create(AOwner: TComponent);
begin
fCheckEmpty := True;
fEmptyColor := clBlue;
inherited Create(AOwner);
fNonEmptyColor := Color;
Change;
end;
procedure TEdit.Change;
var LColor: TColor;
begin
if fCheckEmpty then
begin
if Self.Text = '' then
LColor := fEmptyColor
else
LColor := fNonEmptyColor;
end else
LColor := fNonEmptyColor;
if LColor <> Color then
Color := LColor;
inherited;
end;
procedure TEdit.FSetCheckEmpty(AValue: Boolean);
begin
if AValue <> fCheckEmpty then
begin
fCheckEmpty := AValue;
Change;
end;
end;
procedure TEdit.FSetColor(AType: Integer; AColor: TColor);
procedure LSetVal(var ACurrVal: TColor);
begin
if (ACurrVal <> AColor) then
begin
ACurrVal := AColor;
if fCheckEmpty then
Change;
end;
end;
begin
case AType of
0: LSetVal(fEmptyColor);
1: LSetVal(fNonEmptyColor);
end;
end;