004
17.12.2005, 19:59 Uhr
Uwe
C/C++ Master (Administrator)
|
Hallo, falls noch Bedarf ist:
Header:
C++: |
//---------------------------------------------------------------------------
#ifndef frmMainH #define frmMainH //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> #include <Menus.hpp> #include <OleCtnrs.hpp> #include <Tabs.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // Von der IDE verwaltete Komponenten TMainMenu *mnuMain; TMenuItem *mnuFile; TMenuItem *mnuNew; TMenuItem *mnuDel; TTabSet *TabSet; void __fastcall mnuNewClick(TObject *Sender); void __fastcall TabSetChange(TObject *Sender, int NewTab, bool &AllowChange); void __fastcall FormDestroy(TObject *Sender); void __fastcall mnuDelClick(TObject *Sender); private: bool bCall; TList* OleCollection; TOleContainer* CreateOleContainer(); TOleContainer* VisibleContainer; void AddOleContainer(TOleContainer*); void ShowContainer(int idx); // Anwender-Deklarationen public: // Anwender-Deklarationen __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif
|
Implementierung:
C++: |
//---------------------------------------------------------------------------
#include <vcl.h> #pragma hdrstop
#include "frmMain.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { OleCollection = new TList(); } //--------------------------------------------------------------------------- void __fastcall TForm1::mnuNewClick(TObject *Sender) { TOleContainer* pNewContainer = CreateOleContainer(); if(pNewContainer->InsertObjectDialog()) { AddOleContainer(pNewContainer); // Edit - wird durch AddOleContainer() aufgerufen // ShowContainer(TabSet->Tabs->Count-1); }else { delete pNewContainer; } } //---------------------------------------------------------------------------
TOleContainer* TForm1::CreateOleContainer() { TOleContainer* pCont = new TOleContainer(this); pCont->Parent = this; pCont->Visible = true; pCont->Align = alClient; return pCont; }
void TForm1::AddOleContainer(TOleContainer* c) { OleCollection->Add(c); TabSet->TabIndex = TabSet->Tabs->Count-1; TabSet->Tabs->Add("Objekt "+IntToStr(TabSet->Tabs->Count)+ " - " + c->OleClassName); ShowContainer(TabSet->Tabs->Count-1); }
void TForm1::ShowContainer(int idx) { if (!bCall){ bCall = true; // sonst wird eine Rekursion durch TabSet->TabIndex ausgeloest!!! try { if(!VisibleContainer==NULL) VisibleContainer->Visible=false; if((idx>=0)&&(OleCollection->Count > idx)) { VisibleContainer = reinterpret_cast<TOleContainer*>(OleCollection->Items[idx]); VisibleContainer->Visible=True; ActiveControl=VisibleContainer; TabSet->TabIndex=idx; }else{ VisibleContainer=NULL; TabSet->TabIndex=-1; } } // Edit /*catch (Exception &ex){ ShowMessage(ex.Message); }*/ __finally{ bCall = false; } } } void __fastcall TForm1::TabSetChange(TObject *Sender, int NewTab, bool &AllowChange) { ShowContainer(NewTab); // Edit // bCall = false; } //---------------------------------------------------------------------------
void __fastcall TForm1::FormDestroy(TObject *Sender) { delete OleCollection; } //---------------------------------------------------------------------------
|
Verbesserungswürdig, aber funzt... -- "Es ist schwierig, ein Programm wirklich idiotensicher zu machen, weil Idioten so genial sind."
Bis dann... Uwe Dieser Post wurde am 18.12.2005 um 17:14 Uhr von Uwe editiert. |