|
If your project is SDI or MDI then you gave a class drived from CWinApp.
look at the header file there is an extern object. declare your object just like that.
www.logicsims.ir
|
|
|
|
|
|
Just Declare in stdAfx.h without extern.
CString tmp; is enough.
G.Paulraj
|
|
|
|
|
If you need a variable visible to all classes of your project, an option maybe a static member variable of your CWinApp -derived class.
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]
|
|
|
|
|
Doesn't need to be static. Presumably, there's only one instance of the app and it's there for the duration. But I like the placement.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Doesn't need to be static? The OP said he needs it 'everywhere'. For instance, think of those classes that are his own (and have no access to the CWinApp derivative). They won't be able to touch the variable unless it is static.
The fact that I consider a singleton class instead of a global variable a better option is aside though.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
You have access to the instance of the CWinApp derived class anywhere you include the .h file with extern AppClass the App. There is only one of them. The member of that class he wants is NOT static but a regular memeber. There is, presumably, still only one of them and it's available anywhere through the app instance, theApp.theVarible or theApp.GetVariable() depending on how anal you are about accessor functions. I fall into the anal category.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Never mind, I actually got your comment wrong. I fall into your category as well.
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Tim Craig wrote: You have access to the instance of the CWinApp derived class anywhere you include the .h file with extern AppClass the App.
There's no need to expose the application object anywhere you need just one variable.
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]
|
|
|
|
|
True, but then there's no technical reason we need object oriented code either. But if a variable needs to be seen by the whole application, then encapsulating it in the app class seems the perfect place for it.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
|
Gee, seeing as how theApp is global anyhow, I'd say he has access to them whenever he wants. Of course, I seem to remember getting smacked around in some forum here when I said sealed classes were a stupid idea but maybe that was just some C# twits who happened to be wandering by.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
|
|
|
|
|
Out of curiosity, why do you need a global variable that can be accessed by "whole class in the project"? I think that a singleton class would be the best option, but I'd like to know the reason first...
“Follow your bliss.” – Joseph Campbell
|
|
|
|
|
Hi...
My code is...
{
CString m_usrDia, value;
for(int i=0;i<10;i++)
{
m_lstctrl.SetItemText(i,0,value);
m_lstctrl.SetItemText(i,1,value);
m_lstctrl.SetItemText(i,2,value);
if(m_usrDia == value)
{
m_lstctrl.SetItemText(i,3,value);
}
else
{
m_lstctrl.DeleteItem(i);
}
}
}
it is not working.
If the cstring values of m_usrDia, value are equal then the value have to set in the listctrl item. otherwise it should be delete the whole line.
can anyone please help me?
Thanks.
G.Paulraj
|
|
|
|
|
First of all, you never seem to give any value to your string variables. But i will asssume you do somewhere in your code and this is just a stripped version so we see what those are. Then, what is the point of setting the itemtexts and after you done that, checking if you set them to a certain string and if you did then deleting them? Why not check first and set the items only if needed? Then, as i see, none of your string variables ever change in that loop, so it will either try to delete everything or nothing. Then, if you delete items in a for loop you should rather go from back to front, meaning -based on your code sniplet- for (int i=9;i>=0;i--)... because if you go in an "increasing order" then you will most likely skip items since when you delete an item, the index of all the other items after it will change but your loop variable doesn't take that into account.
p.s: please the next time you submit code, put it between code block tags, that is, <pre> and </pre>, this makes it much more readable, thanks.
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Sometimes you just have to hate coding to do it well. <
|
|
|
|
|
gnanapaul wrote:
it is not working.
No surprise, as it's a disaster in the making. You can't add/change items and delete other items in the same loop. When an item is deleted, all other items below that one get renumbered. If you insist on doing it this way, change the for() loop to be:
for (int i = 9; i >= 0; i--)
{
m_lstctrl.SetItemText(i, 0, value);
m_lstctrl.SetItemText(i, 1, value);
m_lstctrl.SetItemText(i, 2, value);
if (m_usrDia == value)
m_lstctrl.SetItemText(i, 3, value);
else
m_lstctrl.DeleteItem(i);
}
"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
|
|
|
|
|
Hello,
I opened a multiband(band number>3) tiff image with gdalopen(). Then, use gdaldataset::getrasterband to get 3 bands as RGB bands to create a bitmap. And i use stretch to draw the bitmap in view class.
For most multiband tiff images, the image shown on the screen is identical to that opened by commercial software, such as erdas or envi.
But for some multiband tiff images, the image drawn on the screen is quite colorful. The shape and location of objects in the image is correct, but the color is distorted, and different from envi with the same input channel set and many possible input channel sets as well.
could anyone who is familar with gdal help me fix up this problem?
|
|
|
|
|
the best way i've found to diagnose TIFF issues is with TIFFDUMP (source comes with LibTiff, but you can probably find an EXE with Google). it will display all the tags in the TIFF.
so you can see what colorspace the TIFF uses, the order of bytes, samples per pixel, etc.. odds are that whatever TIFF reader you're using just isn't catching some tag combination. given the number of possible combinations, it's not uncommon for a TIFF reader to choke on some variants...
|
|
|
|
|
Hi all,
How to prevent same program can open twice in windows?I want limit my program can only 1 time in windows only. Can anyone suggest me a method to do it?
|
|
|
|
|
|
Thank you. This solve my problem
|
|
|
|
|
I've already written my code in C# and it works. But to integrate it into our product, I have to re-write it C++ 6.0. I'm very weak here and am lost. My problem is this: I start with a line extracted from a file. The string contains a variable number of individual commands consisting of one letter followed by a number. In C# my code is built like this:
private string[] LineSplitter(string LineIn){
if (LineIn == "")
return null;
string[] strOut = new string[0];
int i = 0;
string strChar;
do
{
...code to locate length of number following letter
} while ((isNumeric(strChar)) && (i + 1 < LineIn.Length));
strOut = (string[])ResizeArray(strOut, strOut.Length + 1);
strOut[strOut.Length - 1] = LineIn.Substring(0, i);
LineIn = LineIn.Substring(i);
} while (LineIn.Length > 0);
return strOut;
}
(And I'm sorry for putting C# in a C++ group, but I'm looking for the C++ equivalent)
Here are my questions...
1. How do I declare the function as string array?
2. How do I increment array elements until I'm done? Each line can have a variable number of elements.
3. How do I return the result.
Please be gentle. I'm struggling with C++ and this is my first post. I'm wrestling through the majority of everything else in this process, but this has my brain in a pickle.
|
|
|
|
|
Mark Randel wrote: 1. How do I declare the function as string array?
Not exactly an array but this is the C++ way -
std::vector<std::string>
Mark Randel wrote: How do I increment array elements until I'm done? Each line can have a variable number of elements.
while (LineIn.size() > 0)
Mark Randel wrote: How do I return the result.
std::vector<std::string> strOut;
.
.
.
return strOut;
modified on Wednesday, November 18, 2009 5:53 PM
|
|
|
|
|
Thanks a lot. The vector was the key to what I was looking for. I'm using CString , though. But it all works fine.
My question about adding to the array was concerning changing the size of the array. The vector makes that easy with the push_back command.
Also, returning the value from the function required that I make the type of the return as a vector:
std::vector<CString> CNCLine::LineSplitter(CString LineIn)
{
std::vector<CString> strOut;
... code
return strOut;
}
Works like clockwork. Thanks for the direction.
____________________________________________________
I'd rather have a frontal lobotomy than a bottle in front of me... Bill W
|
|
|
|
|
Interesting... the post erased the "<cstring>" command after the vector designation. Hope it doesn't with this text. Otherwise, I'm going to end up looking quite foolish.
____________________________________________________
I'd rather have a frontal lobotomy than a bottle in front of me... Bill W
|
|
|
|