Recent

Author Topic: editbox / combobox text check for charicaters?  (Read 14846 times)

cazzajay

  • Jr. Member
  • **
  • Posts: 94
editbox / combobox text check for charicaters?
« on: October 09, 2009, 09:20:26 am »
i have some edits and combo boxes that end up creating filenames.  is there any way to run a little procedure to check to ensure they don't contain the windows-forbidden characters such as ! etc?

im looking for as simple a solution as possible, any help?

thanks

cj  :D
Windows XP 32 bit / Lazarus 1.0.6 / FPC 2.6.0

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1933
Re: editbox / combobox text check for charicaters?
« Reply #1 on: October 09, 2009, 11:10:32 am »
What is exactly your question?
You don't know how to scan a string for certain characters?
Or you don't know which event to use for checking the content of some controls?
What do you mean with "simple a solution as possible"?
« Last Edit: October 09, 2009, 11:39:07 am by theo »

cazzajay

  • Jr. Member
  • **
  • Posts: 94
Re: editbox / combobox text check for charicaters?
« Reply #2 on: November 18, 2009, 07:15:35 pm »
ok ive managed to work around this but the problem has cropped up again.

i have an edit box, and i want to scan every single character in that box to check it ain't from a known "bad list".  pseudocode something like:


y := 0
i := edit1.length

for j := 0 to i do
begin
if edit1.character[j] = '!' then y := y + 1;
end;

for x := 0 to i do
begin
if edit1.character[j] = '$' then y := y + 1;
end;

if y > 1 then
begin
showmessage('Dont be an idiot - you cant use ! or $ in that field');
exit;
end;


except i cant find the right bits for edit1.character[j] and edit1.length

and the same for a memobox...


« Last Edit: November 18, 2009, 07:18:20 pm by cazzajay »
Windows XP 32 bit / Lazarus 1.0.6 / FPC 2.6.0

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: editbox / combobox text check for charicaters?
« Reply #3 on: November 18, 2009, 07:59:33 pm »
Hi,
I think so

Code: [Select]
i:=length(Edit1.Text);
and

Code: [Select]
for j:=1 to i do
begin
  if Edit1.Text[j] = '!' then ....

Is important to start the loop from 1.

You can try this wild characters remove automatically.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Marc

  • Administrator
  • Hero Member
  • *
  • Posts: 2673
Re: editbox / combobox text check for charicaters?
« Reply #4 on: November 18, 2009, 08:21:37 pm »
to make sure the edit text is not retrieved on every call, better store it locally first.
Code: [Select]
var
  S: String;
  n: Integer;
begin
  S := Edit1.Text;
  for n := 1 to Length(S) do...
//--
{$I stdsig.inc}
//-I still can't read someones mind
//-Bugs reported here will be forgotten. Use the bug tracker

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: editbox / combobox text check for charicaters?
« Reply #5 on: November 18, 2009, 09:52:33 pm »
Marc:
Quote
to make sure the edit text is not retrieved on every call, better store it locally first
I'm interested in this. Is this faster - I mean making local variable rather than accessing object preperty again and again ?

I usually do it, but sometimes not, I never tested difference.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: editbox / combobox text check for charicaters?
« Reply #6 on: November 18, 2009, 10:27:43 pm »
I made little test (measured using function Now) and it seems searching in local string variable is more than 200 times faster than accessing object property.

Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

cazzajay

  • Jr. Member
  • **
  • Posts: 94
Re: editbox / combobox text check for charicaters?
« Reply #7 on: November 19, 2009, 01:44:28 pm »
I made little test (measured using function Now) and it seems searching in local string variable is more than 200 times faster than accessing object property.



Really? I had no idea!!!  What OS is that on?
Windows XP 32 bit / Lazarus 1.0.6 / FPC 2.6.0

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: editbox / combobox text check for charicaters?
« Reply #8 on: November 19, 2009, 03:29:30 pm »
On Kubuntu 9.10, Qt 4.5, 64 bit, i can give here code but now I am away from my PC.
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

cazzajay

  • Jr. Member
  • **
  • Posts: 94
Re: editbox / combobox text check for charicaters?
« Reply #9 on: November 19, 2009, 03:59:24 pm »
dont worry about it - i did it the local variable way, on win32, and the difference is hardly noticeable but even so - nice to have my app running at its optimum :D
Windows XP 32 bit / Lazarus 1.0.6 / FPC 2.6.0

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: editbox / combobox text check for charicaters?
« Reply #10 on: November 20, 2009, 01:23:42 am »
Here is a little test, code is simple, I hope it will work on your PCs (it is without project1.lrs file)

Edit: Be patient, test run ~ 15 seconds.
On my CPU Intel Penryn 7350 2GHz usually multiplication is 3.2x faster and searching in local variable is 150 - 250 x faster, depend on length of string and also if test run from Lazarus (under debugger) or normally from binary.
« Last Edit: November 20, 2009, 01:30:28 am by Blaazen »
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Garry Hopkins

  • Newbie
  • Posts: 2
Re: editbox / combobox text check for charicaters?
« Reply #11 on: January 08, 2010, 10:56:31 am »
Blaazen has worked this out,any issues after this? I think this should work.

samps

  • Newbie
  • Posts: 4
Re: editbox / combobox text check for charicaters?
« Reply #12 on: April 22, 2010, 05:44:27 am »
Windows don't mind the '!' character. In fact, I use it often to ensure MY stuff is listed first.. :)


I would use SETs to discern what is filename legal and what's not:


goodies = SET of CHAR;

goodies = [a..z,A..Z,0..9,!,[,],etc.....];


while i < length(filename) do
    if filename not in goodies then filename i := whatever-fallback-character-routine-returns


That's the idea anyway, mind the syntax (why isn't there a syntax highlighter/grammar checker for web content? Like: TinyMCE on proggin' steroids?)


cheers
Samps

 

TinyPortal © 2005-2018