Recent

Author Topic: Parsing ip string within a TextBox  (Read 35132 times)

jolix

  • Jr. Member
  • **
  • Posts: 60
Parsing ip string within a TextBox
« on: October 21, 2010, 10:25:14 am »
Hi
I have a TextBox that i need to modify or fill contents wich is an ip like '192.168.1.10' or other.
I google it and find nothing, just a few words about it.

Exists any way like a filter ###.###.###.###

I already have a code doing it with a state machine inside of OnEditingDone but i want it running in realtime, i mean, auto correction while writing.

Certainly this is done somewhere and thus, while reinventing the wheel?

Regards,
jolix

BlueIcaro

  • Hero Member
  • *****
  • Posts: 790
    • Blog personal
Re: Parsing ip string within a TextBox
« Reply #1 on: October 21, 2010, 11:23:20 am »
Try use OnChange Event

/BlueIcaro

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Parsing ip string within a TextBox
« Reply #2 on: October 21, 2010, 11:34:47 am »
You could use a TMaskEdit with EditMask like
!099.099.099.099;1;

jolix

  • Jr. Member
  • **
  • Posts: 60
Re: Parsing ip string within a TextBox
« Reply #3 on: October 21, 2010, 11:57:54 am »
Quote
Try use OnChange Event
BlueIcaro, i already try use code to parse inside of OnChange, but i realize the code needed results very extensive.
So i will try some cooked thing like TMaskEdit as Theo suggested.

Regards,
jolix

jolix

  • Jr. Member
  • **
  • Posts: 60
Re: Parsing ip string within a TextBox
« Reply #4 on: October 21, 2010, 12:46:57 pm »
Hi,
I try EditMask with unexpected results:

1. Setting Mask to 099.099.099.099 Lazarus don't compile at all.
2. Setting Mask to 999.999.999.999 Lazarus compile well although the result is not perfect as i expected.

For the case 1, the object inspector shows me:
Property Text: _99._99._99._99
and SpaceChar: _

Any suggestion?

Regards,
jolix

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Parsing ip string within a TextBox
« Reply #5 on: October 21, 2010, 12:58:45 pm »
Which Lazarus version do you have?
Try a snapshot:
http://www.hu.freepascal.org/lazarus/

DirkS

  • Sr. Member
  • ****
  • Posts: 251
Re: Parsing ip string within a TextBox
« Reply #6 on: October 21, 2010, 01:02:56 pm »
Quote
1. Setting Mask to 099.099.099.099 Lazarus don't compile at all.
The mask should be '!099.099.099.099;1; ' (without the quotes and space at the end).

Gr.
Dirk.

jolix

  • Jr. Member
  • **
  • Posts: 60
Re: Parsing ip string within a TextBox
« Reply #7 on: October 21, 2010, 01:39:13 pm »
Theo msg:
Quote
Which Lazarus version do you have?
Lazarus Version 0.9.26 Beta - fcp version 2.2.2

Note that 0.9.28 or 0.9.29 versions, i have tried few months ago in my xp pro and i can't find a way to put it working at all.

DirkS msg:
Quote
The mask should be '!099.099.099.099;1; ' (without the quotes and space at the end).
I tried and the compiler ends with the same error:
Project myapp rised exception class 'EDBEditError' with message:
  Error stting Text...!

Thanks to both :)
jolix

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Parsing ip string within a TextBox
« Reply #8 on: October 21, 2010, 01:48:35 pm »
Lazarus Version 0.9.26 Beta - fcp version 2.2.2

Note that 0.9.28 or 0.9.29 versions, i have tried few months ago in my xp pro and i can't find a way to put it working at all.

You should upgrade. 0.9.26 is really old now.
The new versions are working for most people, so what's the problem?

jolix

  • Jr. Member
  • **
  • Posts: 60
Re: Parsing ip string within a TextBox
« Reply #9 on: October 21, 2010, 01:56:56 pm »
If i remember it right, new versions i tried don't worked basically because have a huge things to configure after installation. Things i loose hours without success.

But because you say me that work for most people, right now, i go try find a stable version and install it.

Regards,
jolix

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1927
Re: Parsing ip string within a TextBox
« Reply #10 on: October 21, 2010, 02:23:01 pm »
But because you say me that work for most people, right now, i go try find a stable version and install it.

Try a snapshot: http://www.hu.freepascal.org/lazarus/

jolix

  • Jr. Member
  • **
  • Posts: 60
Re: Parsing ip string within a TextBox
« Reply #11 on: October 21, 2010, 03:26:12 pm »
Theo,
I finished installation of 0.9.28.3 Lazarus version successful

Back to the MaskEdit:
First i start writing mask with 099.099.099.099 that works close of expected.
After i tried !099.099.099.099 and compiler stops with error: myapp.lpr(17,1) Error: Can't create object file c:\test\test.exe
Compiler show me last line of test.lpr selected:
Code: [Select]
begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end. <<--- SELECTED LINE ERROR

This error persists even after removing the component from the form.

Regards
jolix

Bart

  • Hero Member
  • *****
  • Posts: 5235
    • Bart en Mariska's Webstek
Re: Parsing ip string within a TextBox
« Reply #12 on: October 22, 2010, 08:50:24 am »
That mostly happens if you recompile (build) while the old exe is still running. (Maybe not closed properly by the debugger if yoy run from within the IDE?, try resetting the debugger)

B.t.w

The mask can also be '!099.099.099.099;1;_' (as opposed to '!099.099.099.099;1; ')
When reading the text property, '_' will be rpelaced by a space (#32).

Bart

jolix

  • Jr. Member
  • **
  • Posts: 60
Re: Parsing ip string within a TextBox
« Reply #13 on: October 22, 2010, 10:22:50 pm »
Bart Reply:
Quote
That mostly happens if you recompile (build) while the old exe is still running. (Maybe not closed properly by the debugger if yoy run from within the IDE?, try resetting the debugger)

Thanks Bart, but is not the case. I can sure by opening Task Manager.

Whats happen is:
Since i place TMaskEdit on the form and apply the mask, everything runs bad.
This happens with any version of Lazarus 0.9.26, 0.9.28.2, 0.9.28.3 or 0.9.29.
Yesterday again, i lose about four hours testing all this versions with my app with MaskEdit and result was the same.
With versions later than 0.9.26, when this error occurs  i can't work anymore even after deleting the MaskEdit component from the form.
By other hand, with 0.9.26 i haven't this behavior, so to me is a more stable version.

Later versions also have several behaviors they force me to adopt the old version which is 0.9.26, for instance after compilation app.exe refuses leave the memory even with task manager.

I finish minutes ago a simple form with MaskEdit component with mask you suggested and result was the same.

Bart, i google for MaskEdit and not found nothing related with mask options.
You know where i can find it? For instance, why '!' and why ...;1; '.
Why mask can't be: '099.099.099.099' ?

After all this work and because i have to go ahead with app, i decided write my own code that not works in "real time" but when edition ends.

Thanks and sorry about long explanation.
jolix

eny

  • Hero Member
  • *****
  • Posts: 1634
Re: Parsing ip string within a TextBox
« Reply #14 on: October 22, 2010, 10:44:43 pm »
After all this work and because i have to go ahead with app, i decided write my own code that not works in "real time" but when edition ends.
Ah, you're using regular expressions now  ;)
All posts based on: Win10 (Win64); Lazarus 2.0.10 'stable' (x64) unless specified otherwise...

 

TinyPortal © 2005-2018