|
|
Hi,
I dont know whether there are some issues implementing threads by means of MFC in Borland C++ Builder.
I have found some problems with CWinThread class in Builder... have you some additional comments regarding it ?
tks a lot for your help...
|
|
|
|
|
MFC is a part of Visual C++, not for C++ builder, maybe the idea is useful.
If you do not want to use api or read codes in visual c++, please use TThread in c++ builder. there is an example contained in c++ builder
D:\Program Files\Borland\CBuilder6\Examples\Apps\Threads
you can file->new->others->thread object to create a new thread, See more in help file of TThread
|
|
|
|
|
Hello,
I am no stranger to the idea that when you call 'new obj' it allocates dynamic memory of the heap, yada yada yada. Mainly call the corresponding 'delete obj' as is dictated by the language.
my question is with the practice of using it as you call a function:
...foo (new bar ())...
I've seen this done a lot, i was wondering why. it is a nice syntax, looks good, but seems dangerous. no handle to the obj to delete it, relying on the underlying func to take responsibility, dangerous most def. i feel like i am missing something about it. Ideas?
|
|
|
|
|
I personally have never written this kind of code, but have worked with such code. For example, such a function expects a pointer to some class object (to be on the heap). You can call the function from within a thread, and forget it. The function then guarantees clean up of the passed object.
The function code looks typically like this:
void foo(CBar *bar)
{
if(bar == NULL)
{
return;
}
delete bar;
}
So, you can call the function safely like: foo(new bar());
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
i'd be very nervous if i ran across that in anything i was working on. unless the function is called DoSomethingThenDeleteTheInputObject, yes, dangerous indeed.
|
|
|
|
|
Definitely. I second it.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
That was pretty common in 1990s when people were trying to emulate Smalltalk with C++. For instance, you'll see a lot of such code in the GoF book.
Today it is not considered a good C++ coding style because of the problems you mention
|
|
|
|
|
Nemanja Trifunovic wrote: For instance, you'll see a lot of such code in the GoF book.
Actually I don't remember it in the book (anyway my memory is far from being perfect... ).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Others pointed no good reasons but I say one situation of no bad.
1) such classes is not wrapper of system object; like HANDLE.
2) such classes need to be active while the program's alive.
An example is neural network programing. In such case, there is usually no need to delete at the end of program.
|
|
|
|
|
I occasionally use that construct in collection classes.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
|
|
|
|
|
I'm having an issue with the zoom method of NTGraph. Basically the code is as follows:
void CPlot1To1NBBBRSvsIL::OnZoomIn()
{
m_Graph.AutoZoomIn(0.0);
}
void CPlot1To1NBBBRSvsIL::OnZoomOut()
{
m_Graph.AutoZoomOut (0.0);
}
Where when I step into the function during debug it goes into NTGraph.cpp at
void CNTGraph::AutoZoomIn(double zoomPercent)
{
static BYTE parms[] =
VTS_R8;
InvokeHelper(0x53, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
zoomPercent);
}
void CNTGraph::AutoZoomOut(double zoomPercent)
{
static BYTE parms[] =
VTS_R8;
InvokeHelper(0x54, DISPATCH_METHOD, VT_EMPTY, NULL, parms,
zoomPercent);
}
The problem is that I do not know what the default zoomPercent is, when I watch the variable it is set to 0.0, but if I change it to
m_Graph.AutoZoomOut (50.0);
It ceases to zoom at all, where it previously would zoom an unknown amount. I've also tried using
m_Graph.SetAutoZoomPercentage(50);
For both ways I tried using various numbers between 200 and .01 as I was not sure if it was truly in percentage format, but this did not make any difference.
Please let me know if you can tell me how the zoom function works and by what percent it goes by (in x and y), the goal being to create some code to reformat the y-axis upon zooming, which currently seems to be faulty if zoomPercent is left at 0.0.
It might be worth noting that upon zooming out, the y axis does indeed adjust accordingly, it's only zoomin thats a problem...
Thank you for your time,
KevinVS
modified on Friday, June 26, 2009 10:42 AM
|
|
|
|
|
Why don't you ask in the article thread?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello All ,
Sorry i am posting all code ,
i this code it is writting & reading stuct data ,BUt not changing that data i want change that data
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
struct MyRecord {
char name[80];
double balance;
unsigned long account_num;
};
int main()
{
struct MyRecord acc;
strcpy(acc.name, "R");
acc.balance = 1.3;
acc.account_num = 34;
ofstream outbal("balance", ios::out | ios::binary);
if(!outbal) {
cout << "Cannot open file.\n";
return 1;
}
outbal.write((char *) &acc, sizeof(struct MyRecord));
outbal.close();
ifstream inbal("balance", ios::in | ios::binary);
if(!inbal) {
cout << "Cannot open file.\n";
return 1;
}
inbal.read((char *) &acc, sizeof(struct MyRecord));
cout << acc.name << endl;
cout << "Account # " << acc.account_num;
cout.precision(2);
cout.setf(ios::fixed);
cout << endl << "Balance: $" << acc.balance;
inbal.close();
return 0;
}
|
|
|
|
|
ashish8patil wrote: i this code it is writting & reading stuct data ,BUt not changing that data...
Of course it's not changing the data. You've shown no code to do that.
ashish8patil wrote: ...i want change that data
So change it and call the write() method again. What's the problem?
"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown
"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
|
|
|
|
|
Plese use the code block button for posting code snippets.
ashish8patil wrote: i this code it is writting & reading stuct data ,BUt not changing that data i want change that data
What do you mean with this? Your program sets the fields of the struct, then write it to disk, and finally read it again from disk. How these operations are supposed to change the content? What is your expected output?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
I am using the below code snippet for retreving the Product version . This works fine when I write this in a sample application. I am retreiving the correct product version Eg. "10.9.8". But when I integrated this code snippet with my project code. then str string in below code gives me return value as "?#@!" Can I know what could have been the problem.
CString GetInstalledIntouchCEVersion()
{
UINT returnCode;
char pProductCode[39]={0};
//char lpVersion[50] = {0};
LPSTR str;
DWORD cchVersionName;
str = new TCHAR[50];
// Here Guid is MSI product upgrade code for InTouchCE
returnCode = MsiEnumRelatedProducts("Our Product Code",0,0,pProductCode);
if ( ERROR_SUCCESS == returnCode )
{
UINT ret = MsiGetProductInfo(pProductCode,INSTALLPROPERTY_VERSIONSTRING,str,&cchVersionName);
}
return str;
}
|
|
|
|
|
Venkat KR wrote: if ( ERROR_SUCCESS == returnCode )
{
UINT ret = MsiGetProductInfo(pProductCode,INSTALLPROPERTY_VERSIONSTRING,str,&cchVersionName);
}
return str;
I see you are 'returning' str with no regards to what MsiGetProductInfo() returned.
Can you check the return value?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
#include <stdio.h>
#include <stdlib.>
#include <string>
main()
{
char s[80];
int i=0;
FILE *fp;
fp=fopen("POEM.TXT","w+");
if(fp==NULL)
{
puts("Cannot open file");
exit(1);
}
puts("Enter any string");
while ( strlen(gets(s)) >; 0 );
{
fputs(s,fp);
fputs("\n",fp);
}
fclose(fp);
}
This prog should write the given output to the text file. But inspite of not giving any errors the text file remains empty!!!
|
|
|
|
|
Take a look at the code you've posted! It is not properly formatted and worse yet some parts are not visible. Please "edit" your post, select all the code and click the "code block" formatting option.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Razanust wrote: while ( strlen(gets(s)) >; 0 );
This line should be
while ( strlen(gets(s)) > 0 )
i.e. without the semicolon at the end.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
|
You are welcome.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
Hello All,
I have structure
student{ char name[10];
int id ;
};
int main()
{
student s ;
///filling data to s
//writting s to file temp.dat
//reading s from temp.dat
}
Now i want to change s.name .
what should i do
thanks all.
|
|
|
|
|
_tcscpy(s.name, _T("Hello")); ?
Are you looking for something else?
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|