Graphic Delphi

Title: Improved DBEdit with ColorOnFocus,EnterLikeTab,UpperCase,LowerCase etc
Question: How to improve edit controls for ColorOnFocus, EnterLikeTab etc.
Answer:
TBlDBEdit is descendand from TDBEdit with additional properties:
------------------------------------------------------------------
CaseMode
cmNormal - inputting char is not converted
cmProperCase - first char of each word after inputting is
converted to uppercase
cmLowerCase - all inputting chars is converted to lowercase
cmUpperCase - all inputting chars is converted to uppercase
default: cmProperCase
------------------------------------------------------------------
ColorOnFocus - color of focused field (unfocused field has color
assigned in Color property) default: clYellow
------------------------------------------------------------------
CursorEndField - cursor stay at end of focused field (only if
Autoselect property is false !)
default: True (Warning! Autoselect is default False)
------------------------------------------------------------------
EnterLikeTab - key Enter moving focus like key Tab default: True
==================================================================
unit BlDBEdit;
interface
uses
{$IFDEF VER80}
WinTypes, WinProcs,
{$ELSE}
Windows,
{$ENDIF}
Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
DBCtrls;
type
TCaseMode = (cmNormal, cmProperCase, cmLowerCase, cmUpperCase);
TBlDBEdit = class(TDBEdit)
private
{ Private declarations }
FCase : TEditCharCase;
FCaseMode : TCaseMode;
FCursorEndField : Boolean;
FOnEnter : TNotifyEvent;
FOnExit : TNotifyEvent;
FOnFocusColor : TColor;
FOnNotFocusColor : TColor;
FEnterLikeTab : Boolean;
protected
{ Protected declarations }
procedure KeyPress(var Key: Char); override;
procedure DoEnter; override;
procedure DoExit; override;
public
{ Public declarations }
constructor Create(AOwner : TComponent); override;
published
{ Published declarations }
{ excluding from Object Inspector property CharCase }
property CharCase : TEditCharCase read FCase;
property CaseMode : TCaseMode read FCaseMode
write FCaseMode;
property CursorEndField : boolean read FCursorEndField
write FCursorEndField;
property OnEnter : TNotifyEvent read FOnEnter
write FOnEnter;
property OnExit : TNotifyEvent read FOnExit
write FOnExit;
property ColorOnFocus : TColor read FOnFocusColor
write FOnFocusColor;
property EnterLikeTab : Boolean read FEnterLikeTab
write FEnterLikeTab;
end;
procedure Register;
implementation
constructor TBlDBEdit.Create(AOwner : TComponent);
begin
inherited Create(AOwner);
AutoSelect := False;
ColorOnFocus := clYellow;
FOnNotFocusColor := Color;
EnterLikeTab := True;
FCase := ecNormal;
CaseMode := cmProperCase;
CursorEndField := True;
end;
procedure TBlDBEdit.KeyPress(var Key: Char);
var
{$IFDEF VER100}
FEditTemp : TCustomForm;
{$ELSE}
FEditTemp : TForm;
{$ENDIF}
begin
if (Key = #13) and FEnterLikeTab then begin
FEditTemp := GetParentForm(Self);
SendMessage(FEditTemp.Handle, WM_NEXTDLGCTL, 0, 0);
Key := #0;
exit;
end;
case CaseMode of
cmProperCase : begin
if (SelStart = 0) or (Text[SelStart] = ' ') then
Key := AnsiUpperCase(Key)[1];
end;
cmUpperCase : begin
Key := AnsiUpperCase(Key)[1];
end;
cmLowerCase : begin
Key := AnsiLowerCase(Key)[1];
end;
end;
inherited KeyPress(Key);
end;
procedure TBlDBEdit.DoEnter;
begin
Color := ColorOnFocus;
if CursorEndField and not AutoSelect then
SelStart := GetTextLen;
if Assigned(FOnEnter) then
FOnEnter(Self);
end;
procedure TBlDBEdit.DoExit;
begin
Color := FOnNotFocusColor;
if Assigned(FOnExit) then
FOnExit(Self);
end;
procedure Register;
begin
RegisterComponents('Extra', [TBlDBEdit]);
end;
end.