Board index » delphi » Linking all edits to one OnEnter event.

Linking all edits to one OnEnter event.

Hi,

How can I link all TDBEdit and TBBLookups to one single OnEnter and OnExit
event at runtime.

The reason for doing this is that I want to change the color of the TDBEdit
or TDBLookup when the user enters it.
The problem that I run into is that when I link it to one event I don't know
which TDBedit I have to change the color for.

Can somebody help me out.

Thanks in advance.

Marco

 

Re:Linking all edits to one OnEnter event.


Hi Marco,

You can do something like this:

procedure TForm1.DBEdit1Enter(Sender: TObject);
begin
  If Sender Is TDBEdit Then Begin
     With Sender As TDBEdit Do Begin
        Color := clRed ;
        Font.Color := clWhite ;
     End;
  End;
end;

procedure TForm1.DBEdit1Exit(Sender: TObject);
begin
  If Sender Is TDBEdit Then Begin
     With Sender As TDBEdit Do Begin
        Color := clWindow ;
        Font.Color := clWindowText ;
     End;
  End;
end;

Regards,
-Steve-

Quote
"Marco Purmer" <m.pur...@quicknet.nl> wrote in message news:3a5b8394_1@dnews...

Hi,

How can I link all TDBEdit and TBBLookups to one single OnEnter and OnExit
event at runtime.

The reason for doing this is that I want to change the color of the TDBEdit
or TDBLookup when the user enters it.
The problem that I run into is that when I link it to one event I don't know
which TDBedit I have to change the color for.

Can somebody help me out.

Thanks in advance.

Marco

Re:Linking all edits to one OnEnter event.


Quote
Marco Purmer <m.pur...@quicknet.nl> wrote in message

news:3a5b8394_1@dnews...

Quote
> Hi,

> How can I link all TDBEdit and TBBLookups to one single OnEnter and OnExit
> event at runtime.

> The reason for doing this is that I want to change the color of the
TDBEdit
> or TDBLookup when the user enters it.
> The problem that I run into is that when I link it to one event I don't
know
> which TDBedit I have to change the color for.

procedure TForm1.DBEdit1Enter(Sender: TObject);
begin
  (Sender as TDBEdit).Color := clRed;
end;

procedure TForm1.DBEdit1Exit(Sender: TObject);
begin
  (Sender as TDBEdit).Color := clWhite;
end;

you'll need to hook up the necessary OnEnter and OnExit events using the
Object Inspector at design time.

--
Do you like me for my brain or my baud?
Jazz is not dead, it just smells funny. - Frank Zappa
ICQ: 91418899
http://www.planeted.co.uk
http://members.nbci.com/edduffe

Re:Linking all edits to one OnEnter event.


I wrote a MyDBEdit component for you...Take the code below and save it in
MyDBEdit.pas file.. Then in delphi install the component.. if you want to do
the same thing for TDBlookup just change every DBEdit word in the code with
DBlookup...You can also do this for TEdit , TCombobox etc...

Regards,
Ahmet Tasatmaz

unit MyDBEdit;

interface

uses Windows,Messages,SysUtils,Classes,StdCtrls,Graphics,
     Controls,Forms,Dialogs,Menus,DbCtrls;

type
  TMyDBEdit=class(TDBEdit)
private
  FocusColor:TColor;
  UnFocusColor:TColor;
  bEnter:Boolean;
  KDown:Boolean;
protected
  procedure DoEnter; override;
  procedure DoExit; override;
  procedure Keypress(var Key:Char); override;
  procedure KeyDown(var Key:Word; Shift:TShiftState); override;
public
  constructor Create(AOwner:TComponent);override;
  destructor Destroy; override;
published
  property ColorOnFocus:TColor read FocusColor write FocusColor;
  property ColorOnNotFocus:TColor read UnFocusColor write UnFocusColor;
  property AllowEnter:Boolean read bEnter write bEnter;
  property UpDown:Boolean read KDown write KDown;
end;

procedure Register;

implementation

constructor TMyDBEdit.Create(AOwner:TComponent);
begin
  inherited Create(AOwner);
  ColorOnFocus:=clInfobk;
  ColorOnNotFocus:=clWindow;
  Color:=ColorOnNotFocus;
  AllowEnter:=True;
  UpDown:=False;
end;

destructor TMyDBEdit.Destroy;
begin
  inherited destroy;
end;

procedure TMyDBEdit.KeyDown(var Key :Word;Shift:TShiftState);
var
  FormMyDBEdit:TCustomForm;
begin
  inherited KeyDown(Key,Shift);
  if UpDown then
  begin
    Case Key of
      VK_UP : begin
                FormMyDBEdit:=GetParentForm(Self);
                SendMessage(FormMyDBEdit.Handle,WM_NEXTDLGCTL,1,0);
                Key:=0;
              end;
      VK_DOWN:begin
                FormMyDBEdit:=GetParentForm(Self);
                SendMessage(FormMyDBEdit.Handle,WM_NEXTDLGCTL,0,0);
                Key:=0;
              end;
    end;
  end;
end;

procedure TMyDBEdit.KeyPress(var Key:Char);
var
  FormMyDBEdit:TCustomForm;
begin
  inherited KeyPress(Key);
  if AllowEnter then
    if Key=#13 then
    begin
      FormMyDBEdit:=GetParentForm(Self);
      SendMessage(FormMyDBEdit.Handle,WM_NEXTDLGCTL,0,0);
      Key:=#0;
    end;
end;

procedure TMyDBEdit.DoEnter;
begin
  inherited DoEnter;
  Color:=ColorOnFocus;
end;
procedure TMyDBEdit.DoExit;
begin
  inherited DoExit;
  Color:=ColorOnNotFocus;
end;

procedure Register;
begin
  RegisterComponents('Ahmet',[TMyDBEdit]);
end;

end.

--
-----------------------------------------------------
Click here for Free Video!!
http://www.gohip.com/free_video/

Quote
Marco Purmer <m.pur...@quicknet.nl> wrote in message

news:3a5b8394_1@dnews...
Quote
> Hi,

> How can I link all TDBEdit and TBBLookups to one single OnEnter and OnExit
> event at runtime.

> The reason for doing this is that I want to change the color of the
TDBEdit
> or TDBLookup when the user enters it.
> The problem that I run into is that when I link it to one event I don't
know
> which TDBedit I have to change the color for.

> Can somebody help me out.

> Thanks in advance.

> Marco

Re:Linking all edits to one OnEnter event.


Don't do that. Or at least consider another solutions. Handle
Application.OnActiveControlChange that is what i usually do...

Re:Linking all edits to one OnEnter event.


"Marco Purmer" <m.pur...@quicknet.nl> skrev i en meddelelse
news:3a5b8394_1@dnews...

Quote
> Hi,

> How can I link all TDBEdit and TBBLookups to one single OnEnter and OnExit
> event at runtime.

> The reason for doing this is that I want to change the color of the
TDBEdit
> or TDBLookup when the user enters it.
> The problem that I run into is that when I link it to one event I don't
know
> which TDBedit I have to change the color for.

> Can somebody help me out.

procedure TForm1.DBEdit1Enter(Sender: TObject);
begin
  if (Sender is TDBEdit) then
    (Sender as TDBEdit).Color := clRed;
  else
  if (Sender is TDBLookupListBox) then
    (Sender as TDBLookupListBox).Color := clRed;
end;

procedure TForm1.DBEdit1Exit(Sender: TObject);
begin
  if (Sender is TDBEdit) then
    (Sender as TDBEdit).Color := clWindow;
  else
  if (Sender is TDBLookupListBox) then
    (Sender as TDBLookupListBox).Color := clWindow;
end;

Other Threads