|
I think you;ve answered your own question
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
hi all!!
i am facing a problem i am bnot able to understand!!!
consider the foll codes in my project
CPrjView pview;
long c1=pview.ctr;
these r lines written in a c.cpp
and it includes the PrjView.h file
ctr is a public variable of The CPrjView class of type long
i am not underrstanding that why c1 is getting a very strange value!!!
for ef ctr is 3 and still c1 is getiing a value like -85899346
also i am not able ti change the values of variables in this c.cpp
for eg if i write
pview.ctitle="ABC";
ctitle is a public variable of CPrjView class of type CString it is giving a run time error...
please help!!!1
|
|
|
|
|
doing CPrjView pview; calls the default constructor CPrjView::CPrjView() .
be sure you're correctly initializing ctr into this constructor, because it seems to be nowhere else getting a value...
maybe you think it contains 3, but it doesn't. did you use the debugger ?
what happens if you do the following ?
pview.ctr = 3;
long c1 = pview.ctr;
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
thanks a lot!!!!!!!!!!1
it solved my prob....i need practice!!!!!!
thanks
but can u also advice me something
i wan t to permanently save the changes made in an array of strings.....
i tried to use databse for it but cud not...do u know hot to get data from multiple tables in different variables
thanks again
|
|
|
|
|
what database do you use exactly ? if MS SQL Server, ADO is the best way (i consider you know about SQL though - see Carlos Antollini's ADO Classes[^] for that).
if you use simple files, it will depend on how you format them...
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
i am using access datase linking by odbc....
is ado better???or it is possible to do so in odbs using access database
acually the thing is i am already using a database for retrieving data in a form in this same project....
i now want to use another table in the same database for retriving data in to another form
plz help or suggest a diff way
thanks
|
|
|
|
|
sorry, i don't know at all how to use access DB...
you should ask this in a separate thread...
(search also on codeproject && google ; there are certainly many useful articles on the subject)...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi,
U can use CDaoDatabase and CDaoRecordset Classes to handle databases. U can directly open access(.mdb) databases and also thro odbc. These classes support both of them. U can also ADO. it is better than DAO. Refer MSDN for more details.
Bye
Cool Ju
|
|
|
|
|
thanks a lot
it solved my prob thanks again!!!
but can u tell me another thing
plz suggest me a medthod to permanently save the changes made during run time into a array of strings in vc++
i tried to use database but am unable as i am already using a database to get data into a form in the same project
do u know how to get data from multiple tables in the same project into diff forms...
thanks again
|
|
|
|
|
smartymanav wrote:
for ef ctr is 3 and still c1 is getiing a value like -85899346
Never define a variable anywhere without giving it a default value. Otherwise, this is what you get. I think the other response covers your more specific problem.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
How to get such a kind of operator= overloading that given a class instance we will be able to do this
class Test
{
int m_data[10][10];
public:
void operator=(int x);
};
Test tst;
tst(2,3) = 20; //and that 20 number will be put to m_data[2][3] ?
9ine
|
|
|
|
|
You can't, at least I don't think so.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
i don't understand you're problem...
you want to overload the operator=() for your class Test ?
nop, it's not actually what you want. here, you need an operator=() that returns an int . right ?
but what you can't do is reaching the (2,3) cell in your array.
so, you have to overload the operator()() ...
<font color=blue>class</font> Test {
<font color=blue>int</font> m_data[10][10];
<font color=blue>public</font>:
Test();
<font color=blue>virtual </font>~Test();
<font color=blue>void operator</font>=(<font color=blue>int</font>); <font color=green>
<font color=blue>int</font>& <font color=blue>operator</font>()(<font color=blue>int</font> x, <font color=blue>int</font> y);
};
<font color=blue>int</font>& Test::<font color=blue>operator</font>()(<font color=blue>int</font> x, <font color=blue>int</font> y) {
<font color=green>
<font color=blue>if</font> (x < 0) x = 0;
<font color=blue>if</font> (y < 0) y = 0;
<font color=blue>if</font> (x > 10) x = 10;
<font color=blue>if</font> (y < 10) y = 10;
<font color=green>
<font color=blue>int</font>& ri = m_data[x][y];
<font color=blue>return</font> ri;
}
this way, when you do:
Test tst;
tst(2, 3) <font color=green>
= 20; <font color=green>
ASSERT(tst(2,3) == 20);
Test *pTst = &tst; <font color=green>
(*pTst)(2, 3) = 21; <font color=green>
ASSERT(tst(2,3) == 21);
cheers,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
It is not the = operator that you need to overload but rather the [] operator. But in your case you have two nestled [] operators so you will need to make use of an intermediate class (like RowTest).
Something like that:
<br />
class RowTest<br />
{<br />
int m_data[10];<br />
public:<br />
int& operator[](int x);<br />
};<br />
<br />
<br />
class Test<br />
{<br />
RowTest m_data[10];<br />
public:<br />
RowTest& operator[](int x);<br />
};<br />
Then, by overloading this operator you will be able to do this:
Test tst;<br />
tst[2][3] = 20;
But of course there is an extra class involved. The syntax is perhaps not correct because I don't play a lot with these kind of things.
Hope this helps
|
|
|
|
|
nop, not the operator[]() because it can get only once value between the [ ] ...
prefer operator ()() ...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Yes, that's why you need to make use of an intermediate class... But ok, it may be a little bit too complicate. The other solutions were simplier
|
|
|
|
|
I dont need extra class I'm going to check out of range x,y for m_data[x][y] in overloaded operator so I need that class will act as an array.
With simple array we can assign a value to it and read it:
int val;
val = m_data[x][y];
m_data[x][y] = val;
All this I want to be done by class
class Test
{
int m_data[10][10];
public:
int operator()(int x, int y);
};
int Test::operator()(int x, int y)
{
//check if x,y out of range
return m_data[y][x];
}
1. so we can read value by overloaded () operator
Test tst;
int val = tst(2,3); //which equ to val = m_data[x][y]
2. how to implement m_data[x][y] = val by Test class and what operator to overload?
if we overload just = operator then we will be able just
Test tst;
tst = 5; //but its not possible with this to provide x,y coeffs for m_data[x][y]
9ine
|
|
|
|
|
9ine wrote:
int Test::operator()(int x, int y)
{
//check if x,y out of range
return m_data[y][x];
}
it won't work until it returns an int (copy of the actual value... so, it is not an lvalue, an the compiler won't accept you to assign the result of the operator()() .
use int& instead, as i did in my first answer[^]...
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
And how to be with class pointers?
with Test tst;
we get nice brief form:
int a = tst(3,2);
but with class pointer Test *tst1 = &tst;
we get bulky notation:
int b = tst1->operator()(3,2);
is it possible to something like tst(3,2) with pointer to class?
9ine
|
|
|
|
|
wohhhhh, no no no
use the defenrenciation operator...
Test *tst1 = &tst;
int b = (*tst1)(3, 2);
hope this helps you
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Thanks very much, I've done it completely and it works!
9ine
|
|
|
|
|
9ine wrote:
Thanks very much, I've done it completely and it works!
you're welcome... i'm always happy when i reach helping people usefully...
ps: if you liked my post, don't forget to vote for it !
ps 2 : i edited my previous answer[^] to consider using pointers.
cheers dear,
TOXCCT >>> GEII power [toxcct][VisualCalc]
|
|
|
|
|
Hi,
I'm using VC7 and MFC.
I create a ListBox control using the dialog editor and the toolbox and I attach it a control variable of the type CListbox.
On the other hand I create another list manually, declaring a CListBox variable and calling Create.
I use AddString to add new items, but the fonts are different. The manually created list has some kind of bold font.
I have tried everything. Changing the create styles, trying to use CreateEx, but I cannot get they to look the same.
I have the same problem with combo boxes.
I would appreciate any idea. Can anybody help me?
|
|
|
|
|
I think that the code that is generated for you to create the control you dragged on includes code to set the font. I believe it has a Font property, or something like that.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thank you very much for your fast response.
I decided to create those controls manually because I have a dialog window with edit controls, list boxes and combo boxes.
If I use the dialog editor and attach the control variable to them, some work properly when I add data, but others raise the error ERROR_INVALID_WINDOW_HANDLE.
And I do not destroy the dialog window or the controls.
Thank you again for our fast response.
|
|
|
|