|
|
That's what I'm talking about. I like to run code, not just try to read it, especially when an
OP posts a couple pages of code. I DON'T like having to format it so I can look at it without
my eyes bleeding
I'm waiting for Luc to figure it all out...
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Luc and I went into a fair discussion about this yesterday or so. To make things more strange, I've used CPSyntax and it has made things go weird.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
I'm intrigued...what is this "CPSyntax"??
Considering how much time I spend in a browser every day, I should know something about this
stuff
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
CPSyntax is a Grease Monkey script done by Shog to pretty up code in the forums. The code shows up in lines of alternating white/light bluish lines. It was nice until I noticed the copy/paste matters. I may drop Shog a note about it...
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Paul Conrad wrote: CPSyntax is a Grease Monkey script done by Shog to pretty up code in the forums
That's what I thought. Cool! Thanks!
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
It's pretty cool, sometimes I forget I have it on the laptop and not my desktop.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Well I switched to FF after these discussions yesterday. It fixed all my code formatting and copying
gripes except for one - I wish the angle brackets would be left alone in pre formatted blocks.
Sure it's not HTML but there's very few tags supported anyway.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
What about the copy/paste issue that I mentioned in the post to Luc?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
You mean with CPsyntax and the line numbers? I'm not using that so it works fine.
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Now all of the sudden I see links view plainshow original copy to clipboard print ? And it works fine when using the copy to clip board. I wonder why I see it on my desktop, but not the laptop? Cool, I got something to research around on this morning
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
|
|
|
|
|
Mark, I agree!
If you use the forum editor, you can write the following:
<pre><code>
x += 2;
y += 3;
</code></pre>
The editor converts it to this:
<pre><code>
<br>x += 2;<br>
<br>y += 3;<br><br>
</code></pre>
Thus, when you copy the code, the HTML tags get stripped out and you have just one line of code.
Geo
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I've been browsing the HTML code as well...
I forgot one other wish - within a block of code that keeps its spacing and newlines and allows
me to bold or color specific text, I'd also like HTML tags turned off so when I post code I don't
have to go through and manually change the angle brackets (I always miss some too).
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Luc,
I think the problem, in part, is Visual Studio. I have copied some sample code from code project into Microsoft Word, and it retained the format. I, then, copied the code from Word into Visual Studio, and everything looked as expected. I only used a small sample however.
Geo
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
BuckBrown wrote: but I cant figure out the correct way to define the arrays named nIndex and nByte.
You need to create them at some point. Wherever is appropriate - CCoordinate class constructor
maybe?
Create them the same way you create the OriginalData array?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I can't get it to work. I added the constructor for the value CCoordinate class and got the compiler error message "value types cannot contain user-defined special member functions". So I changed the class definition to "ref class CCordinate" and this allowed me to create the constructor and add the array definitions in the CCoordinate constructor. But this broke another part. I had to change...
array[CCoordinate, 2]^ OriginalData; To the following line...
array[CCoordinate^, 2]^ OriginalData; to keep from getting the "need an upper level ^" error.
This all compiled but I can't access any of the variables. Most of CLI is pretty cool but the way they put together the arrays is for the birds. I cna't seem to wrap my head around anything other than a one dimensional array of a basic type (such as int). I can create an array of handles (such as int^) but then I can't below System::Array. Native arrays make so much more sense but CLI won't let me use a native type.
Buck
|
|
|
|
|
Can you repost the classes in question with the "Ignore HTML tags in this message (good for code
snippets)" checkbox checked on your reply?
That will make it easier to see what's going on
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I will attempt to make this bare bones.
ref class CWafer()
{
public:
CWafer(void);
value struct MyStruct
{
int AnIntegerValue;
array<int>^ AnArrayOfIntegers; // How do I define this to be an integer array of 10 ints.
Init()
{
AnArrayOfIntegers = gcnew array<int>(10) // I have tried this and it does not work.
}
};
array<MyStruct, 2>^ TwoDimensionalArray;
MyStruct newStruct;
}
CWafer::CWafer()
{
TwoDimensionalArray = gcnew array<MyStruct, 2>(1000, 1000);
newStruct = MyStruct.Init();
}
This is it! My application uses an x coordinate and a y coordinate, hence a two dimensional array is perfect because for each (x, y) location there are several integer values and integer arrays that need to be accessed. The above code snippet allows me to write "TwoDimensionalArray.AnIntegerValue = 1;" and I would like to be able to do something like write "TwoDimensionalArray.AnArrayOfIntegers[n] = 2;" but the array is undefined. It seems that the managed heap is being gabage collected before I can use it but I don't see anything wrong with the scope.
|
|
|
|
|
I'm not sure what value (pun intended) you're getting out of using a value struct here, since
you're not creating heap objects and they need to be initialized.
Beyond that, compare the following with your code. Most of the changes were regular C++
related...
ref class CWafer
{
public:
CWafer();
value struct MyStruct
{
int AnIntegerValue;
array<Int32>^ AnArrayOfIntegers;
void Init()
{
AnArrayOfIntegers = gcnew array<Int32>(10);
}
};
array<MyStruct, 2>^ TwoDimensionalArray;
MyStruct newStruct;
};
CWafer::CWafer()
{
TwoDimensionalArray = gcnew array<MyStruct, 2>(1000, 1000);
for (int i = 0; i < 1000; ++i)
{
for (int j = 0; j < 1000; ++j)
{
TwoDimensionalArray[i,j].Init();
}
}
newStruct.Init();
}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Okay, getting closer. This has to be a scope issue. Just as before, the two dimensional array was initialized, then the one dimensional array was initialized (inside the CWafer constructor). Then several functions are called from within the constructor, one of those accesses these arrays. When the function is called the arrays become undefined. I suppose I might be able to pass them as arguments but there is some confusion on how gcnew works. In C++ MFC I would declare types in the header file and then create them with "new" in the constructor. Then if I called a series of functions from the constructor I could "see" within the functions the type as I had defined it in the constructor. If I use "gcnew" then call a function from the constructor the definition is immeadiately lost. I saw this same behavior with another class where my CWafer class had to instantiate a CLtx class (contains some parameters that my CWafer class uses). In the CWafer constructor I instantiated a "CLtx^ LtxFile = gcnew CLtx^;" because I wanted all kinds of CWafer functions to use LtxFile. Unfortunately I had to instantiate the LtxFile inside of each function as it was called. This basic difference in scope is huge and causing me all kinds of problems (current one included). I understand that the garbage collected heap will release the memory when it is no longer needed but why is it reclaiming memory just because I have called a function from within the CWafer constructor?
Buck
|
|
|
|
|
The same scoping rules apply as with unmanaged C++.
BuckBrown wrote: Then several functions are called from within the constructor, one of those accesses these arrays. When the function is called the arrays become undefined.
How is this function accessing the arrays if it's not a member function? You must be passing
something, because just like unmanaged C++, you need to have an object to access non-static class
members.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Okay, I slept on it and figured out what was happening, and yes, it is my bad big time. What was happening with the scope was that at some point in time (probably in order to correect a compiler error) I edited the constructor to re-declare the arrays. So when I called a function from within the constructor and had my arrays seem to go undefined was really the debugger referencing the arrays declared in the header file, NOT the arrays re-declared in the constructor. Anyway, I have now got the declarations, definitions, and initializations of these arrays working, but I still think the way CLI does multi-dimensional arrays is for the birds.
Thanks for all your help. Glad to see this started a onversation between you all on that format issue.
Buck
|
|
|
|
|
Actually, the more I look at it, the value struct is fine. I'll drop that topic
And you can change those Int32s back to ints
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I am using Visual c++ NET 2005
Who can I set focus to a control in the same form ?
|
|
|
|
|
RTFM
|
|
|
|