Recent

Author Topic: Handling User Paste in TEdit  (Read 5693 times)

99Percent

  • Full Member
  • ***
  • Posts: 160
Handling User Paste in TEdit
« on: November 05, 2011, 07:12:06 pm »
Lets say we have a TEdit component that should only have numeric characters 0..9. I can trap keystrokes that aren't numeric with the OnKeyPress event, converting them to #0 easily enough.

But if the user copies and paste text, the TEdit object will accept all the characters. I can intercept the Ctrl-V and then filter the Clipboard.Text accordingly, but I don't see how I can intercept a mouse paste.

Somewhere in the object, LCL is accepting this input into the textbox, but I can't see how.

An OnPaste (even better, OnBeforePaste and OnAfterPaste) would be very convenient to have as properties no?

Avishai

  • Hero Member
  • *****
  • Posts: 1021
Re: Handling User Paste in TEdit
« Reply #1 on: November 05, 2011, 07:17:26 pm »
Can you use the OnChange event?  I did not try, but I think it can work.
Lazarus Trunk / fpc 2.6.2 / Win32

souppatin

  • Newbie
  • Posts: 6
Re: Handling User Paste in TEdit
« Reply #2 on: November 22, 2011, 09:58:08 am »
have you try OnContextPopup ?   :D

zeljko

  • Hero Member
  • *****
  • Posts: 1594
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Handling User Paste in TEdit
« Reply #3 on: November 22, 2011, 10:57:09 am »
And what if user paste something via middle button (X11 selection) , how will you intercept Ctrl+V ? ;)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Handling User Paste in TEdit
« Reply #4 on: November 22, 2011, 01:59:11 pm »
What about being more relaxed and allowing all kinds of pasting - users can still change what they type while editing, anyway.

Then use OnEditingDone with a message to restrict the kind of values that are allowed.

Personnally, I hate fields such as telephone number edits that disallow the + symbol. If I want to paste a number with +, I can't, so I have to edit it elsewhere and then paste it.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Bart

  • Hero Member
  • *****
  • Posts: 5275
    • Bart en Mariska's Webstek
Re: Handling User Paste in TEdit
« Reply #5 on: November 23, 2011, 01:07:20 pm »
If the length of the text in the TEdit you expect allows for it, you can use a TMaskEdit with a mask like '999999999999999'
This will allow up to 15 "digits" in th econtrol.
It also handles past actions.

Bart

 

TinyPortal © 2005-2018