Re: How to detect clicking of TEdit?

From: Bruce Roberts (ber_at_bounceitattcanada.xnet)
Date: 09/07/04


Date: Tue, 7 Sep 2004 11:51:17 -0400


"Vertuas" <vertuas@nospamcallistocs.freeserve.co.uk> wrote in message
news:feA_c.86$di1.1@newsfe3-gui.ntli.net...
> I am working on on a touch screen application and nedd to implement text
> entry via an onscreen keyboard.
>
> My keyboard is just a TPanel with lots on buttons on it. the button makes
> letters, etc appear in the capion of a TLabel
>
> I am using windows messages to get the text from an the the tedit
> components. Messages WM_GETTEXT and WM_SETTEXT from within the keyboard's
> panel
>
> the problem that i now have if detecting when a TEdit recieves focus, but
i
> cannot use a normal event as all of me TEdits are dynamically created.

You might want to consider a more Delphish solution. For example create a
form for the keyboard give it a BorderStyle of bsToolWindow and a FormStyle
of fsStayOnTop. Add a field of type tControl, lets call it CurrentEdit, to
the Public section of that form's declaration. Presuming that you are using
tSpeedButtons for the keys, give them all the same onClick handler that
looks something like: (This is rough, lots of refinement possible.)

procedure tKeyboardForm.ButtonClick(Sender: TObject);

var eBuf : string; lth : integer;

begin
Assert (Sender is tSpeedButton);
Assert (Assigned (CurrentEdit));
lth := 1024;
SetLength (eBuf, lth);
lth := CurrentEdit.Perform (wm_GetText, lth, Integer (eBuf));
SetLength (eBuf, lth);
eBuf := eBuf + tSpeedButton (Sender).Caption;
CurrentEdit.Perform (wm_SetText, 0, Integer (eBuf));
end;

Instead of using tEdit, create a descendant that makes life a little
simpler.

type
tBoundEdit = class (tEdit)
    protected
        procedure doEnter; override;
    public
        constructor Create (aOwner : tComponent); override;
    end;

constructor tBoundEdit.Create (aOwner : tComponent);

begin
inherited;
Assert (Assigned (KeyboardUnit.KeyboardForm), 'Keyboard form has to be
created first.');
FreeNotification (KeyboardUnit.KeyboardForm);
end;

procedure tBoundEdit.doEnter;

begin
inherited;
KeyboardUnit.KeyboardForm.CurrentEdit := Self;
end;

You will also want to provide an override of the keyboard form's
Notification method. It will look something like

procedure tKeyboardForm.Notification (aComponent : tComponent; Operation :
tOperation);

begin
inherited;
if (Operation = opRemove) and (aComponent = CurrentEdit)
then CurrentEdit := nil;
end;