Zugriff auf Object Array



  • Ein Funktionsaufruf liefert mir eine Eigenschaft vom Typ Object
    Der Inhalt des Objectes ist ein Array. Wie kann ich auf die einzelnen Elemente
    des Array's zugreifen?
    In C# sieht die Sachse so aus:
    if (item.Value is Array)
    {
    System.String sText = "";
    // converte itemvalue object to an array
    System.Array theValues = (System.Array)item.Value;
    // look for each object in the array of items to get the single values
    foreach (System.Object o in theValues)
    {
    // build the result string for the textbox
    sText += (Convert.ToDouble(o)).ToString() + " | ";
    }
    // set value to the output textbox
    txtRefreshData.Text = sText;
    }
    ------------------------------------------------
    Meine Versuche in C++/CLI sehen so aus:
    data->Read(item);
    Type ^t = item->Value->GetType();
    System::Windows::Forms::MessageBox::Show(t->Name,
    "Type von Item- Value",MessageBoxButtons::OKCancel);
    //Hier wird "Object[]" angezeigt
    if (t->Name = "Object[]")
    {
    array<Object^> ^values =(array<Object^>) item->Value;
    //Hier kommt Compilerfehler
    .\dll.cpp(132) : error C3149: 'cli::array<Type>' : cannot use this type //here without a top-level '^'
    //1> with
    1> [
    1> Type=System::Object ^
    1> ]
    1>
    array<Object^> ^values =static_cast<array<Object^>>(item->Value);
    //Das funktioniert auch nicht, gleicher Comilerfeher
    }

    Wie bekomme ich Zugriff auf die einzelnen Objecte von item->Value?



  • Steht ja:
    error C3149: 'cli::array<Type>' : cannot use this type //here without a top-level '^'

    Du musst ^ benutzen bei der Dekl. des Arrays!



  • Habe ich doch.

    array<Object^> ^values =(array<Object^>) item->Value;
    |
    hier



  • mozarella schrieb:

    Habe ich doch.

    array<Object^> ^values 😞array<Object^>) item->Value;
    |
    hier

    BTW: benutze für Code bitte die entsprechenden Tags ([ cli][ /cli] ohne Leerschläge)


Anmelden zum Antworten