|
Why you are using "delete(settingsFile);" instead of "delete settingsFile;". What does it mean?
I think you should also close settings file before deleting it.
And if the settingsfile->open() fails you will get another memmory leaks, because you are leaving function without deleting settingsfile.
|
|
|
|
|
Newbie00 wrote: What does it mean?
The same this as sizeof(var) and return(result) . Parenthesis are optional.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous
|
|
|
|
|
Certainly looks like the entire code block is suspect to me.
You have something that looks like a file, which is scoped by new/delete. Then that gets used by something else, that looks like a file reader, and the scope of that is the method. Thus it continues to have a reference to the 'file' until the method exits even though you have already deleted it. Either both should be on the heap or neither should be.
And the first has a close method. Which, hopefully the dtor takes care of by certainly I never assume that.
You make a memory allocation and then do an error check and exit - without cleaning up.
|
|
|
|
|
I need to store a structure in a database..but the structure contains another structure..can anybody help me plz
|
|
|
|
|
Are you trying to store all this data in one database field or store its contents in separate fields? Please provide more details.
Use the best guess
|
|
|
|
|
Given that you have two structures, you need something like a foreign key to resolve them when loading them from database.
Given there is structure #1:
struct numberOne{
int childStructId,
int someValue
};
and struct #2:
struct numberTwo{
int id, int anotherValue
};
You need now a database which has two tables, one to store struct #1 and another one for struct #2:
The table for struct #1 has two fields, for the childStructId and onther one for someValue.
The table for struct #2 has also two fields, one for its unique Id and another one for anotherValue.
Afterwards you can load struct #1 from database, and according to the childStructId you can load struct #2 from the database.
I was just guessing what you want, please come back to me if you have further questions.
|
|
|
|
|
sir,
first of all thank u so much for ur reply..
what i need is for example there is a structure
struct example
{
int id;
string name;
struct example2
{
int value;
}
};
now i need to store this structure in a database...as i'm new to database i
dnt have any idea of it...so plz help me...also i'm using sqlite3 database
|
|
|
|
|
Member 7894601 wrote: first of all thank u so much for ur reply..
You're welcome.
Member 7894601 wrote: now i need to store this structure in a database...as i'm new to database i
dnt have any idea of it...so plz help me...also i'm using sqlite3 database
You can find an intro of how to connect to a SQLite database at the SQLite website[^].
The people of the Database forum[^] will help you to find out which tables you will need to create a reliable database.
|
|
|
|
|
You may create two tables where one contains a reference (foreign key) to the other:
TABLE example2
INT id unique ID, usually auto increment
INT value
TABLE example
INT id
VARCHAR name
INT id2 foreign key to access table example2
|
|
|
|
|
but initially how to create a database with two tables using sqlite3
|
|
|
|
|
|
Member 7894601 wrote: can anybody help me plz
The first step is that you need to learn
- How to create a database
- How to create tables
- How to store and retrieve data from a table
None of that has anything to do with your structures, so don't try to do that until you understand the above.
|
|
|
|
|
Sir,
i am nw able to create a database...nw my requirement is how to store the details of files and folders in the database..
|
|
|
|
|
sir,
nw i am able to create a sqlite3 database...but nw i face a problem of storing a variable which is wchar_t...which datatype should i use...plz help me
|
|
|
|
|
I need to send the data to the server in a manner like
00 12 34 00 00 54
when I am doing a strcat of 00 to 1243 or strcat of 1234 to 000054 it's not concatenating 00 to string and the result is 1234 only.
I know strcat treats 00 as a terminating null character that's why it is considering 00 as terminator.I have tried with the memcpy also but then in the server side 00 is coming as 3030.
How can I make my program to treat 00 as the part of the array not as the terminating null character or to treat 00 as it is,not the ascii value as 30.
|
|
|
|
|
If you are sending pure binary data then forget about functions that treat byte sequences as zero terminated strings. Don't use strcat but memcpy should be okay to move bytes here and there if you use it correctly. Along with your binary data you should store the length/size of the data in an int or size_t variable. If you are using C++ you could simply use an std::vector for this job.
class CStorage
{
size_t m_Size;
char m_Bytes[100];
public:
CStorage()
: m_Size(0)
{}
void Append(const char* data, size_t size)
{
memcpy(m_Bytes+m_Size, data, size);
}
};
OR
#include <vector>
#include <iterator>
static const char appendable[] = "abcdefgh";
std::vector<char> bytes;
std::copy(appendable, appendable+sizeof(appendable)/sizeof(appendable[0]), std::back_inserter(bytes));
|
|
|
|
|
You CStorage::Append() should do a m_Size += size; after the memcpy(). 
|
|
|
|
|
Of course. 
|
|
|
|
|
I explained yesterday[^] that you cannot use the string functions for binary data that contains null characters: you must use memcpy() . If the server is receiving 3030 rather than 00 , then it means your sending code is not converting it from characters to binary.
Use the best guess
|
|
|
|
|
Hello,
I need to verify content of my edit control before I let it to loose focus. To do so I wrote my PreTranslateMessage like this:
BOOL CMyFrameWnd::PreTranslateMessage( MSG *pMsg )
{
BOOL bMessageHandled = FALSE;
switch( pMsg->message )
{
case WM_LBUTTONDOWN:
{
if( ::GetFocus == MyEditWnd )
{
if( !IsContentOfMyEditWndOK )
{
ShowMessageBox( "You cannot change value");
}
}
break;
}
}
if( !bMessageHandled )
{
bMessageHandled = CFrameWnd::PreTranslateMessage( pMsg );
}
return bMessageHandled;
}
In order to be able to show modal dialog in PreTranslateMessage and after it forward WM_LBUTTONDOWN I would like to do something like this:
BOOL CMyFrameWnd::PreTranslateMessage( MSG *pMsg )
{
BOOL bMessageHandled = FALSE;
MSG oRememberMsg;
switch( pMsg->message )
{
case WM_LBUTTONDOWN:
{
if( ::GetFocus == MyEditWnd )
{
if( !IsContentOfMyEditWndOK )
{
oRememberMsg = *pMsg;
ShowMessageBox( "You cannot change value");
*pMsg = oRememberMsg;
}
}
break;
}
}
if( !bMessageHandled )
{
bMessageHandled = CFrameWnd::PreTranslateMessage( pMsg );
}
return bMessageHandled;
}
But I am not sure if my code is ok from MFC structural point of view. Can I manipulate with MSG *pMsg parameter as I described above? I tried it and it seems to work, but I don't know... Does it make some side effects? Is something I am missing here? How do you think?
|
|
|
|
|
Couldn't you handle the EN_KILLFOCUS message from the edit control in the parent dialog, check for valid values, and if is isn't OK, call the SetFocus() method for the edit control?
|
|
|
|
|
I cannot let to run OnKillFocus if control has no valid value, because OnKillFocus is too late. It is out of my control.
Let me show you some example:
I have a toolbar also. If somebody presses toolbar button OnCommand is running. Let say it is saving the document. Before saving I have to recalculate it and then save. Recalculating depends on the values in Edit. If Edit is not valid I have wrong calculations. Unfortunately pressing this toolbar buton doesn't cause KillFocus for my Edit. I have to use SetFocus to the edit's parent in order to make KillFocus for my edit to run, before I make recalculation. I don't like this solution.
I have many similar problems with validating data in OnKillFocus, so I need to handle all actions before OnKillFocus and before OnLButtonDown, OnCommand, etc of given buton. I do not want to change all possible handlers in my app so I choose PreTranslateMessage.
Sometime I return TRUE in PreTranslateMessage for example in order to not let the app for saving document, if user is in serious trouble with his already typed data.
|
|
|
|
|
Why make life difficult for yourself? The edit control provides notifications that will let you know when the contents are changing. Take a look at EN_CHANGE [^] and EN_UPDATE [^].
Use the best guess
|
|
|
|
|
Unfortunately I cannot use OnChange. It is to early to disturb user. I have to wait untill user finishes typing. EN_CHANGE is sent after each pressed key and I cannot save data from control to internal buffer during typing. I want to do it, if user decides to leave edit control.
I have also investigated this MSG *pMsg deeper and it occured that: If I let pumping messages (f.e with modal messagebox), I always have to return TRUE in PreTranslateMessage. Saving first message and forwarding it at the end has no sence, because the whole messaging process is disturbed any way.
Here is example of situation, for which my solution with saving *pMSG won't help:
WM_LBUTTONDOWN -> WM_LBUTTONUP pair is very sensitive here.
If I put messagebox between WM_LBUTTONDOWN and WM_LBUTTONUP in PreTranslateMessage it causes WM_LBUTTONUP to run for mouse point from the [OK] button on the messagebox and not for the original coordinates. So code from CFirstClickedArea::OnLButtonUp() will not be run.
So I think, I have to return always TRUE and I have no choice, if I want to use PreTranslateMessage with DoModal.
modified 26-Apr-13 13:22pm.
|
|
|
|
|
I think you are just making your program far more complicated than necessary. Using either EN_CHANGE or EN_UPDATE means that you can trap illegal content at any point. This will not have any effect on the user's typing unless they enter an incorrect character.
Use the best guess
|
|
|
|