ravedadave Posted June 29, 2020 Posted June 29, 2020 Hi, I am trying to count the characters entered into a TUniMemo box as they are typed, All the KeyPress functions do not work correctly, can anyone recommend another way of doing it accurately ? Thanks, Dave. Quote
Sherzod Posted June 29, 2020 Posted June 29, 2020 10 minutes ago, ravedadave said: I am trying to count the characters entered into a TUniMemo box as they are typed Hi, Sorry, for what purpose do you want to use it? Quote
ravedadave Posted June 29, 2020 Author Posted June 29, 2020 53 minutes ago, Sherzod said: Hi, Sorry, for what purpose do you want to use it? Hi, Thanks for the reply. So I need to count the characters entered into an TUniMemo (i.e. You have entered 64 characters of 160) it's for sending an SMS Text to let the end user know when they are reaching the length of the maximum text. Quote
mierlp Posted June 29, 2020 Posted June 29, 2020 Hi, Take a look at my example of sending text messages, I think that's what it is all about Quote
Sherzod Posted June 29, 2020 Posted June 29, 2020 56 minutes ago, ravedadave said: So I need to count the characters entered into an TUniMemo (i.e. You have entered 64 characters of 160) it's for sending an SMS Text to let the end user know when they are reaching the length of the maximum text. Ok. It is better to use a client-side solution. For example: 1. UniLabel, UniMemo1 2. UniMemo1.ClientEvents.UniEvents: function beforeInit(sender, config) { config.enforceMaxLength = true; config.maxLength = 160; } 3. UniMemo1.ClientEvents.ExtEvents: function keyup(sender, e, eOpts) { MainForm.UniLabel1.setText('You have entered '+ sender.getValue().length +' characters of 160'); } 4. procedure TMainForm.UniFormReady(Sender: TObject); begin UniLabel1.JSInterface.JSCode(#1'.setText(''You have entered ''+'+ UniMemo1.JSName +'.getValue().length + '' characters of 160'');'); end; Quote
mierlp Posted June 29, 2020 Posted June 29, 2020 procedure TMainForm.UniMemoChange(Sender: TObject); begin uniLabel_Char.Caption := IntToStr(Length(StringReplace(StringReplace(UniMemo. Lines.Text, #10, '', [rfReplaceAll]), #13, '', [rfReplaceAll]))); end; sorry...wrong post Quote
ravedadave Posted July 2, 2020 Author Posted July 2, 2020 On 6/29/2020 at 11:23 AM, Sherzod said: Ok. It is better to use a client-side solution. For example: 1. UniLabel, UniMemo1 2. UniMemo1.ClientEvents.UniEvents: function beforeInit(sender, config) { config.enforceMaxLength = true; config.maxLength = 160; } 3. UniMemo1.ClientEvents.ExtEvents: function keyup(sender, e, eOpts) { MainForm.UniLabel1.setText('You have entered '+ sender.getValue().length +' characters of 160'); } 4. procedure TMainForm.UniFormReady(Sender: TObject); begin UniLabel1.JSInterface.JSCode(#1'.setText(''You have entered ''+'+ UniMemo1.JSName +'.getValue().length + '' characters of 160'');'); end; Thank You! Very much appreciated, Kind Regards. Dave 1 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.