Re: declare & initialize array?
- From: "Markus Minichmayr" <news_mima@xxxxxxxxxxx>
- Date: Tue, 16 Aug 2005 22:37:01 +0200
Hi Geoff!
Declare the array like
private: System::String __gc* myArray __gc[];
and initialize it anywhere you want like
this->myArray = new System::String* __gc[2];
this->myArray[0] = "element 1";
this->myArray[1] = "element 2";
Hope that helps!
- Markus
<Geoff Cox> schrieb im Newsbeitrag
news:bqb4g19v800ihiii46m7l4ukc3m6ngo27s@xxxxxxxxxx
> Hello,
>
> Can I separately declare and initialize a string array? How and where
> would I do it in the code below? It was created using Visual C++ 2005
> Express Beta 2 ...
>
> In C# I would have
>
> private string[] myArray;
>
> and later
>
> myArray = new string[] {"element 1","element 2"};
>
> Now, I know C++ is more difficult to learn than C# but .......
>
> Thanks
>
> Geoff
>
>
>
> #pragma once
>
> namespace slider1
> {
> using namespace System;
> using namespace System::ComponentModel;
> using namespace System::Collections;
> using namespace System::Windows::Forms;
> using namespace System::Data;
> using namespace System::Drawing;
>
> public ref class Form1 : public System::Windows::Forms::Form
> {
>
> public:
>
> Form1(void)
> {
> InitializeComponent();
> //
> //TODO: Add the constructor code here
> //
>
> }
>
> protected:
> /// <summary>
> /// Clean up any resources being used.
> /// </summary>
> /// <param name="disposing">"description of the
> parameter"</param>
> virtual void Dispose(Boolean disposing) override
> {
> if (disposing && components)
> {
> delete components;
> }
> __super::Dispose(disposing);
> }
> private: System::Windows::Forms::PictureBox^ pictureBox1;
> protected:
> private: System::Windows::Forms::Button^ button1;
> private: System::Windows::Forms::Label^ label1;
> private: System::Windows::Forms::Label^ label2;
> private: System::Windows::Forms::TrackBar^ trackBar1;
>
>
> private:
> /// <summary>
> /// Required designer variable.
> /// </summary>
> System::ComponentModel::Container ^components;
>
> #pragma region Windows Form Designer generated code
> /// <summary>
> /// Required method for Designer support - do not
> modify
> /// the contents of this method with the code editor.
> /// </summary>
> void InitializeComponent(void)
> {
>
> System::ComponentModel::ComponentResourceManager^ resources = (gcnew
> System::ComponentModel::ComponentResourceManager(Form1::typeid));
> this->pictureBox1 = (gcnew
> System::Windows::Forms::PictureBox());
> this->button1 = (gcnew
> System::Windows::Forms::Button());
> this->label1 = (gcnew
> System::Windows::Forms::Label());
> this->label2 = (gcnew
> System::Windows::Forms::Label());
> this->trackBar1 = (gcnew
> System::Windows::Forms::TrackBar());
>
> (cli::safe_cast<System::ComponentModel::ISupportInitialize^
>>(this->pictureBox1))->BeginInit();
>
> (cli::safe_cast<System::ComponentModel::ISupportInitialize^
>>(this->trackBar1))->BeginInit();
> this->SuspendLayout();
> //
> // pictureBox1
> //
> this->pictureBox1->Image =
> (cli::safe_cast<System::Drawing::Image^
>>(resources->GetObject(L"pictureBox1.Image")));
> this->pictureBox1->Location =
> System::Drawing::Point(36, 26);
> this->pictureBox1->Name = L"pictureBox1";
> this->pictureBox1->Size =
> System::Drawing::Size(218, 129);
> this->pictureBox1->TabIndex = 0;
> this->pictureBox1->TabStop = false;
> //
> // button1
> //
> this->button1->Location =
> System::Drawing::Point(105, 231);
> this->button1->Name = L"button1";
> this->button1->Size =
> System::Drawing::Size(75, 23);
> this->button1->TabIndex = 1;
> this->button1->Text = L"button1";
> //
> // label1
> //
> this->label1->AutoSize = true;
> this->label1->Location =
> System::Drawing::Point(23, 190);
> this->label1->Name = L"label1";
> this->label1->Size = System::Drawing::Size(31,
> 13);
> this->label1->TabIndex = 2;
> this->label1->Text = L"label1";
> //
> // label2
> //
> this->label2->AutoSize = true;
> this->label2->Location =
> System::Drawing::Point(222, 190);
> this->label2->Name = L"label2";
> this->label2->Size = System::Drawing::Size(31,
> 13);
> this->label2->TabIndex = 3;
> this->label2->Text = L"label2";
> //
> // trackBar1
> //
> this->trackBar1->Location =
> System::Drawing::Point(87, 180);
> this->trackBar1->Name = L"trackBar1";
> this->trackBar1->Size =
> System::Drawing::Size(104, 45);
> this->trackBar1->TabIndex = 4;
> this->trackBar1->Scroll += gcnew
> System::EventHandler(this, &Form1::Form1_Load);
> //
> // Form1
> //
> this->AutoScaleDimensions =
> System::Drawing::SizeF(6, 13);
> this->AutoScaleMode =
> System::Windows::Forms::AutoScaleMode::Font;
> this->ClientSize = System::Drawing::Size(292,
> 266);
> this->Controls->Add(this->trackBar1);
> this->Controls->Add(this->label2);
> this->Controls->Add(this->label1);
> this->Controls->Add(this->button1);
> this->Controls->Add(this->pictureBox1);
> this->Name = L"Form1";
> this->Text = L"Form1";
> this->Load += gcnew System::EventHandler(this,
> &Form1::Form1_Load);
>
> (cli::safe_cast<System::ComponentModel::ISupportInitialize^
>>(this->pictureBox1))->EndInit();
>
> (cli::safe_cast<System::ComponentModel::ISupportInitialize^
>>(this->trackBar1))->EndInit();
> this->ResumeLayout(false);
> this->PerformLayout();
>
> }
> #pragma endregion
> private: System::Void Form1_Load(System::Object^ sender,
> System::EventArgs^ e) {
> }
> };
> }
>
>
>
.
- Prev by Date: Re: VC6->VC7 Warning C4005 with Warning lvl=3
- Next by Date: Re: declare & initialize array?
- Previous by thread: Static MFC in DLL (linker error)
- Next by thread: Re: declare & initialize array?
- Index(es):