|
Are you still having trouble with this?
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
No, I'm just reading the file one character at a time and checking for nulls. Seems to be working fine.
Thanks.
Buck
|
|
|
|
|
Sounds like you have it right now. Any problems let me know
"Any sort of work in VB6 is bound to provide several WTF moments." - Christian Graus
|
|
|
|
|
hello,
how to declare a globale variable for 2 or all methodes ?
|
|
|
|
|
Is there a good reason you need to use global variables in a C++/CLI application?
If so, you can simply define a variable in any CPP file, outside of any function or class
declaration:
// Global int
int MyGlobalInt = 0;
To access the global variable from another CPP module, use "extern":
// MyGlobalInt exists in another module
extern int MyGlobalInt;
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
Hi, everyone,
Postfix p;
char *postfix = p.convertToPostfix(infix);
//p.convertToPostfix(infix) returns a pointer
I would like to write a method in Postfix class to overload the "=" operator so that the left pointer gets a deep copy of the right pointer(returns from a method in the class).
How do I write it?
Thanks.
|
|
|
|
|
Here's one way (you'll have to do the actual deep copy yourself since I don't know the details of
your class - my sample implementation just demonstrates a possible deep copy scenario):
class Postfix
{
protected:
someclass *pSomeClass;
public;
Postfix* operator=(const Postfix *Src);
};
Postfix *Postfix::operator=(const Postfix *Src)
{
if (this->pSomeClass)
delete this->pSomeClass;
this->pSomeClass = new someclass(...);
... copy Src->pSomeClass to this->pSomeClass ...
return this;
}
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
hi;
i would add in listView, for this i need to declare an array of string:
String *subItems[] = new String*[10];<br />
subItems[4]="1";<br />
subItems[2]="2";<br />
subItems[3]="3";<br />
subItems[1]="4";<br />
subItems[5]="5";<br />
<br />
<br />
ListViewItem* itm = new ListViewItem(subItems);<br />
listView1->Items->Add(itm);
but it didn't work,
i try for :
<br />
cli::array<String ^, 1> ^ tabChaine = gcnew cli::array<String ^>(3);<br />
tabChaine[0] = "Element 1";<br />
tabChaine[1] = "Element 2";<br />
tabChaine[2] = "Element 3";<br />
<br />
this->listView1->Items->Add(tabChaine);
=> there are error :Error cannot convert parameter 1 from 'cli::array<type,dimension> ^' to 'System::String ^'
Thank you verry mutch
|
|
|
|
|
You need to use the .NET framework classes documentation.
There's no ListView.ListViewItemCollection.Add() overload that takes an array of Strings as a
parameter.
You could add one string at a time:
listView1->Items->Add("Element 1");
listView1->Items->Add("Element 2");
listView1->Items->Add("Element 3");
or maybe use ListView.ListViewItemCollection.AddRange().
Mark
-- modified at 16:07 Sunday 15th July, 2007
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
By the way, your code is wrong as far as creating an array of strings! It should be:
<br />
array<String^>^ tabChaine = gcnew array<String^>(3);<br />
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
I assumed his angle brackets got html-formatted out.
That could be a completely invalid assumption
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
Sorry, your assumption was correct. I loaded the source HTML and found:
cli::array<String ^, 1> ^ tabChaine = gcnew cli::array<String ^>(3); I guess we need to learn to check "Ignore HTML tags in this message" more often.
Geo
P.S. Thanks for your great answers and sense of humor in this forum.
"We make a living by what we get, we make a life by what we give." --Winston Churchill
|
|
|
|
|
George L. Jackson wrote: I loaded the source HTML and found
Too much work for me....if I can't assume (wrongly or not) I'll ask the OP to repost.
I'm lazy
Thank you for your great posts as well! I just migrated all my code to VS2005 within the last
week. I've been using managed extensions for .NET coding so I put alot of stuff off so I
wouldn't get nailed with migration issues. Now that I can use it, I'm always watching posts for
new tips on managed code!
Cheers,
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
i have creat capture.h et capture.cpp, in 1st i declared all variables us folow:
<br />
class capture<br />
{<br />
public:<br />
capture(void);<br />
~capture(void);<br />
public:<br />
int i;<br />
int k;<br />
void Ap();<br />
};
and for capture.cpp
<br />
#include "StdAfx.h"<br />
<br />
#include ".\capture.h"<br />
<br />
using namespace System;<br />
<br />
void capture::Ap() {...........................}
When i add capture.h {#include "capture.h"}in forme1.h, knowing that variable i déclared in capture.h.
In form1.h i use a variable i without declaration, there are error 'i' : undeclared identifier .
Please help me,
Thank you verry mutch
|
|
|
|
|
You haven't shown any global variables. All the variables shown are members of the class
capture.
You also didn't show how and where you try to use 'i'.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
i use it us folow
public ref class Form1 : public System::Windows::Forms::Form<br />
{public:<br />
Form1(void)<br />
{ InitializeComponent();<br />
<br />
<br />
}<br />
<br />
protected:<br />
~Form1()<br />
{<br />
if (components)<br />
{<br />
delete components;<br />
}<br />
}<br />
<br />
<br />
<br />
<br />
#pragma region Windows Form Designer generated code<br />
void InitializeComponent(void)<br />
{.............................}<br />
<br />
<br />
<br />
<br />
private: System::Void button12_Click(System::Object^ sender, System::EventArgs^ e) {<br />
<br />
for (i=0;i<3;i++){...........}<br />
}.<br />
.<br />
.
thank you verry mutch
|
|
|
|
|
'i' would have to be used in a "capture" class method. 'i' is not global.
button12_Click() is not a capture class method so you need to define an automatic variable 'i'.
Two examples (2 different scopes for 'i'):
for (int i=0;i<3;i++){...........}
or
int i;
for (i=0;i<3;i++){...........}
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
But when i was modified in button12, i can't see the modification in back of button12,
i would declare i in capture.h, and use it in form1.h by adding #include "capture.h", but unfortunaly this variable can't be identifiable in form1.h
Help me,
Thank you verry mutch
|
|
|
|
|
A variable needs to be static to be used without a class instance that contains it.
A delegate is a better way to communicate between classes.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
As Christian mentioned, i would need to be static to access it without an object of the capture
class.
You're leavig something out of your posted code so it's hard to help you.
Is button12_Click() a delegate? Is it a class member function (method)?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
"Great job team! Head back to base for debriefing and cocktails."
|
|
|
|
|
hi,
i would use delegate with associate a function
public :delegate void deleg(Packet^ e);<br />
event deleg ^arr;<br />
<br />
<br />
<br />
arr += gcnew deleg(this, DisplayListbox(e.Packet));<br />
<br />
arr(e.Packet);<br />
}<br />
<br />
void DisplayListbox(Packet^ value)<br />
{.................. }
there are error : Error 1 error C3364: 'BHIDS00::Form1::deleg' : invalid argument for delegate constructor; delegate target needs to be a pointer to a member function c:\documents and settings\abbd\bureau\bhids0.4\bhids0.0\Form1.h 788
thank you verry mutch
|
|
|
|
|
As indicated in the error message, the second parameter of the constructor needs to be the
address of a method, something like:
&class::methodname
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
I know the reason that when we need to do shallow copy.But how copy constructor resolve this problem?I am not able to understand.
So please reply me as soon as possible.
Regards,
Pankaj Sachdeva
|
|
|
|
|
Please post questions not related to managed C++ on the
Visual C++/MFC board[^]
It's up to you to decide how objects are copied, either using the assignment operator or a copy
constructor. The difference between the two is right in the names -
An assignment operator assigns the "value" of one object to another object.
A copy constructor does the same but it's a constructor - it constructs the destination
object.
The compiler can only provide default copy semantics for objects based on the class of the object.
For any class which doesn't provide operators, this means a bitwise, binary copy.
In the case of pointers, this may not be what you want. You may want a copy of the data pointed
to by a pointer (deep copy), not just a copy of the pointer (shallow copy). To do this you need
to implement assignment operator(s) and/or a copy constructor for a class.
Mark
Mark Salsbery
Microsoft MVP - Visual C++
This episode brought to you by the number 3
|
|
|
|
|
I have to write the event handler for MSCOMM.OnComm who is listening to serial port for data, so that the event is fired 'OnComm' is executed when the data is arrived.
My understanding for the documentation is unclear as how to achieve this.
Does any one have the sample source code implementation in C# / C++?
Thanks and Regards.
Amar.
|
|
|
|