herculanojs Posted April 11, 2016 Posted April 11, 2016 I'm having trouble defining events in runtime. I saw in another post that the definition of the event must be made before the creation of the form, but the components are created dynamically, so you can not use the definition of code in the form creation. The code below works perfectly put in the form of creation, with the component already created. However when I create the component and attribute the event, it does not work. The event is for the UniEdit only accept numbers. Is there any other way to do it? All my form components are dynamically created. Exemple 1: component existing === OK!! procedure TMainForm.UniFormCreate(Sender: TObject); begin UniEdit1.ClientEvents.ExtEvents.Values['keypress']:='function keypress(sender, e, eOpts) {var allowed = "0123456789"; var c = e.getCharCode(); if (allowed.indexOf(String.fromCharCode©)=== -1) {e.stopEvent(); } }'; end; Exemple 2: component not existing === NO!! procedure TMainForm.UniButton1Click(Sender: TObject); var Edit:TuniEdit; begin edit := Tuniedit.Create(self); edit.Left := 8; edit.Top := 8; edit.Parent := self; edit.Visible := True; edit.ClientEvents.ExtEvents.Values['keypress']:='function keypress(sender, e, eOpts) {var allowed = "0123456789"; var c = e.getCharCode(); if (allowed.indexOf(String.fromCharCode©)=== -1) {e.stopEvent(); } }'; end; how to proceed ? Project1.rar Quote
Sherzod Posted April 11, 2016 Posted April 11, 2016 Hi, You must assign the Name...: procedure TMainForm.UniButton1Click(Sender: TObject); var Edit:TuniEdit; begin edit := Tuniedit.Create(self); edit.Left := 8; edit.Top := 8; edit.Parent := self; edit.Visible := True; -> edit.Name := 'myedit'; edit.ClientEvents.ExtEvents.Values['keypress']:='function keypress(sender, e, eOpts) {var allowed = "0123456789"; var c = e.getCharCode(); if (allowed.indexOf(String.fromCharCode(c))=== -1) {e.stopEvent(); } }'; end; Best regards. Quote
herculanojs Posted April 11, 2016 Author Posted April 11, 2016 that thing ... thank you so much Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.