fehler beim erstellen vom panel



  • hi!

    ich erstelle mehrere panels und in diese wiederum panels

    TPanel*Gruppe[32];
    
    void funk_1();
    {
    Gruppe[ID] = new TPanel(Form7);
    Gruppe[ID]->Parent = Form7;
    }
    
    void funk_2();
    {
    TPanel*Bon[32];
    Bon[ID] = new TPanel(Form7->Gruppe[ID]);
    Bon[ID]->Parent = Form7->Gruppe[ID];
    }
    
    void main()
    {
    funk_1();
    funk_2();
    }
    

    wenn ich das programm starten will, bekomm ich immer die fehlermeldung,
    dass Gruppe kein Element von Form7 ist. aber wieso? und wie könnte ich das ändern?

    vielen dank



  • Hallo

    Da Gruppe[32] offenbar eine globale Variable und keine Membervariable von Form7 ist, darfst (und brauchst) du Gruppe7 in funk2_2 nicht über Form7 ansprechen.

    Außerdem :
    - Globale Variable sind meistens schlecht. Verwende in deinem Fall lieber Membervariablen. Siehe die üblichen Tutorials zum Thema OOP
    - Verwende aussagekräftige Variablen- und Funktionsnamen. funk_x und Formx sind wirklich schlechte Namen

    bis bald
    akari



  • danke für die antwort, aber ich bekomme das trotzdem nicht hin. der obere code ist nur ein beispiel gewesen. ich poste den ganzen

    Header:

    int CallbackPlan( void *Pointer, int argc, char **argv, char **columnNames);
    int CallbackGruppeCount( void *Pointer, int argc, char **argv, char **columnNames);
    int CallbackGruppe( void *Pointer, int argc, char **argv, char **columnNames);
    int CallbackBon( void *Pointer, int argc, char **argv, char **columnNames);
    
    class TForm7 : public TForm
    {
    __published:	// Von der IDE verwaltete Komponenten
    	TButton *Button1;
    	TListBox *ListBox1;
    	TListBox *ListBox2;
    	TPanel *Panel1;
    	TPanel *Panel2;
    	TImage *Image2;
    	TPanel *Panel3;
    	TLabel *Label2;
    	TLabel *Label3;
    	TLabel *Label4;
    	TPanel *Panel4;
    	TPanel *Panel5;
    	TPanel *Panel6;
    	TPanel *Panel7;
    	TPanel *Panel9;
    	TPanel *PanelKey;
    	TPanel *Panel11;
    	TLabel *Label1;
    	TEdit *Edit1;
    	//TPanel *Gruppe;
    
    	int __fastcall LoadPlan(int x);
    	int __fastcall CountGruppe(int x);
    	int __fastcall LoadGruppe(int x);
    	int __fastcall LoadBon(int x);
    	void __fastcall MakeKey();
    
    	//void __fastcall TischOnClick(TObject *Sender);
    	void __fastcall TischOnMouseDown(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y);
    	void __fastcall TischOnMouseUp(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y);
    
    	void __fastcall GruppeOnMouseDown(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y);
    	void __fastcall GruppeOnMouseUp(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y);
    
    	void __fastcall BonOnMouseDown(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y);
    	void __fastcall BonOnMouseUp(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y);
    
    	void __fastcall Button1Click(TObject *Sender);
    	void __fastcall Image2MouseUp(TObject *Sender, TMouseButton Button,
              TShiftState Shift, int X, int Y);
    	void __fastcall Image2MouseDown(TObject *Sender, TMouseButton Button,
    		  TShiftState Shift, int X, int Y);
    	void __fastcall Image2MouseMove(TObject *Sender, TShiftState Shift, int X,
              int Y);
    private:	// Benutzer-Deklarationen
    public:		// Benutzer-Deklarationen
    	__fastcall TForm7(TComponent* Owner);
    
    };
    //---------------------------------------------------------------------------
    extern PACKAGE TForm7 *Form7;
    

    C++:

    const int TischLimit = 128;
    const int ArtLimit = 512;
    const int BonUnterLimit = 32;
    const int BonLimit = 256;
    const char *PlanBild = "e:\\mars30\\plan.bmp";
    const char *PlanDatei = "e:\\mars30\\plan.txt";
    const char *BonDatei = "e:\\mars30\\bon.txt";
    const char *ArtDatei = "e:\\mars30\\artikel.txt";
    const char *GruppenDatei = "e:\\mars30\\gruppen.txt";
    
    const char *cStamm = "e:\\mars30\\Stamm.s3db";
    
    const int iFarbe[56][3] = {{255,255,255},{220,220,220},{190,190,190},{160,160,160},{130,130,130},{110,110,110},{80,80,80},{0,0,0},
    						  {255,0,0},{220,0,0},{200,0,0},{180,0,0},{160,0,0},{140,0,0},{120,0,0},{100,0,0},
    						  {0,255,0},{0,220,0},{0,200,0},{0,180,0},{0,160,0},{0,140,0},{0,120,0},{0,100,0},
    						  {0,0,255},{0,0,220},{0,0,200},{0,0,180},{0,0,160},{0,0,140},{0,0,120},{0,0,100},
    						  {0,255,255},{0,220,220},{0,200,200},{0,180,180},{0,160,160},{0,140,140},{0,120,120},{0,100,100},
    						  {255,0,255},{220,0,220},{200,0,200},{180,0,180},{160,0,160},{140,0,140},{120,0,120},{100,0,100},
    						  {255,255,0},{220,220,0},{200,200,0},{180,180,0},{160,160,0},{140,140,0},{120,120,0},{100,100,0}};
    
    const int iGruppeBonA = 10;
    const int iGruppeBonL = 0;
    const int iGruppeBonT = 400;
    const int iGruppeBonW = 600;
    const int iGruppeBonH = 40;
    const int iGruppeL = 0;
    const int iGruppeT = 440;
    const int iGruppeW = 600;
    const int iGruppeH = 160;
    
    const int iMaxGruppe = 32;
    
    typedef struct sqlite_vm sqlite_vm;
    sqlite3 *db;
    sqlite_vm *dbcursor;
    char *dberr = 0;
    char *sql, *sqltail;
    
    int iLastGruppe = 1;
    int Index;
    int IndexGes;
    int IndexID[iMaxGruppe];
    
    int iArtID[ArtLimit];
    AnsiString sArtName[ArtLimit];
    int iArtArt[ArtLimit];
    float fArtKe[ArtLimit];
    float fArtVe[ArtLimit];
    float fArtEp[ArtLimit];
    float fArtVp[ArtLimit];
    
    int iBonID[BonLimit];
    AnsiString sBonName[BonLimit];
    int iBonArt[BonLimit];
    float fBonVp[BonLimit];
    
    int TFontSize = 20;
    bool bmouse = false;
    int imouseX, imouseY;
    int ipixposX[20], ipixposY[20];
    int r, g, b;
    
    TPanel*Gruppe[BonUnterLimit];
    
    //---------------------------------------------------------------------------
    int __fastcall TForm7::LoadPlan(int x)
    {
    	if(FileExists(PlanBild))
    	{
    		Image2->Picture->LoadFromFile(PlanBild);
    	}
    	else
    	{
    		//Image2->Canvas->TextExtent("test");
    		//ShowMessage("Datei existieret");
    	}
    	sql = "SELECT ID, Name, Farbe, Schrift, SchriftFarbe, PosL, PosT, PosW, PosH FROM Tische";
    	if(SQLITE_OK != sqlite3_exec(db, sql, CallbackPlan, NULL, &dberr))
    	{
    		free(dberr);
    	}
    }
    int CallbackPlan( void *Pointer, int argc, char **argv, char **columnNames)
    {
    	TForm7* Form = reinterpret_cast<TForm7*>(Pointer);
    	int ID=atoi(argv[0]);
    	TPanel*Tisch[10];
    	Tisch[ID] = new TPanel(Form7->Panel2);
    	Tisch[ID]->Parent = Form7->Panel2;
    	Tisch[ID]->Name = "T" + IntToStr(ID);
    	Tisch[ID]->Color = RGB(iFarbe[atoi(argv[2])][0],iFarbe[atoi(argv[2])][1],iFarbe[atoi(argv[2])][2]);
    	Tisch[ID]->Font->Color = RGB(iFarbe[atoi(argv[4])][0],iFarbe[atoi(argv[4])][1],iFarbe[atoi(argv[4])][2]);
    	Tisch[ID]->Left = atoi(argv[5]);
    	Tisch[ID]->Top = atoi(argv[6]);
    	Tisch[ID]->Width = atoi(argv[7]);
    	Tisch[ID]->Height = atoi(argv[8]);
    	Tisch[ID]->BevelInner = true;
    	Tisch[ID]->OnMouseDown = Form7->TischOnMouseDown;
    	Tisch[ID]->OnMouseUp = Form7->TischOnMouseUp;
    	Tisch[ID]->Font->Size = atoi(argv[3]);
    	Tisch[ID]->Caption = argv[1];
    	return 0;
    }
    //---------------------------------------------------------------------------
    int __fastcall TForm7::CountGruppe(int x)
    {
    	IndexGes = 1;
    	sql = "SELECT ID FROM Gruppe";
    	if(SQLITE_OK != sqlite3_exec(db, sql, CallbackGruppeCount, NULL, &dberr))
    	{
    		free(dberr);
    	}
    }
    int CallbackGruppeCount( void *Pointer, int argc, char **argv, char **columnNames)
    {
    	TForm7* Form = reinterpret_cast<TForm7*>(Pointer);
    	IndexID[IndexGes] = atoi(argv[0]);
    	Form7->ListBox1->Items->Add(argv[0]);
    	IndexGes++;
    	return 0;
    }
    //---------------------------------------------------------------------------
    int __fastcall TForm7::LoadGruppe(int x)
    {
    	Index = 1;
    	sql = "SELECT ID, Name, Farbe, Schrift, SchriftFarbe FROM Gruppe";
    	if(SQLITE_OK != sqlite3_exec(db, sql, CallbackGruppe, NULL, &dberr))
    	{
    		free(dberr);
    	}
    
    }
    int CallbackGruppe( void *Pointer, int argc, char **argv, char **columnNames)
    {
    	int test;
    	if (IndexGes>iGruppeBonA)
    	{
    		test=IndexGes - 1;
    	}
    	else
    	{
    		test=10;
    	}
    	int ID=atoi(argv[0]);
    	TForm7* Form = reinterpret_cast<TForm7*>(Pointer);
    	TPanel*GruppeBon[iMaxGruppe];
    	GruppeBon[ID] = new TPanel(Form7);
    	GruppeBon[ID]->Parent = Form7;
    	GruppeBon[ID]->Name = "GruppeBon" + IntToStr(ID);
    	GruppeBon[ID]->Color = RGB(iFarbe[atoi(argv[2])][0],iFarbe[atoi(argv[2])][1],iFarbe[atoi(argv[2])][2]);
    	GruppeBon[ID]->Font->Color = RGB(iFarbe[atoi(argv[4])][0],iFarbe[atoi(argv[4])][1],iFarbe[atoi(argv[4])][2]);
    	GruppeBon[IndexID[Index]]->Left = (iGruppeBonW/test) * (Index - 1);
    	GruppeBon[ID]->Top = iGruppeBonT;
    	GruppeBon[ID]->Width = iGruppeBonW/test;
    	GruppeBon[ID]->Height = iGruppeBonH;
    	GruppeBon[ID]->BevelInner = true;
    	GruppeBon[ID]->OnMouseDown = Form7->GruppeOnMouseDown;
    	GruppeBon[ID]->OnMouseUp = Form7->GruppeOnMouseUp;
    	GruppeBon[ID]->Font->Size = atoi(argv[3]);
    	GruppeBon[ID]->Caption = argv[1];
    
    	Gruppe[ID] = new TPanel(Form7);
    	Gruppe[ID]->Parent = Form7;
    	Gruppe[ID]->Name = "Gruppe" + IntToStr(ID);
    	Gruppe[ID]->Color = RGB(128,0,128);
    	Gruppe[ID]->Left = iGruppeL;
    	Gruppe[ID]->Top = iGruppeT;
    	Gruppe[ID]->Width = iGruppeW;
    	Gruppe[ID]->Height = iGruppeH;
    	Gruppe[ID]->Visible= False;
    	Index++;
    	return 0;
    
    }
    //---------------------------------------------------------------------------
    int __fastcall TForm7::LoadBon(int x)
    {
    	sql = "SELECT ID, Name, Farbe, Schrift, SchriftFarbe FROM Bon";
    	if(SQLITE_OK != sqlite3_exec(db, sql, CallbackBon, NULL, &dberr))
    	{
    		free(dberr);
    	}
    }
    int CallbackBon( void *Pointer, int argc, char **argv, char **columnNames)
    {
    	int ID=atoi(argv[0]);
    	TForm7* Form = reinterpret_cast<TForm7*>(Pointer);
    	TPanel*Bon[iMaxGruppe];
    	Bon[ID] = new TPanel(Form7->Gruppe[ID]);
    	Bon[ID]->Parent = Form7->Gruppe[ID];
    	Bon[ID]->Name = "Bon" + IntToStr(ID);
    	Bon[ID]->Color = RGB(iFarbe[atoi(argv[2])][0],iFarbe[atoi(argv[2])][1],iFarbe[atoi(argv[2])][2]);
    	Bon[ID]->Font->Color = RGB(iFarbe[atoi(argv[4])][0],iFarbe[atoi(argv[4])][1],iFarbe[atoi(argv[4])][2]);
    	Bon[IndexID[Index]]->Left = (iGruppeBonW/test) * (Index - 1);
    	Bon[ID]->Top = iGruppeBonT;
    	Bon[ID]->Width = iGruppeBonW/test;
    	Bon[ID]->Height = iGruppeBonH;
    	Bon[ID]->BevelInner = true;
    	Bon[ID]->OnMouseDown = Form7->GruppeOnMouseDown;
    	Bon[ID]->OnMouseUp = Form7->GruppeOnMouseUp;
    	Bon[ID]->Font->Size = atoi(argv[3]);
    	Bon[ID]->Caption = argv[1];
    
    	Index++;
    
    	return 0;
    }
    //---------------------------------------------------------------------------
    
    //---------------------------------------------------------------------------
    void __fastcall TForm7::MakeKey()
    {
    
    int i;
    
    }
    //---------------------------------------------------------------------------
    __fastcall TForm7::TForm7(TComponent* Owner)
    	: TForm(Owner)
    {
    	Panel1->DoubleBuffered=true;
    	Panel2->DoubleBuffered=true;
    	Panel1->Width = 600;
    	Panel1->Height = 400;
    	Image2->Width = 800;
    	Image2->Height = 600;
    	Panel2->Width = 800;
    	Panel2->Height = 600;
    
        if(!sqlite3_open(cStamm, &db))
    	{
    		LoadPlan(1);
    		CountGruppe(1);
    		LoadGruppe(1);
    		LoadBon(1);
    		sqlite3_close(db);
    	}
    	else
    	{
    		//ShowMessage("Hoppla: %sn", dberr);
    		free(dberr);
    	}
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm7::TischOnMouseDown(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y)
    {
      Button1->Caption = ((TButton*)Sender)->Caption;
      //Tisch((TButton*)Sender->)->
      //((TButton*)Sender)->Controls::TWinControl::FBevelInner=2;
      //::BevelOuter::bvLowered=true;
    
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm7::TischOnMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y)
    {
      Button1->Caption = "UP";//((TButton*)Sender)->Caption;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm7::GruppeOnMouseDown(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y)
    {
      Button1->Caption = ((TButton*)Sender)->Caption;
      //Tisch((TButton*)Sender->)->
      //((TButton*)Sender)->Controls::TWinControl::FBevelInner=2;
      //::BevelOuter::bvLowered=true;
    
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm7::GruppeOnMouseUp(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y)
    {
    	//ss_temp = ca_full_name;
    	//ss_extention = ss_temp.substr(ss_temp.find_last_of(".")+1);
    	//ss_file_name = ss_temp.substr(ss_temp.find_last_of("\\")+1);
    	//ss_file_name = ss_file_name.substr(0, ss_file_name.length() - ss_extention.length()-1);
    
    	//Panel2->Visible
    	std:String test;
    	//int alex;
    	test = ((TButton*)Sender)->Name;
    	test = test.SubString(10,test.Length()-9);
    	Button1->Caption =(test);
    	Gruppe[iLastGruppe]->Visible = False;
    	Gruppe[StrToInt(test)]->Visible = True;
    	iLastGruppe = StrToInt(test);
    
    	//Button1->Caption = ((TButton*)Sender)->Hint;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm7::BonOnMouseDown(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y)
    {
      Button1->Caption = ((TButton*)Sender)->Caption;
      //Tisch((TButton*)Sender->)->
      //((TButton*)Sender)->Controls::TWinControl::FBevelInner=2;
      //::BevelOuter::bvLowered=true;
    
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm7::BonOnMouseUp(TObject *Sender, TMouseButton Button,
          TShiftState Shift, int X, int Y)
    {
      Button1->Caption = "UP";//((TButton*)Sender)->Caption;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm7::Button1Click(TObject *Sender)
    {
       //ShowMessage("test");
       Label2->Canvas->Rectangle(10,10,20,20);
       //TRect R1 = Rect (100,100,104,200);
       //this->Canvas->Pen->Color = clGreen;
       //this->Canvas->LineTo(100,100);
    
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm7::Image2MouseUp(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y)
    {
    	bmouse = false;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm7::Image2MouseDown(TObject *Sender, TMouseButton Button,
    	  TShiftState Shift, int X, int Y)
    {
    	bmouse=true;
    	TPoint P = Mouse->CursorPos;
    	P = Panel1->ScreenToClient(P);
    	imouseX = P.x - Panel2->Left;
    	imouseY = P.y - Panel2->Top;
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm7::Image2MouseMove(TObject *Sender, TShiftState Shift,
    	  int X, int Y)
    {
    	if (bmouse==true)
    	{
        	TPoint P = Mouse->CursorPos;
    		P = Panel1->ScreenToClient(P);
    
    		if (Panel2->Left>=-200)
    		{
    			if (Panel2->Left<=0)
    			{
    				Panel2->Left=P.x-imouseX;
    			}
    			else
    			{
    				Panel2->Left=0;
    				imouseX = P.x;
    			}
    		}
    		else
    		{
    			Panel2->Left=-200;
    			imouseX = (P.x + 200);
    		}
    
    		if (Panel2->Top>=-200)
    		{
    			if (Panel2->Top<=0)
    			{
    				Panel2->Top=P.y-imouseY;
    			}
    			else
    			{
    				Panel2->Top=0;
    				imouseY = P.y;
    			}
    		}
    		else
    		{
    			Panel2->Top=-200;
    			imouseY = (P.y + 200);
    		}
    	}
    }
    //---------------------------------------------------------------------------
    

    wenn ich die CallBack funktionen öffentlich deklariere, dann bekomm ich eine fehlermeldung vom "sqlite.h". also wie kann ich auf die panels Gruppe zugreifen, wenn ich sie erst zur laufzeit erstelle?

    vielen dank...



  • Sorry Alex, dass ich jetzt mal ein wenig deinen Programmcode kritisieren muß, aber der ist "äußerst übelst"!

    Dir scheinen die Grundlagen der objektorientierten Programmierung noch völlig zu fehlen. Wie akari schon geschrieben hat, sind globale Variablen "böse" und deine Namensgebung auch!

    Desweiteren ist das Mixen von GUI- und Datenbank-Code auch sehr schlecht (besser: Aufteilen auf verschiedene Module).

    Da du anscheinend eine Datenbank mit einer reinen C-Schnittstelle verwendest (welche nur reine Funktionen als Callbacks entgegen nimmt), gibt es hierfür nur die Möglichkeit des "Pointer casten".

    Mittels des 3. Parameters beim sqlite3_exec kannst du einen beliebigen Zeiger übergeben, welcher dann in der Callback-Funktion dann als "Pointer" zur Verfügung steht.

    Jedoch rate ich dir, evtl. eine andere Datenbank zu benutzen, welche besser mit dem Borland-Builder zu verwenden ist (je nachdem welche Version du verwendest).

    Und strukturier dein Programm übersichtlicher!

    Zuletzt noch dein eigentlicher Fehler:
    du hast die TPanel-Arrays ja lokal in den Callback-Funktionen deklariert...


Anmelden zum Antworten