dynm. Label erstellen -> wo liegt der Fehler?



  • TForm1 *Form1;
    
    const int x = 8;
    const int y = 8;
    
    TLabel *flaeche[x][y];
    
    //---------------------------------------------------------------------------
    
    void __fastcall TForm1::FormCreate(TObject *Sender)
    {
    for(p=0; p<8; p++)
     {
      for(q=0; q<8; q++)
       {
        flaeche[p][q] = new TLabel(this);
    
        flaeche[p][q] = this; // Hier kommt der Fehler
    
        flaeche[p][q]->Width = 32;
        flaeche[p][q]->Height = 32;
        flaeche[p][q]->Top = p * 35;
        flaeche[p][q]->Left = q * 35;
        flaeche[p][q]->Visible = true;
       }
     }
    }
    //---------------------------------------------------------------------------
    

    Fehler:
    [C++ Fehler] Unit1.cpp(34): E2034 Konvertierung von 'TForm1 * const' nach 'TLabel *' nicht möglich

    Kann mir jemand weiterhelfen?

    Gruß,
    Johrtreel



  • warum setzt du das TLabel =

    this
    

    ?

    meinst du vieleicht

    flaeche[p][q]->Parent = this
    

    [ Dieser Beitrag wurde am 20.02.2003 um 18:59 Uhr von Xeno the Alien editiert. ]



  • Das Dynamische er stellen des Label ist in der FAQ mit einem Beispiel.



  • hallo,

    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    for(int p=0; p<8; p++)
    {
      for(int q=0; q<8; q++)
      {
        flaeche[p][q] = new TLabel(this);
        flaeche[p][q]->Parent = this; //Parent wichtig!!!
        //flaeche[p][q] = this; // Hier kommt der Fehler
    
        flaeche[p][q]->Width = 32;
        flaeche[p][q]->Height = 32;
        flaeche[p][q]->Top = p * 35;
        flaeche[p][q]->Left = q * 35;
        flaeche[p][q]->Caption = IntToStr(p) + IntToStr(q); //sonst ja leer= unsichtbar...
        flaeche[p][q]->Visible = true;
      }
    }
    }
    

    mfg
    murphy


Anmelden zum Antworten