 |
|
 |
I am trying to determine how to use FloatEdit to validate a string from a dialog as a float or double value. First, in FloatEdit.cpp I notice the function: double CFloatEdit::GetValue () const
Let see, GetValue(), that means go and get/ retrieve something from somewhere. But there is no argument to specify the source of the data. Rather than being a straight forward function, it must rely on what is called a side effect. So we check into the function and look for that side effect.
I find function: GetWindowText (strFloat);
Another function that gets (that is to say, retrieves) something, expectedly text. But what is the source of the data retrieved. The name of the argument indicates a string. But a string is what I want it to get. Now I see that StrFloat is declared locally so GetWindowText must get the string from somewhere. Where? How does it know where to get the text.
Search for GetWindowText. Not found. Go to the boot library that I installed in C:/Program Files\boost. Not found.
Go to windows help function and loop up GetWindowText:
int GetWindowText( HWND hWnd, LPTSTR lpString, int nMaxCount );
Hmmm, not the same function. There appears to be insufficient information to determine how this works.
So, describe my need and maybe someone will give me a clue:
One of the fields if my dialog that I want filtered is an edit control box and has the ID: IDC_X_POSITION_EDIT and strings in the box can be accessed via a variable name as follows: GBE_x_position_string.GetWindowTextW( str ); That puts the value into CString names str. This does indeed provide the string from the dialog box.
Will someone tell me how to use this FloatEdit to: 1. verify that the text in this dialog box text field is valid for a float or double, and 2. How put that value into a double variable?
Thanks for your time
|
|
|
|
 |
|
 |
1. Call IsInputValid() on CFloatEdit. 2. double d = GBE_x_position_string.GetValue();
Try looking up CWnd in the help and searching for GetWindowText() there. You should also read something on object oriented programming.
Regards,
Ben
|
|
|
|
 |
|
 |
I downloaded the CFilterEdit code and demoproject. File BaseEdit.h contains this line:
#include
This file in not contained in the download. This is the only file containing the include and it has no previous includes that lead me to the file.
Where do I find this file?
Thanks for your time
|
|
|
|
 |
|
 |
I assume you are looking for boost/regex.hpp.
You can find the boost library at www.boost.org.
For instructions on compiling the regex library, see [^]
(Note that the latest version 1.35.0, so change the paths accordingly)
Regards,
Ben
|
|
|
|
 |
|
 |
Kirk: Do you suppose if you continue to beat it..... McCoy: LET IT DIEEEEEEEEEEEEEEE, Jim Kirk: Just beat it some more, Bones... Let's see what happens. McCoy: I'M A DOCTOR NOT A MAGICIAN. Kirk: But if you just beat it some more, it might still....
|
|
|
|
 |
|
 |
Lay off the cough medicine hombre...
|
|
|
|
 |
|
 |
The horse is dead only when there are no more people interested in it. This is not the case here, partially because WPF was released unfinished and because the C++/CLI syntax to access Windows Forms is not so pleasant. And you may want to control the memory footprint of your application.
|
|
|
|
 |
|
 |
I need to take an existing English application and accept special characters typed from the keyboard like èï, et. The member variable of the dialog is defined as a CString. When I trap the CString the character is properly displayed in debugger but the value is negative. Using iswalpha does not identify it as an alpha character (using isalpha throws exception.) I also need to disallow digits and iswdigit does not work. Where do I go for help? Thanks.
narlad
|
|
|
|
 |
|
 |
I don't have experience of using iswalpha or iswdigit, but if your characters show negative values then presumably you haven't done a UNICODE build as wchar_t is unsigned?
Ben
|
|
|
|
 |
|
 |
Hello I want to use your class for validating the user input for a correct url.
I found the ultimate regex therefore:
http://foad.org/~abigail/Perl/url2.html
Direct link to regex: http://foad.org/~abigail/Perl/url3.regex
But how can I use this very long regular expression?
The line: CString strRegEx (_T("THE_REGEX_FROM_SITE_WITHOUT_NEWLINE")); don't work, perhaps too long? 
Thanks!
|
|
|
|
 |
|
 |
Did you escape all the '\' characters? Remember it's not enough to just paste a regex into a C++ string, it still has to follow the C++ string rules.
It should be enough to do a find and replace of \ to \\ - at least I can't see anything else you need to change. boost::regex in release 0.34 defaults to PERL compatibility.
Non marking grouping "(?:" is compatible.
OK, let me know how you get on..!
Cheers,
Ben
|
|
|
|
 |
|
 |
Hi Ben,
you are right, I forgot to escape the '\' characters. But after testing this regular expression for checking of a URL, I think the regex above is not the best.
Do you have a regex therefore which works good (with alternative user and port and so on)?
Do you found a solution to the drawing problem for my last post (manifest problem)? 
Cheers
|
|
|
|
 |
|
 |
The book 'Mastering Regular Expressions' by Jeffrey Friedl, O'Reilly has an example on how to recognise URLS. Otherwise try this page: http://www.osix.net/modules/article/?id=586 (I just googled for url regex).
No luck on the manifest bug. All I found was lots of people complaining about the problem!
Regards,
Ben
|
|
|
|
 |
|
 |
Hi Ben,
I am wondering that nobody found a solution for the manifest bug. 
Thank you for the link, I found also a realy good site for regex's:
http://regexlib.com/DisplayPatterns.aspx?cattabindex=0&categoryId=1
Now I'm fighting with a regex for validating email:
I decided me for: http://regexlib.com/UserPatterns.aspx?authorId=2a7f5d15-0633-416c-8e2f-8eca473567a1
Qutoted to:
^((\\"[^\\"\\f\\n\\r\\t\\v\\b]+\\")|([\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+(\\.[\\w\\!\\#\\$\\%\\&\\'\\*\\+\\-\\~\\/\\^\\`\\|\\{\\}]+)*))@((\\[(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))\\])|(((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9]))\\.((25[0-5])|(2[0-4][0-9])|([0-1]?[0-9]?[0-9])))|((([A-Za-z0-9\\-])+\\.)+[A-Za-z\\-]+))$
(I tried a lot of the email regex's but many of them has the same problem with your class or my changes).
I create a new file with the following code, because I need no cast:
CString CEMailEdit::GetValue () const { CString EMail; GetWindowText (EMail); return EMail; }
If I use this regex in other programs with UNIX f.e. and it seems to work, but with your class the following don't work and I don't know why:
prename.name@adress.domain --> the problem is if after prename.name I have no chance to insert the "@"-sign
I tried to escape the @ in the regex but it still not work.
What it is the problem?
|
|
|
|
 |
|
 |
Easy! Don't use the sequence '\\"', instead use '\\\"'. You also don't really need to double escape things like '\f', although it won't harm.
In the end, it is better to convert by hand considering each operator/escape individually instead of just using search and replace. It's always tricky converting a regex off the web to use in a C++ program..!
Cheers,
Ben
|
|
|
|
 |
|
 |
Have you tried expresso[^]? In the expressions library tab, there's regex for URL's & email's.
|
|
|
|
 |
|
 |
Hello,
first thank you for sharing your good class to use regualar expressions.
I found a small bug:
If you create a manifest.xml-file for using XP-style (add manifest: Manifest Tool --> Input and Output --> Addional ManifestFiles: EditTest.manifest.xml)
This is a sample file for EditTest.manifest.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0"> <dependency> <dependentAssembly> <assemblyIdentity type="win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*" /> </dependentAssembly> </dependency> </assembly>
Now the XP-style is used for the application. If the m_EditUInt lost the focus, the background (the rect) is already paint until you move over the control.
Do you have a solution to remove this bug?
Thanks in advance!
|
|
|
|
 |
|
 |
I've got around to trying this and I can see the effect you are talking about. I'll see if I can find out how to fix this.
Cheers,
Ben
|
|
|
|
 |
|
 |
Hi Ben,
thank you for your fast answer to my question. I hope you find realy fast an solution to fix this problem.
I will have a look on your page every day 
Greets
|
|
|
|
 |
|
 |
I haven't been on the MFC page in a while... it's nice to see you're still beating this dead horse.
|
|
|
|
 |
|
|
 |
|
 |
How would you validate a regular expression? That is, a regular expression that only accepts valid regular expressions. 
/Chris
|
|
|
|
 |
|
 |
I don't think it's possible to do this in full, as really you need a full parser for that kind of thing. Also even when complicated regexes have been written to validate things like URLs, once they start spreading over several pages you really can't justify using a regex because you'll never be able to maintain it.
If you want to parse regular expressions yourself, take a look at http://www.benhanson.net/cpp/lexertl/Zip/lexertl.zip
Cheers,
Ben
|
|
|
|
 |
|
 |
Thanks, but I actually solved it just after I posted the message. So if some coders out there wonder the same thing, here's how you do it with the boost library (using mfc typedefs):
try { boost::tregex r( "parenthesis ( mismatch " ); } catch (const boost::regex_error &e) { e.what(); // A string with information about the error. PERFECT! } catch (...) { }
Cheers, Chris
|
|
|
|
 |
|
 |
Ok, your code is right and not totally bugged. BUT,
if I create a new CFilterEdit (from CUIntEdit) herited class, and if I set the regular expr ".*" (I use such a regular expr to have all my Edit control from CFilterEdit) then the bug appears when pasting from keyboard, the text is pasted twice.
Can you try to correct it, or please give me a good regular expr. Thanks for all.
Firejano
|
|
|
|
 |