|
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
|
|
|
|
|
Yes I know but how to retrieve this main menu created by the framework ????
|
|
|
|
|
GetMenu().
I case you mean the menu on top of your app.
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hum, great! That was easy
Thanks
|
|
|
|
|
Is there something wrong with this code?
void Calculate(const int &a, float *b, int &c); //?
int a; //can i initialize a
float b;
int c;
float d = 20.4;
Calculate(a,b,c); //function call
void Calculate(const int &a, float *b, int &c)
{
//Code //
};
lets say a is 4, b is 0.0 and c is 5.
a is supposed to stay 4, b is supposed to be 0.25 and c 24.4 when the function returns.
Can someone correct please
oh and its not home work or an assignment or something
Thanks bhangie
|
|
|
|
|
In what way are the parameters being calculated? There must be some sense of the "Calculate" function
What do you want to achieve?
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Some comments:
If you don't want a to change a variable, don't pass a reference to it. You can do something like this:
void Calculate( const int a, int c, float* f );
Here I'm not passing any references and you cannot change 'a' within Calculate. I can change the value of 'c' within the function, except the variable will retain its original value upon return. Now you maybe asking why I changed the parameter order. Mainly preferrence. I like to have the same types grouped together.
Yes, you can initialize 'a' just like you did with float. The variable 'a' at the point you placed it is not a constant value.
If you have anymore questions, just ask.
Larry J. Siddens
Cornerstone Communications
TAME THE DOCUMENT MONSTER
www.unifier.biz
|
|
|
|