Thanks a lot, I'll go find out more about it. Regards, Arjen
KlaasVersteeg
Posts
-
Use of managed variables in non-ref class -
Use of managed variables in non-ref classHi, I am currently working on extending an existing C++ project with new functions. The existing project is made using C++, without using managed variables. I would like to insert some of my function which I have written in C++/CLI, so with managed variables. Is it possible to declare a managed variable within a class, without making the class a ref class? If I have to make it a ref class it produces a load of errors, as it is connected with parts of existing code that cannot deal with that. Any ideas would be more than welcome! Thanks, Arjen
-
How to stop a simulation while runningThat indeed looks interesting for what I'm doing, I'll have a look at it. Thanks again!
-
How to stop a simulation while runningLuc, I found out I did indeed not follow your point #6, I guess I didn't completely understand. Now it works fine, thanks a lot for all your quick and useful help!! Regards, ATJA
-
How to stop a simulation while runningThanks a lot for your comments! I've used them in my code, but the problem with debugging is still not solved. My start button contains the following code:
simWorker = gcnew BackgroundWorker;
simWorker->WorkerSupportsCancellation = true;
simWorker->WorkerReportsProgress = true;
simWorker->DoWork += gcnew DoWorkEventHandler(this, &uDP2::DPSim::simWorker_DoWork);
simWorker->ProgressChanged += gcnew ProgressChangedEventHandler(this, &uDP2::DPSim::simWorker_ProgressChanged);
simWorker->RunWorkerCompleted += gcnew RunWorkerCompletedEventHandler(this, &uDP2::DPSim::simWorker_RunWorkerCompleted);
butReset->Enabled = false;
butPause->Enabled = true;
butStart->Enabled = false;
simWorker->RunWorkerAsync(model);When I compile and run the program this works fine, the last line in this code runs the actual model. However, when I step through the code in debug mode the last line seems to be skipped; it passes this line without running the model. I don't have a clue what's going on here, this seems to be very strange to me... Update: It seems that the code which updates the data on my Graphical User Interface in each timestep causes the problem. I have an "updateGUI" function which is called in each timestep from the simulation, which is again called by RunWorkerAsync. The updateGUI function contains:
lblTime->Text = Convert::ToString(Math::Round(\*model->state->t,2)); txtX->Text = Convert::ToString(Math::Round(model->state->eta\[0,0\],2)); txtY->Text = Convert::ToString(Math::Round(model->state->eta\[1,0\],2)); txtPsi->Text = Convert::ToString(Math::Round(model->state->eta\[5,0\],2)); lblWindDirSim->Text = Convert::ToString(\*model->environment->windDir / Math::PI \* 180);
If I comment this out the code runs fine in debug mode, otherwise it doesn't. Any idea what the problem could be?
modified on Thursday, June 24, 2010 5:41 AM
-
How to stop a simulation while runningThat makes sense... Here is the relevant part of my code. I made a BackgroundWorker called simWorker, and a start and stop button which should, obviously, start and stop my simulation. Starting it works fine when I compile the code, but nothing happens when I run in debug mode. The stop button is not working yet, I'm still finding out how to deal with that. Hope you can think of something to make this also run in debug mode, that would make life much easier. Thanks!
namespace uDP2 {
public ref class DPSim : public System::Windows::Forms::Form
{
static clModel^ model = gcnew clModel;
public:
DPSim(clModel^ mdl)
{
InitializeComponent();
model = mdl;
InitializeSimWorker();
}protected: ~DPSim() { if (components) { delete components; } } private: System::ComponentModel::IContainer^ components; protected: private: System::ComponentModel::BackgroundWorker^ simWorker; void InitializeSimWorker(){ simWorker = gcnew BackgroundWorker; simWorker->DoWork += gcnew DoWorkEventHandler( this, &DPSim::simWorker\_DoWork ); } void simWorker\_DoWork( Object^ sender, DoWorkEventArgs^ e ){ BackgroundWorker^ worker = dynamic\_cast<BackgroundWorker^>(sender); e->Result = simulate(model, worker, e); }
#pragma region Windows Form Designer generated code
{
// code to generate form and components
}
#pragma endregion
private: clModel^ simulate(clModel^ model, BackgroundWorker^ worker, DoWorkEventArgs^ e){
// run simulation
return model;
}
private: System::Void butStart_Click(System::Object^ sender, System::EventArgs^ e) {
simWorker->RunWorkerAsync(model);
}
private: System::Void butStop_Click(System::Object^ sender, System::EventArgs^ e) {
model->state->modelRunning = Convert::ToInt32(0);
}
};
} -
How to stop a simulation while runningThanks, it works now! However, there is one very strange thing. When I compile the code everything works, but in debug mode nothing happens if I click the button that triggers the backgroundworker events. Any idea what this problem could be?
-
How to stop a simulation while runningLuc, Thanks for your answer! I'm trying to use a backgroundworker, but I'm having some trouble with getting it to work. I followed the example on MSDN, and first put:
System::ComponentModel::BackgroundWorker^ worker
in the code. Then I try to initialize the worker by:worker->DoWork += gcnew DoWorkEventHandler(this, &form::worker_doWork);
But now I get an error on this last line while running the program: "Object reference not set to an instance of an object". Any idea what the problem could be? ATJA -
How to stop a simulation while runningI am building a program which is to run time-domain simulations. I made a form with a start button which kicks-off the simulation. I now want to make a button to stop the simulation. I made a boolean which is set to true when the simulation is started, and the simulation runs in a while loop as long as this boolean is true. Then I made a stop button which sets the boolean to false. However, when I click the stop button nothing happens. It seems as if this event is only dealt with after the simulation is ended. Does anyone have an idea on how to deal with this? Any idea is very welcome! ATJA
-
loop through comboboxesSolved! I made a typo in Richard's code (forgot the ^ symbol in the cast part). Now it works, thanks a lot for your help!
-
loop through comboboxesRichard, this makes sense. However, when I compile this code I get: error C2440: 'type cast' : cannot convert from 'System::Windows::Forms::Control ^' to 'System::Windows::Forms::ComboBox' Any idea how to solve this?
-
loop through comboboxesvoo doo12, I've tried this, but when I run the program I get an error that says: "Unable to cast object of type 'System.Windows.Forms.Button' to type 'System.Windows.forms.ComboBox'. So it seems that if the program encounters a control which is not a ComboBox it cannot deal with it in this way.
-
loop through comboboxesHi, Ik have a form containing a number of comboboxes, called cmb1, cmb2, etc. I want to loop through these boxes to set their itemlist. I have tried the following code:
for each (Control^ box in this->Controls){
if (box->GetType() == ComboBox::typeid){
box->Items->Clear();
}
}This works fine, except that I cannot access the combobox's
Items
property. I can for instance access theText
property, so I think it's strange that theItems
property is missing. Does anyone have an idea how to solve this? Thanks! -
[] symbol appears in string when reading from / writing to fileHi, I have written a piece of code to save data from a Windows form in a file, and to read it from the file back into the Windows form. This works fine on the computer on which I've written the code (Windows 7). However, now I try to run the program on another computer (Windows XP), and a strange thing happens: when I read the data from the file, a rectangle character appeard at the end of each line. When I write the data to the file, another such character is written to the file. So every time I save and read a file, an extra rectangle character is added. I'm using streamwriter / streamreader for the file input / output. Any idea how to prevent this strange behaviour?
-
BinaryWriter writes empty fileWell, the file was actually written, so the create time changed. It was only the referece where to write the data to that as wrong, and that I didn't catch when stepping through the code. But now it works. Thanks again for the help!
-
BinaryWriter writes empty fileHi Luc, I found out that something was going wrong with my
fileName
indeed. Its working now. Thanks a lot for your help! -
BinaryWriter writes empty fileThat's strange. I'll try it on another computer, maybe that helps. Thanks a lot for your help anyway!
-
BinaryWriter writes empty fileThanks for your answer Richard. I tried running in the debugger. I do have some data to write to the file. How can I check whether it is actually written to the file? When I check the file in Windows Explorer it stays at 0kb.
-
BinaryWriter writes empty fileI forgot to mention that
fileData
is anarray<String^,2>^
-
BinaryWriter writes empty fileHi, I'm trying to write a binary file, using BinaryWriter. My code does write a file, but it is empty. This is the code I'm using:
FileStream^ fs = gcnew FileStream(Convert::ToString(fileName), FileMode::Create); BinaryWriter^ w = gcnew BinaryWriter(fs); int rows = fileData->GetLength(0); int cols = fileData->GetLength(1); try { for (int row = 0; row < rows; row++){ for (int col = 0; col < cols; col++){ w->Write(fileData\[row,col\]); } } } finally { w->Close(); fs->Close(); }
Does anyone have a clue why the written files is empty? Thanks!