Thema: Delphi Forms und OOP

Einzelnen Beitrag anzeigen

Benutzerbild von dataspider
dataspider

Registriert seit: 9. Nov 2003
Ort: 04539 Groitzsch
1.350 Beiträge
 
Delphi 11 Alexandria
 
#8

Re: Forms und OOP

  Alt 25. Apr 2006, 19:31
Hi,

also, nicht alles muss in eine Basisklasse.
Das Einfärben der Editfelder lässt sich z.B. eleganter lösen:

Delphi-Quellcode:
unit EditColorHandler;

interface
Uses Forms, Classes, Controls, Graphics, StdCtrls;

Const
  _ActiveColor = $009BF5FD;
  _DefaultColor = clWhite;

type
  TEditColorHandler = class(TObject)
  private
    FActiveControl: TWinControl;
    FActive: Boolean;
    procedure SetActive(const Value: Boolean);
  public
    procedure doActiveControlChange(Sender: TObject);
    property Active: Boolean read FActive write SetActive;
  end;

Var
  AppEditColorHandler: TEditColorHandler;

implementation

procedure TEditColorHandler.doActiveControlChange(Sender: TObject);
begin
  if Assigned(FActiveControl) and FActiveControl.HandleAllocated and
    (FActiveControl is TEdit) then
    TEdit(FActiveControl).Color := _DefaultColor;

  FActiveControl := Screen.ActiveControl;

  if FActiveControl is TEdit then
    TEdit(FActiveControl).Color := _ActiveColor;

end;

procedure TEditColorHandler.SetActive(const Value: Boolean);
begin
  if FActive <> Value then
  begin
    FActive := Value;
    if FActive then
      Screen.OnActiveControlChange := doActiveControlChange
    else
      Screen.OnActiveControlChange := nil;
  end;
end;

initialization
  AppEditColorHandler := TEditColorHandler.Create;

finalization
  AppEditColorHandler.Free;

end.
die Unit in Uses des MainForm und an einer günstigen Stelle:

  AppEditColorHandler.Active := True;
Cu, Frank
Frank Reim
  Mit Zitat antworten Zitat