|
dear all,
the following lines of code gives wrong value on windows 2000, but on every other operating systems it works fine
<br />
if (sDir.CompareNoCase("M") != 0)<br />
{<br />
.....<br />
}<br />
but if i use a variable with value "M"...it works fine.......
any guesses why
Regards
rIsHaBh
|
|
|
|
|
rishabhs wrote:
if (sDir.CompareNoCase("M") != 0)
use this instead..
if(!sDir.CompareNoCase("M"))
{
}
Rob
Whoever said nothing's impossible never tried slamming a revolving door!
|
|
|
|
|
rishabhs wrote:
...the following lines of code gives wrong value...
Which means what? What does CompareNoCase() return in this case? What are you expecting it to return?
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
I assume sDir is a CString, you're not compiling for Unicode, and you're trying to test for sDir NOT being M (i.e. the if block should be executed if sDir is not M).
I can't see why this would fail on Windows 2000. CompareNoCase uses _tcsicmp , which translates to _stricmp for a non-MBCS, non-Unicode build. For an MBCS build, it translates to _mbsicmp . Check which of MBCS and/or UNICODE you're defining.
Apparently these functions are affected by the LC_CTYPE but not the LC_COLLATE locale parameter. I believe that the locale defaults to the C locale - see the documentation for setlocale .
See also the CodeProject BugList article[^].
|
|
|
|
|
This is probably a UNICODE vs. ANSI (MBCS) issue. If you change your code like this:
#include "tchar.h"
if (sDir.CompareNoCase(_T("M")) != 0)
{
}
that may help.
Software Zen: delete this;
|
|
|
|
|
when i tried to add function for user to edit data, the CString all work correctly but the float numbers become distorted after user edit the fields.
void CEtchDlg::OnEdit()
{
CString a,b,c,d,e,f;
float h,j,k,l;
GetDlgItemText(IDC_EID,a);
GetDlgItemText(IDC_TARGET1,b);
GetDlgItemText(IDC_PROCESS1,c);
GetDlgItemText(IDC_ETCHANT1,d);
GetDlgItemText(IDC_CONCENTRATE,e);
GetDlgItemText(IDC_REMARKS,f);
recordset->Edit();
recordset->SetFieldValue("a",(LPCSTR)a);
recordset->SetFieldValue("b",(LPCSTR)b);
recordset->SetFieldValue("c",(LPCSTR)c);
recordset->SetFieldValue("d",(LPCSTR)d);
recordset->SetFieldValue("e",(LPCSTR)e);
recordset->SetFieldValue("f",(LPCSTR)f);
recordset->SetFieldValue("h",(float)h);
recordset->SetFieldValue("j",(float)j);
recordset->SetFieldValue("k",(float)k);
recordset->SetFieldValue("l",(float)l);
recordset->Update();
}
|
|
|
|
|
When you need a char* , as in SetFieldValue, you need to access it via GetBuffer(0) and ReleaseBuffer(). Casting it your way (LPCSTR) is a bad practise.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Nah I disagree completely, using LPCSTR returns a constant pointer to a string, which is good if you're only going to read from it and NEVER alter it. GetBuffer(0) returns a MODIFIABLE char* which should be treated with care because you can munch memory and cause the app to crash. Its always good practice to use constants where you can, it offers a little protecting from making silly mistakes.
Alan.
|
|
|
|
|
Whoops, of course you are right. I mixed up LPCSTR and LPSTR :/
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Easy enough to do , all this LPCSTR, LPCTSTR, LPSTR stuff etc... its just asking for it really. I can see why LPSTR would be bad practice mind since the CString buffer isn't protected, as in GetBuffer(0) (which requires you to ReleaseBuffer before the changes are implemented), so cheers for pointing that out. I always use GetBuffer(0) but this discussion has just highlighted that it is the better coding practice of the two, which is nice to know .
|
|
|
|
|
coda_x wrote:
recordset->SetFieldValue("h",(float)h);
recordset->SetFieldValue("j",(float)j);
recordset->SetFieldValue("k",(float)k);
recordset->SetFieldValue("l",(float)l);
Why are you casting a float to a float ? Since none of the SetFieldValue() methods take float as a parameter, this will not work. You'll need to use a COleVariant instead, as in:
COleVariant v(h);
recordset->SetFieldValue("h", v);
or use the LPCTSTR version:
CString s;
s.Format("%f", h);
recordset->SetFieldValue("h", s);
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
In your example, h j k and l are never set to anything. Uninitialized floats will have random values.
You need to get the strings from the dialog items that are supposed to be numbers, convert the strings to numbers, and use those to set the field values.
|
|
|
|
|
thanx! i used the atof to convert and it works
|
|
|
|
|
i encountered an application error: xxxxx reference memory cannot be "read"..., after I run and close my .exe program. I suspect tis to do with my declaration of:
private:
CDaoDatabase database; //prob:application error
CDaoRecordset *recordset;
};
in my header file..... anything wrong with this?
|
|
|
|
|
Run the debugger to find where in the code it crashes.
You're problably using an pointer that points to invalid data.
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|
|
there is no error when i compiled the program, wat do u mean by running the debugger? i simply debug and it can b compiled
|
|
|
|
|
u propose u first learn how to debug software before coding anything!
read tutorials about that...
Don't try it, just do it!
|
|
|
|
|
Compile the program in debug mode, and run it using F5.
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
I have a MFC app in which i create controls dynamically in a View.For the edit control i need to set the width dynamically.may be to hold characters of length 10 or 15 or may be anything.How to handle this .I tried to use memebrs of Crect..but nothing works.
Pls help .i am struggling .
I don't use dialogs.The size of control is known only during runtime.
Thnks in advance
Ram
|
|
|
|
|
Look at the second parameter of CEdit::Create() . Otherwise, you'll need to use CWnd::MoveWindow() , or CWnd::SetWindowPos() .
Five birds are sitting on a fence.
Three of them decide to fly off.
How many are left?
|
|
|
|
|
Hi,
I would like to know if there is any way (preferrably easy ) of drawing an icon as an overlay over another icon on a dialog (like overlays in an imagelist).
I tried to use 2 CStatic controls with tranparent backgrounds, but it didn't seem to work.
If I had to subclass CStatic and create my own control for this, which methods should I implement besides OnDraw()?
Thanks in advance.
|
|
|
|
|
Salvador Dali wrote:
Now, that is truly surreal!
Phil
|
|
|
|
|
Why is it so hard for us surrealists to do something that is so easy to do on the canvas (overlaying and mixing colors), in MFC?
|
|
|
|
|
Hello, I want to disable (gray) an item from the main menu created by the framework.
I know when the menu is create by code but here?? It must be really simple but I don't have a lot of time to search in the MSDN doc
Thanks
|
|
|
|
|
EnableMenuItem() ?
Rickard Andersson
Here is my card, contact me later!
UIN: 50302279
Sonork: 37318
Interests: C++, ADO, SQL, Winsock, 0s and 1s
|
|
|
|