Recent

Author Topic: Firing OnChange event  (Read 5542 times)

asyzard

  • New member
  • *
  • Posts: 9
Firing OnChange event
« on: May 27, 2013, 08:26:58 pm »
Hi.
Please someone could tell me, how is possible to call the OnChange event for multiple TEdit objects,
for example if whichever is changed then returns the Sender and with that calls the event?
And those TEdits are on a TabSheet not directly on the form.

Thanks.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Firing OnChange event
« Reply #1 on: May 27, 2013, 08:50:33 pm »
events are raised from the component you are not supposed to call them directly, the only exception is if you are writing a descendant component and you raise the event. You are free to call the event handlers though.
Each TEdit component can have its own event handler or all of them could be linked on a single handler or any combination of event handler and events you might need for that matter.

Now that I said that, I have no idea what you are trying to accomplish please give us a proper description of what you need to do.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

asyzard

  • New member
  • *
  • Posts: 9
Re: Firing OnChange event
« Reply #2 on: May 27, 2013, 11:05:00 pm »
Sorry, I will try to explain it better.
    I´m trying to make a fill out form, where I have five TEdit boxes, and I would like to run a function that checks the input, and if contains invalid characters, then returns false. I don't want to make separate procedures (OnChange) for each TEdit so here comes my question.
    How is possible to make, that the change of any of those TEdit boxes would run my validate function for the proper TEdit (for the one that I'm currenty editing)?

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Firing OnChange event
« Reply #3 on: May 27, 2013, 11:11:25 pm »
Code: [Select]
TEdit(Sender).TEditMethodOrProperty;

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Firing OnChange event
« Reply #4 on: May 27, 2013, 11:13:48 pm »
You double click on the edit1 onChange event on the object inspector to create the handler procedure.
Then you write your code something along the lines of

Code: [Select]
procedure TForm1.Edit1Change(Sender : TObject);
begin
  if sender is TEdit then begin
    if Validate(TEdit(Sender).Text) then showMessage('All is Well')
    else ShowMessage('You stupid blond wanna be, get your act together');
  end;
end; 

after you have finished the select edit2 and in the object inspector instead of double clicking just drop down the combo box list and select the Edit1Change procedure repeat with the rest of the edit controls, this will force all controls to call the same handler.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Firing OnChange event
« Reply #5 on: May 27, 2013, 11:33:46 pm »
You double click on the edit1 onChange event...
...in the object inspector instead of double clicking just drop down the combo box list and select the Edit1Change procedure repeat with the rest of the edit controls, this will force all controls to call the same handler.

Even quicker is to select all the edit controls in the Object Inspector first. Then you can set the common event handler just once using the dropdown combo, without needing to repeat the action for every control.

asyzard

  • New member
  • *
  • Posts: 9
Re: Firing OnChange event
« Reply #6 on: May 27, 2013, 11:34:21 pm »
Thanks for help!  :D

geno

  • Full Member
  • ***
  • Posts: 198
Re: Firing OnChange event
« Reply #7 on: May 27, 2013, 11:35:14 pm »
Quote
else ShowMessage('You stupid blond wanna be, get your act together')
;

Oh, so we all must be Racially/Ethnically/Culturally sensitive these days, and any type of profiling creates an uproar, however we blondes can still be the target of dumb jokes??  Ok, so I am more grey than blonde, but still...

just kidding (except about the grey) :D

  regards,
     geno
version:      Lazarus 1.9   FPC 3.0.4
   
widget set:  x-86_64-linux-gtk 2
OS:             ArchLinux/ Xfce 4.12

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Firing OnChange event
« Reply #8 on: May 28, 2013, 12:13:46 am »
Well the Racially/Ethnically/Culturally stereotypes are different from country to country, blonds on the other side are a common value in every culture I have experience with. :P

Just in case this is misunderstood I apologize in advance, I was in the mood for a silly message nothing more.
 
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

geno

  • Full Member
  • ***
  • Posts: 198
Re: Firing OnChange event
« Reply #9 on: May 28, 2013, 03:48:49 am »
@taazz

  No apology necessary, my friend;  I enjoy the humour as well.  I was merely attempting to evoke a response from other members.
  And of course, there is nothing wrong with a good blonde joke, or three.   There was a time when I had one on hand for every occasion, sadly however, in this Politically Correct climate we all live in now, its dangerous just telling them to oneself!!  :)


  regards,
    geno
version:      Lazarus 1.9   FPC 3.0.4
   
widget set:  x-86_64-linux-gtk 2
OS:             ArchLinux/ Xfce 4.12

 

TinyPortal © 2005-2018