Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread OnChange - does not fire when dataset / field bound
Tue, Oct 8 2024 5:26 AMPermanent Link

Walter Matte

Tactical Business Corporation

In 3.02 b9   (this used to work in 2.xx)

The OnChange Event - simple example below work

I just tested with TEdit but I assume it does not fire for other controls.

Edit1.Text := Uppercase(Edit1.Text);
// This will show for every keystroke.


Does anyone have a work around - or how to know when a change has been made to a bound data field???

Walter
Tue, Oct 8 2024 8:07 AMPermanent Link

erickengelke

Avatar

Walter Matte wrote:

In 3.02 b9   (this used to work in 2.xx)

> The OnChange Event - simple example below work
>I just tested with TEdit but I assume it does not fire for other controls.
> Edit1.Text := Uppercase(Edit1.Text);

I'm surprised you are seeing this.  I use OnChange a lot with bound fields.

You may have a recursion problem, you are changing Edit1.Text whenever Edit1.Text changes.... not good.

// This will show for every keystroke.
OnKeyUp is a good choice if you want to post process after a key is pressed.  But it amy not catch cut and paste.

or with OnKeyPress you can change the characters as they are entered.  ch := uppercase( ch ) ...

Good luck
EWB Programming Books and Nice Component Library
See my EWB BLOG posts, at:
http://www.erickengelke.com
Wed, Oct 9 2024 5:22 AMPermanent Link

Walter Matte

Tactical Business Corporation

You are correct - there must be a recursion issue.

But on the Key Press - you cannot alter the key.

If I do an uppercase statement you get an error.  And it I try to hard code a key - it is not used.

function TfrmConfig.edNameKeyPress(Sender: TObject; Key: Char; ShiftKey: Boolean;
                                  CtrlKey: Boolean;
                                  AltKey: Boolean): Boolean;
begin
 // Key := Uppercase(key);  [Error] ufrmConfig.wbs (155,11): Invalid expression type found, expected character or variant

 Key := 'X';

 result := true;
end;
Wed, Oct 9 2024 5:37 AMPermanent Link

Ralf Mimoun

Uppercase() gives you a string, but you need a char. Convert it, and you should be fine - except that changes of the parameter "Key" won't be visible after the event code is finished, because it's not a var parameter (have to check if EWB even has var params, they are quite unique to "real" Pascal/Delphi).

What about something more brute force like

if Edit1.Text <> Uppercase(Edit1.Text) then Edit1.Text := Uppercase(Edit1.Text);

That should always result in two event calls max. And yes, it's not a beauty Smile
Thu, Oct 10 2024 5:52 AMPermanent Link

Walter Matte

Tactical Business Corporation

While the field is databound -


procedure TfrmConfig.edNameChange(Sender: TObject);
begin
//   Window.alert('x-'+edName.Text);   // show correct input
 edName.Text := Uppercase(edName.Text);   // DOES NOT WORK

 SysCtrl.Columns['Name'].AsString :=  Uppercase(edName.Text);    // This works as I want
                                                                                                           // force uppercase input as user types.
end;


Walter
Image