|
Can you provide a screenshot?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
http://img460.imageshack.us/img460/2465/extraspaceofpropertyshemk5.jpg[^]
Button having caption Cancel occupies the whole property page, but still there is some space occupied by property sheet, I have pointed that with some painting of blue colored airbrush.
Best Regards,
Mushq
Mushtaque Ahmed Nizamani
Software Engineer
Ultimus Pakistan
"English is my second language; please excuse any grammatical or spelling mistakes"
|
|
|
|
|
I could be wrong, but I think that spacing is normal.
¡El diablo está en mis pantalones! ¡Mire, mire!
Real Mentats use only 100% pure, unfooled around with Sapho Juice(tm)!
SELECT * FROM User WHERE Clue > 0
0 rows returned
Save an Orange - Use the VCF!
VCF Blog
|
|
|
|
|
Hi All,
I am new to c++ and facing one prob. I have one base class Vehicle and two sub class Car and Motor. I have an array of pointer to sub class but i m not able to delete the memory for that.
CVehicle
CCar : CVehicle
CMotor : CVehicle
CVehicle** myVehicle;
myVehicle = new CVehicle*[3];
myVehicle[0] = new CCar;
myVehicle[1] = new CMotor;
myVehicle[2] = new CCar;
now when I tried to reallocate the memroy, it is giving an error.
delete myVehicle ;
Any idea how to delete the memory??
Any help
Monark - I am learning
|
|
|
|
|
When you are deleting an array of elements that you created using new, you should be doing it using '[]'
delete []variable;
|
|
|
|
|
when you use new, you must use delete.
when you use new[], you must use delete[].
BTW, i see a problem in your design.
a Car is actually a Vehicle, so, it's ok to derive it from CVehicle.
but a Motor is not a Vehicle. a Vehicle HAS A Motor... it seems that you confused with the IS A relationship.
also, are you sure to wanting to create an array of pointers rather than an array of objects ?
|
|
|
|
|
You need to deallocate as
delete myVehicle[0];
delete myVehicle[1];
delete myVehicle[2];
delete [] myVehicle;
- NS -
|
|
|
|
|
use the delete operator carefully. With delete you delete pointers:
first delete myVehicle[0];
delete myVehicle[1];
delete myVehicle[2];
delete *myVehicle;//pointer to pointer
Hammer in your head: to every new belongs a delete
Greetings from Germany
|
|
|
|
|
KarstenK wrote: delete *myVehicle;//pointer to pointer
Your syntax is a bit askew. Use:
delete [] myPointer;
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
I chose this way use the same syntax as the declararion: to make it easier readable
Greetings from Germany
|
|
|
|
|
KarstenK wrote: I chose this way use the same syntax as the declararion: to make it easier readable
But it is wrong. As the address being deleted is not the same as the one allocated, you will receive an access violation.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
it was (not my code as followed) allocated:
CVehicle** myVehicle;
myVehicle = new CVehicle*[3];
so I would
delete *myVehicle;
or would I get (a deservred) exception
Greetings from Germany
|
|
|
|
|
You're missing it entirely. myVehicle and *myVehicle point to two different addresses, with the latter already having been freed (via delete myVehicle[0] ). Rather than guess at what you are trying to do, why not just try it?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi,
I'm having an application which connects to a database. I'm calling the SQLConnect() function in a seperate thread, so that if the connection is not there, it should time-out in 10 sec. and if the thread times out, I'm calling terminatethread. Is this the right way of doing? or is there any other way to terminate the thread? NB: SQLConnect() is a blocking call.
Please find the code snippet.
void DBConnectThread(void* param);
HANDLE hThread;
HANDLE hMutex;
int main()
{
unsigned long ThreadID=NULL;
unsigned long ExitCode=0;
DWORD retCode;
hThread = CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)DBConnectThread, 0, 0, &ThreadID);
if (WAIT_TIMEOUT == WaitForSingleObject(hThread, 10000))
{
GetExitCodeThread(hThread, &ExitCode);
TerminateThread(hThread, ExitCode);
}
if (hThread != NULL)
CloseHandle(hThread);
return 0;
}
void DBConnectThread(void *param)
{
SQLHENV henv;
SQLHDBC hdbc;
SQLHSTMT hstmt;
SQLRETURN retcode;
SQLINTEGER rgbValue = 0;
DWORD startTickCount = 0;
unsigned char username[255] = "blue";
unsigned char password[255] = "_abc97";
SQLCHAR * OutConnStr = (SQLCHAR * )malloc(255);
SQLSMALLINT * OutConnStrLen = (SQLSMALLINT *)malloc(255);
// Allocate environment handle
retcode = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
// Set the ODBC version environment attribute
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retcode = SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (void*)SQL_OV_ODBC3, SQL_IS_INTEGER);
cout << "setting odbc version" << endl;
// Allocate connection handle
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
retcode = SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
cout << "Allocating SQL Handle"<< endl;
// Set login timeout to 5 seconds
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
cout << "Attempt to Connect" << endl;
startTickCount = GetTickCount();
// Connect to data source
retcode = SQLConnect(hdbc, (SQLCHAR*) "OQTUAM blue", SQL_NTS, username, SQL_NTS, password, SQL_NTS);
cout << "Connection Done in "<< (GetTickCount() - startTickCount) << " Secs" << endl;
// Allocate statement handle
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
cout << "Connection Successful"<< endl;
retcode = SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
// Process data
if (retcode == SQL_SUCCESS || retcode == SQL_SUCCESS_WITH_INFO)
{
SQLFreeHandle(SQL_HANDLE_STMT, hstmt);
}
SQLDisconnect(hdbc);
}
else
{
cout << "Failed to Connect" << endl;
}
SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
}
}
SQLFreeHandle(SQL_HANDLE_ENV, henv);
}
}
thanks in advance,
Rajesh
|
|
|
|
|
Rajesh_Parameswaran wrote: I'm calling terminatethread. Is this the right way of doing?
No.
TeminateThread() is almost always the wrong solution.
Use a variable whose pointer you hand to the thread, and have the thread terminate itself when the outside pulls this variable to false.
Also, read the following stuff (made by Christian Grauss who is a codeproject regular):
The Processes Articles[^]
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
You better let the SQL-Stuff run completly. Normally you can somewhere else set a proper timeout for the DB. Or you have to wait the time.
Otherwise you can damage your Database and THAT is an overkill accident
Check the material for the database for the details
Greetings from Germany
|
|
|
|
|
Hi jhwurmbach/KarstenK,
Thanks for your response.
jhwurmbach, but the problem is that the call to SQLConnect() in the thread is a blocking one. So until i get a connection or it will timeout, it will be holding the call. It is getting timeout only after 40 seconds, that is a huge delay. I'm unable to set the ODBC Connection time out also. Even I set the ODBC time-out, it is taking it as WAIT_INFINITE.
Any other alternative methods??
thanks in advance,
Rajesh
|
|
|
|
|
I strongly advise you to respect the Database (DB) and its rules. If you get in trouble with the Integrety of the DByou are in the biggest trouble. Dont ferget that the DB needs some reaction time and some work to do so it needs the time.
If it is a professional DB on a network 40 seconds arent a big delay. Make a progress bar or a wait dialog to show the process.
Whether you findnt this approbiate contact the adminstrators of the DB to discuss the issue.
And inform me please what they said.
Greetings from Germany
|
|
|
|
|
Hi everyone!
I doing output file by MFC application.
How can I do it ? Pls help me
Thanks a lot
Tun
|
|
|
|
|
Hi,
you can use a simple fopen, fwrite and fclose for basic writtings:
#include <stdio.h>
int main ()
{
FILE * pFile;
char buffer[] = { 'x' , 'y' , 'z' };
pFile = fopen ( "myfile.bin" , "wb" );
fwrite (buffer , sizeof(buffer[0]) , sizeof(buffer) , pFile );
fclose (pFile);
return 0;
}
( Web-Example )
I hope it's usefull for you
|
|
|
|
|
You can use of CFile::Write .
|
|
|
|
|
There is a nice CFile class in MFC which you should know.
Greetings from Germany
|
|
|
|
|
CStdioFile is a good option to do that.
This class is derived from CFile class and contains a large amount of features.
|
|
|
|
|
tunminster wrote: ...output file by MFC application. How can I do it ?
Like you do in C++ on every platform:
#include <string>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
int main() {
std::string FileName = "C:/temp/file.out";
std::ofstream file(FileName.c_str());
if( !file) {
std::cerr << "Error opening file " << FileName << std::endl;
exit( EXIT_FAILURE);
}
const int i = 56;
const double j = 56.0003;
file << "Some play with Numbers \n";
file << std::setw(3) << i << " " << std::setw(2) << i << "\n";
file << std::setw(7) << j << " " << std::setw(4) << j << std::endl;
}
Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal. George Orwell, "Keep the Aspidistra Flying", Opening words
|
|
|
|
|
In my program i'm creating an editor like visualc++..
in this u can display the line no,column no of the editor part in statusbar ..the editor is based on scintilla..below to that editor i'm having an output window exactly like the output window of vc++..
so if i keep the mouse in output window and if i move the cursor it should show that corresponding line nd colmn no..
the output window is a richedit control...
i'm having code for detecting line no nd colmn no...
but how will detect that the cursor is in mainwindow or output window so that i can display the corresponding lineno,colmn no in the status bar?
aqny help..thanx in advance...
|
|
|
|