"Clicked" in Form1, jetzt aller Code da drin - oder doch besser als .cpp?
-
Hallo!
Da ja z.B. die clicked-Ereignisse auf Form1 in der Datei Form1.h stehen, habe ich sämtlichen code in diesem header stehen.
Also auch die ganzen Funktionen.
Dagegen ist die Form1.cpp ziemlich leer, da habe ich ncihts reingeschrieben.
Ich dachte mir, dass das vielleicht dann so sein soll?!?Macht man das so, oder sollte ich das alles in die .cpp portieren?
Was ist da gängige Praxis?Gruß
-
Lass das mal da wo das ist, nämlich in der Header, dass ist schon richtig so und wird auch so gemacht.
-
Doug_HH schrieb:
Lass das mal da wo das ist, nämlich in der Header, dass ist schon richtig so und wird auch so gemacht.
Neeeeeee das kann man so nicht stehen lassen.
Trenne um himmelswillen Deklaration von Definition! Auch wenn es der Compiler für Dich nicht übernimmt. Du sparst Dir
a) Übersetzungszeit
b) Unnötige Abhängigkeiten
c) Möglichkeit zur Auflösung von Abhängigkeiten per DeklarationIn C++ gehören Definitionen und Deklarationen getrennt!!!
-
Was legst Du den von einem Klickereignis in die *cpp?
-
Die Deklaration wird im Header gelassen
System::Void seitenansichtToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e); System::Void GutschriftenDetail::vonMahnungToolStripMenuItem_DropDownOpening(System::Object^ sender, System::EventArgs^ e);
Die Definition kommt in die .cpp
/************************************************************************/ /* */ /************************************************************************/ System::Void GutschriftenDetail::seitenansichtToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) { ReportDruck::cl_ReportDruck::Printer->Type = "Gutschrift"; ReportDruck::cl_ReportDruck::Printer->Where = "RechnungsNummer = '" + Gutschriftnummer->Text + "'"; ReportDruck::cl_ReportDruck::Printer->PreviewOnly = true; ReportDruck::cl_ReportDruck::Printer->print(); } /************************************************************************/ /* */ /************************************************************************/ System::Void GutschriftenDetail::vonMahnungToolStripMenuItem_DropDownOpening(System::Object^ sender, System::EventArgs^ e) { fill_cbx(btn_cpy_von_geb_Mahnung->Items,"RechnungsNummer","GebuchteMahnung"); }
-
So habe ich mal eben gemach.
MouseEnter-Ereignis in die *.cpp verschoben.
Das ist das Ergebnis.1>------ Erstellen gestartet: Projekt: RAT, Konfiguration: Debug Win32 ------ 1>Kompilieren... 1>RATStart.cpp 1>c:\user software\hsl\rat\rat\RATStart.h(418) : error C2039: 'TextBoxSuchen_MouseEnter': Ist kein Element von 'RAT::RATStart' 1> c:\user software\hsl\rat\rat\RATStart.h(28): Siehe Deklaration von 'RAT::RATStart' 1>c:\user software\hsl\rat\rat\RATStart.h(418) : error C2065: 'TextBoxSuchen_MouseEnter': nichtdeklarierter Bezeichner 1>c:\user software\hsl\rat\rat\RATStart.h(418) : error C3350: "System::EventHandler": Ein Delegatkonstruktor erwartet 2 Argument(e). 1>.\RATStart.cpp(4) : error C2059: Syntaxfehler: 'private' 1>.\RATStart.cpp(5) : error C2365: "TextBoxSuchen_MouseEnter": Erneute Definition; vorherige Definition war "Ehemals unbekannter Bezeichner". 1>.\RATStart.cpp(6) : error C2065: 'toolStripComboBoxAuswahl': nichtdeklarierter Bezeichner 1>.\RATStart.cpp(6) : error C2227: Links von "->Text" muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden. 1> Typ ist ''unknown-type'' 1>.\RATStart.cpp(8) : error C2065: 'TextBoxSuchen': nichtdeklarierter Bezeichner 1>.\RATStart.cpp(8) : error C2227: Links von "->ToolTipText" muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden. 1> Typ ist ''unknown-type'' 1>.\RATStart.cpp(12) : error C2227: Links von "->ToolTipText" muss sich ein Zeiger auf Klassen-/Struktur-/Union-/generischen Typ befinden. 1> Typ ist ''unknown-type'' 1>RAT.cpp 1>c:\user software\hsl\rat\rat\RATStart.h(418) : error C2039: 'TextBoxSuchen_MouseEnter': Ist kein Element von 'RAT::RATStart' 1> c:\user software\hsl\rat\rat\RATStart.h(28): Siehe Deklaration von 'RAT::RATStart' 1>c:\user software\hsl\rat\rat\RATStart.h(418) : error C2065: 'TextBoxSuchen_MouseEnter': nichtdeklarierter Bezeichner 1>c:\user software\hsl\rat\rat\RATStart.h(418) : error C3350: "System::EventHandler": Ein Delegatkonstruktor erwartet 2 Argument(e). 1>Code wird generiert... 1>Das Buildprotokoll wurde unter "file://c:\user Software\HSL\RAT\RAT\Debug\BuildLog.htm" gespeichert. 1>RAT - 13 Fehler, 0 Warnung(en) ========== Erstellen: 0 erfolgreich, Fehler bei 1, 0 aktuell, 0 übersprungen ==========
Hätte meine Projekte auch gerne mal etwas sauberer.
Aber ich hab damit auch schon mal schlechte Erfahrung gemacht, vor allem wenn das Projekt schon etwas größer geworden ist.
Und in der Schule haben wir da auch nie was hin und hergeschoben, hab aber auch ehrlich gesagt nie danach gefragt.
Weil die uns mit andrem Zeug die Birne zugehauen haben.
Aber würde mich wirklich mal interessieren ob das Sinnvoll ist, weil das ja nun doch ein bisschen Arbeit ist.
-
Das es sinnvoll ist steht nicht mal zur Diskussion, glaub es einfach mal
Die Fehlermeldungen sagen ohne dazugehörenden Code nicht viel aus. Zeig mal Zeile 418
-
Das ist die Deklaration für das MouseEnter-Ereignis, das ich ja nun in die *.cpp geschoben habe.
this->TextBoxSuchen->MouseEnter += gcnew System::EventHandler(this, &RATStart::TextBoxSuchen_MouseEnter);
-
Na Deklarationen gehören in den Header!
TextBoxSuchen_MouseEnter wird im Header deklariert ? Wenn Du magst, schick mal das Projekt. Dann kann man sich die Zeilen die man zur ansicht benötigt zusammen suchen
-
Das ist die *.cpp
#include "StdAfx.h" #include "kundenEinzel.h"
Das die *.h
#pragma once #include "stdafx.h" using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms; using namespace System::Data; using namespace System::Drawing; namespace RAT { /// <summary> /// Zusammenfassung für kundenEinzel /// /// Warnung: Wenn Sie den Namen dieser Klasse ändern, müssen Sie auch /// die Ressourcendateiname-Eigenschaft für das Tool zur Kompilierung verwalteter Ressourcen ändern, /// das allen RESX-Dateien zugewiesen ist, von denen diese Klasse abhängt. /// Anderenfalls können die Designer nicht korrekt mit den lokalisierten Ressourcen /// arbeiten, die diesem Formular zugewiesen sind. /// </summary> public ref class kundenEinzel : public System::Windows::Forms::Form { public: kundenEinzel(void) { InitializeComponent(); // //TODO: Konstruktorcode hier hinzufügen. // } protected: /// <summary> /// Verwendete Ressourcen bereinigen. /// </summary> ~kundenEinzel() { if (components) { delete components; } } private: RAT::RAT1DataSet^ RAT1DataSet; protected: private: System::Windows::Forms::BindingSource^ KundenBindingSource; private: RAT::RAT1DataSetTableAdapters::KundenTableAdapter^ KundenTableAdapter; private: System::Windows::Forms::BindingNavigator^ KundenBindingNavigator; private: System::Windows::Forms::ToolStripButton^ bindingNavigatorAddNewItem; private: System::Windows::Forms::ToolStripLabel^ bindingNavigatorCountItem; private: System::Windows::Forms::ToolStripButton^ bindingNavigatorDeleteItem; private: System::Windows::Forms::ToolStripButton^ bindingNavigatorMoveFirstItem; private: System::Windows::Forms::ToolStripButton^ bindingNavigatorMovePreviousItem; private: System::Windows::Forms::ToolStripSeparator^ bindingNavigatorSeparator; private: System::Windows::Forms::ToolStripTextBox^ bindingNavigatorPositionItem; private: System::Windows::Forms::ToolStripSeparator^ bindingNavigatorSeparator1; private: System::Windows::Forms::ToolStripButton^ bindingNavigatorMoveNextItem; private: System::Windows::Forms::ToolStripButton^ bindingNavigatorMoveLastItem; private: System::Windows::Forms::ToolStripSeparator^ bindingNavigatorSeparator2; private: System::Windows::Forms::ToolStripButton^ KundenBindingNavigatorSaveItem; private: System::Windows::Forms::TextBox^ KundennummerTextBox; private: System::Windows::Forms::TextBox^ FirmaTextBox; private: System::Windows::Forms::TextBox^ AnsprechpartnerTextBox; private: System::Windows::Forms::TextBox^ StrasseTextBox; private: System::Windows::Forms::TextBox^ PostleitzahlTextBox; private: System::Windows::Forms::TextBox^ OrtTextBox; private: System::Windows::Forms::TextBox^ TelefonTextBox; private: System::Windows::Forms::TextBox^ TelefaxTextBox; private: System::Windows::Forms::TextBox^ E_MailTextBox; private: System::Windows::Forms::TextBox^ WebsiteTextBox; private: System::ComponentModel::IContainer^ components; private: /// <summary> /// Erforderliche Designervariable. /// </summary> #pragma region Windows Form Designer generated code /// <summary> /// Erforderliche Methode für die Designerunterstützung. /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden. /// </summary> void InitializeComponent(void) { this->components = (gcnew System::ComponentModel::Container()); System::Windows::Forms::Label^ KundennummerLabel; System::Windows::Forms::Label^ FirmaLabel; System::Windows::Forms::Label^ AnsprechpartnerLabel; System::Windows::Forms::Label^ StrasseLabel; System::Windows::Forms::Label^ PostleitzahlLabel; System::Windows::Forms::Label^ OrtLabel; System::Windows::Forms::Label^ TelefonLabel; System::Windows::Forms::Label^ TelefaxLabel; System::Windows::Forms::Label^ E_MailLabel; System::Windows::Forms::Label^ WebsiteLabel; System::ComponentModel::ComponentResourceManager^ resources = (gcnew System::ComponentModel::ComponentResourceManager(kundenEinzel::typeid)); this->RAT1DataSet = (gcnew RAT::RAT1DataSet()); this->KundenBindingSource = (gcnew System::Windows::Forms::BindingSource(this->components)); this->KundenTableAdapter = (gcnew RAT::RAT1DataSetTableAdapters::KundenTableAdapter()); this->KundenBindingNavigator = (gcnew System::Windows::Forms::BindingNavigator(this->components)); this->bindingNavigatorAddNewItem = (gcnew System::Windows::Forms::ToolStripButton()); this->bindingNavigatorCountItem = (gcnew System::Windows::Forms::ToolStripLabel()); this->bindingNavigatorDeleteItem = (gcnew System::Windows::Forms::ToolStripButton()); this->bindingNavigatorMoveFirstItem = (gcnew System::Windows::Forms::ToolStripButton()); this->bindingNavigatorMovePreviousItem = (gcnew System::Windows::Forms::ToolStripButton()); this->bindingNavigatorSeparator = (gcnew System::Windows::Forms::ToolStripSeparator()); this->bindingNavigatorPositionItem = (gcnew System::Windows::Forms::ToolStripTextBox()); this->bindingNavigatorSeparator1 = (gcnew System::Windows::Forms::ToolStripSeparator()); this->bindingNavigatorMoveNextItem = (gcnew System::Windows::Forms::ToolStripButton()); this->bindingNavigatorMoveLastItem = (gcnew System::Windows::Forms::ToolStripButton()); this->bindingNavigatorSeparator2 = (gcnew System::Windows::Forms::ToolStripSeparator()); this->KundenBindingNavigatorSaveItem = (gcnew System::Windows::Forms::ToolStripButton()); this->KundennummerTextBox = (gcnew System::Windows::Forms::TextBox()); this->FirmaTextBox = (gcnew System::Windows::Forms::TextBox()); this->AnsprechpartnerTextBox = (gcnew System::Windows::Forms::TextBox()); this->StrasseTextBox = (gcnew System::Windows::Forms::TextBox()); this->PostleitzahlTextBox = (gcnew System::Windows::Forms::TextBox()); this->OrtTextBox = (gcnew System::Windows::Forms::TextBox()); this->TelefonTextBox = (gcnew System::Windows::Forms::TextBox()); this->TelefaxTextBox = (gcnew System::Windows::Forms::TextBox()); this->E_MailTextBox = (gcnew System::Windows::Forms::TextBox()); this->WebsiteTextBox = (gcnew System::Windows::Forms::TextBox()); KundennummerLabel = (gcnew System::Windows::Forms::Label()); FirmaLabel = (gcnew System::Windows::Forms::Label()); AnsprechpartnerLabel = (gcnew System::Windows::Forms::Label()); StrasseLabel = (gcnew System::Windows::Forms::Label()); PostleitzahlLabel = (gcnew System::Windows::Forms::Label()); OrtLabel = (gcnew System::Windows::Forms::Label()); TelefonLabel = (gcnew System::Windows::Forms::Label()); TelefaxLabel = (gcnew System::Windows::Forms::Label()); E_MailLabel = (gcnew System::Windows::Forms::Label()); WebsiteLabel = (gcnew System::Windows::Forms::Label()); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->RAT1DataSet))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->KundenBindingSource))->BeginInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->KundenBindingNavigator))->BeginInit(); this->KundenBindingNavigator->SuspendLayout(); this->SuspendLayout(); // // KundennummerLabel // KundennummerLabel->AutoSize = true; KundennummerLabel->Location = System::Drawing::Point(20, 46); KundennummerLabel->Name = L"KundennummerLabel"; KundennummerLabel->Size = System::Drawing::Size(84, 13); KundennummerLabel->TabIndex = 1; KundennummerLabel->Text = L"Kundennummer:"; // // FirmaLabel // FirmaLabel->AutoSize = true; FirmaLabel->Location = System::Drawing::Point(20, 72); FirmaLabel->Name = L"FirmaLabel"; FirmaLabel->Size = System::Drawing::Size(35, 13); FirmaLabel->TabIndex = 3; FirmaLabel->Text = L"Firma:"; // // AnsprechpartnerLabel // AnsprechpartnerLabel->AutoSize = true; AnsprechpartnerLabel->Location = System::Drawing::Point(20, 98); AnsprechpartnerLabel->Name = L"AnsprechpartnerLabel"; AnsprechpartnerLabel->Size = System::Drawing::Size(88, 13); AnsprechpartnerLabel->TabIndex = 5; AnsprechpartnerLabel->Text = L"Ansprechpartner:"; // // StrasseLabel // StrasseLabel->AutoSize = true; StrasseLabel->Location = System::Drawing::Point(20, 124); StrasseLabel->Name = L"StrasseLabel"; StrasseLabel->Size = System::Drawing::Size(45, 13); StrasseLabel->TabIndex = 7; StrasseLabel->Text = L"Strasse:"; // // PostleitzahlLabel // PostleitzahlLabel->AutoSize = true; PostleitzahlLabel->Location = System::Drawing::Point(20, 150); PostleitzahlLabel->Name = L"PostleitzahlLabel"; PostleitzahlLabel->Size = System::Drawing::Size(63, 13); PostleitzahlLabel->TabIndex = 9; PostleitzahlLabel->Text = L"Postleitzahl:"; // // OrtLabel // OrtLabel->AutoSize = true; OrtLabel->Location = System::Drawing::Point(20, 176); OrtLabel->Name = L"OrtLabel"; OrtLabel->Size = System::Drawing::Size(24, 13); OrtLabel->TabIndex = 11; OrtLabel->Text = L"Ort:"; // // TelefonLabel // TelefonLabel->AutoSize = true; TelefonLabel->Location = System::Drawing::Point(20, 202); TelefonLabel->Name = L"TelefonLabel"; TelefonLabel->Size = System::Drawing::Size(46, 13); TelefonLabel->TabIndex = 13; TelefonLabel->Text = L"Telefon:"; // // TelefaxLabel // TelefaxLabel->AutoSize = true; TelefaxLabel->Location = System::Drawing::Point(20, 228); TelefaxLabel->Name = L"TelefaxLabel"; TelefaxLabel->Size = System::Drawing::Size(45, 13); TelefaxLabel->TabIndex = 15; TelefaxLabel->Text = L"Telefax:"; // // E_MailLabel // E_MailLabel->AutoSize = true; E_MailLabel->Location = System::Drawing::Point(20, 254); E_MailLabel->Name = L"E_MailLabel"; E_MailLabel->Size = System::Drawing::Size(39, 13); E_MailLabel->TabIndex = 17; E_MailLabel->Text = L"E-Mail:"; // // WebsiteLabel // WebsiteLabel->AutoSize = true; WebsiteLabel->Location = System::Drawing::Point(20, 280); WebsiteLabel->Name = L"WebsiteLabel"; WebsiteLabel->Size = System::Drawing::Size(49, 13); WebsiteLabel->TabIndex = 19; WebsiteLabel->Text = L"Website:"; // // RATDataSet // this->RAT1DataSet->DataSetName = L"RATDataSet"; this->RAT1DataSet->SchemaSerializationMode = System::Data::SchemaSerializationMode::IncludeSchema; // // KundenBindingSource // this->KundenBindingSource->DataMember = L"Kunden"; this->KundenBindingSource->DataSource = this->RAT1DataSet; // // KundenTableAdapter // this->KundenTableAdapter->ClearBeforeFill = true; // // KundenBindingNavigator // this->KundenBindingNavigator->AddNewItem = this->bindingNavigatorAddNewItem; this->KundenBindingNavigator->BindingSource = this->KundenBindingSource; this->KundenBindingNavigator->CountItem = this->bindingNavigatorCountItem; this->KundenBindingNavigator->DeleteItem = this->bindingNavigatorDeleteItem; this->KundenBindingNavigator->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^ >(12) {this->bindingNavigatorMoveFirstItem, this->bindingNavigatorMovePreviousItem, this->bindingNavigatorSeparator, this->bindingNavigatorPositionItem, this->bindingNavigatorCountItem, this->bindingNavigatorSeparator1, this->bindingNavigatorMoveNextItem, this->bindingNavigatorMoveLastItem, this->bindingNavigatorSeparator2, this->bindingNavigatorAddNewItem, this->bindingNavigatorDeleteItem, this->KundenBindingNavigatorSaveItem}); this->KundenBindingNavigator->Location = System::Drawing::Point(0, 0); this->KundenBindingNavigator->MoveFirstItem = this->bindingNavigatorMoveFirstItem; this->KundenBindingNavigator->MoveLastItem = this->bindingNavigatorMoveLastItem; this->KundenBindingNavigator->MoveNextItem = this->bindingNavigatorMoveNextItem; this->KundenBindingNavigator->MovePreviousItem = this->bindingNavigatorMovePreviousItem; this->KundenBindingNavigator->Name = L"KundenBindingNavigator"; this->KundenBindingNavigator->PositionItem = this->bindingNavigatorPositionItem; this->KundenBindingNavigator->Size = System::Drawing::Size(467, 25); this->KundenBindingNavigator->TabIndex = 0; this->KundenBindingNavigator->Text = L"bindingNavigator1"; // // bindingNavigatorAddNewItem // this->bindingNavigatorAddNewItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image; this->bindingNavigatorAddNewItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"bindingNavigatorAddNewItem.Image"))); this->bindingNavigatorAddNewItem->Name = L"bindingNavigatorAddNewItem"; this->bindingNavigatorAddNewItem->RightToLeftAutoMirrorImage = true; this->bindingNavigatorAddNewItem->Size = System::Drawing::Size(23, 22); this->bindingNavigatorAddNewItem->Text = L"Neu hinzufügen"; // // bindingNavigatorCountItem // this->bindingNavigatorCountItem->Name = L"bindingNavigatorCountItem"; this->bindingNavigatorCountItem->Size = System::Drawing::Size(44, 22); this->bindingNavigatorCountItem->Text = L"von {0}"; this->bindingNavigatorCountItem->ToolTipText = L"Die Gesamtanzahl der Elemente."; // // bindingNavigatorDeleteItem // this->bindingNavigatorDeleteItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image; this->bindingNavigatorDeleteItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"bindingNavigatorDeleteItem.Image"))); this->bindingNavigatorDeleteItem->Name = L"bindingNavigatorDeleteItem"; this->bindingNavigatorDeleteItem->RightToLeftAutoMirrorImage = true; this->bindingNavigatorDeleteItem->Size = System::Drawing::Size(23, 22); this->bindingNavigatorDeleteItem->Text = L"Löschen"; // // bindingNavigatorMoveFirstItem // this->bindingNavigatorMoveFirstItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image; this->bindingNavigatorMoveFirstItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"bindingNavigatorMoveFirstItem.Image"))); this->bindingNavigatorMoveFirstItem->Name = L"bindingNavigatorMoveFirstItem"; this->bindingNavigatorMoveFirstItem->RightToLeftAutoMirrorImage = true; this->bindingNavigatorMoveFirstItem->Size = System::Drawing::Size(23, 22); this->bindingNavigatorMoveFirstItem->Text = L"Erste verschieben"; // // bindingNavigatorMovePreviousItem // this->bindingNavigatorMovePreviousItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image; this->bindingNavigatorMovePreviousItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"bindingNavigatorMovePreviousItem.Image"))); this->bindingNavigatorMovePreviousItem->Name = L"bindingNavigatorMovePreviousItem"; this->bindingNavigatorMovePreviousItem->RightToLeftAutoMirrorImage = true; this->bindingNavigatorMovePreviousItem->Size = System::Drawing::Size(23, 22); this->bindingNavigatorMovePreviousItem->Text = L"Vorherige verschieben"; // // bindingNavigatorSeparator // this->bindingNavigatorSeparator->Name = L"bindingNavigatorSeparator"; this->bindingNavigatorSeparator->Size = System::Drawing::Size(6, 25); // // bindingNavigatorPositionItem // this->bindingNavigatorPositionItem->AccessibleName = L"Position"; this->bindingNavigatorPositionItem->AutoSize = false; this->bindingNavigatorPositionItem->Name = L"bindingNavigatorPositionItem"; this->bindingNavigatorPositionItem->Size = System::Drawing::Size(50, 23); this->bindingNavigatorPositionItem->Text = L"0"; this->bindingNavigatorPositionItem->ToolTipText = L"Aktuelle Position"; // // bindingNavigatorSeparator1 // this->bindingNavigatorSeparator1->Name = L"bindingNavigatorSeparator1"; this->bindingNavigatorSeparator1->Size = System::Drawing::Size(6, 25); // // bindingNavigatorMoveNextItem // this->bindingNavigatorMoveNextItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image; this->bindingNavigatorMoveNextItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"bindingNavigatorMoveNextItem.Image"))); this->bindingNavigatorMoveNextItem->Name = L"bindingNavigatorMoveNextItem"; this->bindingNavigatorMoveNextItem->RightToLeftAutoMirrorImage = true; this->bindingNavigatorMoveNextItem->Size = System::Drawing::Size(23, 22); this->bindingNavigatorMoveNextItem->Text = L"Nächste verschieben"; // // bindingNavigatorMoveLastItem // this->bindingNavigatorMoveLastItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image; this->bindingNavigatorMoveLastItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"bindingNavigatorMoveLastItem.Image"))); this->bindingNavigatorMoveLastItem->Name = L"bindingNavigatorMoveLastItem"; this->bindingNavigatorMoveLastItem->RightToLeftAutoMirrorImage = true; this->bindingNavigatorMoveLastItem->Size = System::Drawing::Size(23, 22); this->bindingNavigatorMoveLastItem->Text = L"Letzte verschieben"; // // bindingNavigatorSeparator2 // this->bindingNavigatorSeparator2->Name = L"bindingNavigatorSeparator2"; this->bindingNavigatorSeparator2->Size = System::Drawing::Size(6, 25); // // KundenBindingNavigatorSaveItem // this->KundenBindingNavigatorSaveItem->DisplayStyle = System::Windows::Forms::ToolStripItemDisplayStyle::Image; this->KundenBindingNavigatorSaveItem->Image = (cli::safe_cast<System::Drawing::Image^ >(resources->GetObject(L"KundenBindingNavigatorSaveItem.Image"))); this->KundenBindingNavigatorSaveItem->Name = L"KundenBindingNavigatorSaveItem"; this->KundenBindingNavigatorSaveItem->Size = System::Drawing::Size(23, 22); this->KundenBindingNavigatorSaveItem->Text = L"Daten speichern"; this->KundenBindingNavigatorSaveItem->Click += gcnew System::EventHandler(this, &kundenEinzel::KundenBindingNavigatorSaveItem_Click); // // KundennummerTextBox // this->KundennummerTextBox->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->KundenBindingSource, L"Kundennummer", true))); this->KundennummerTextBox->Location = System::Drawing::Point(114, 43); this->KundennummerTextBox->Name = L"KundennummerTextBox"; this->KundennummerTextBox->Size = System::Drawing::Size(100, 20); this->KundennummerTextBox->TabIndex = 2; // // FirmaTextBox // this->FirmaTextBox->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->KundenBindingSource, L"Firma", true))); this->FirmaTextBox->Location = System::Drawing::Point(114, 69); this->FirmaTextBox->Name = L"FirmaTextBox"; this->FirmaTextBox->Size = System::Drawing::Size(100, 20); this->FirmaTextBox->TabIndex = 4; // // AnsprechpartnerTextBox // this->AnsprechpartnerTextBox->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->KundenBindingSource, L"Ansprechpartner", true))); this->AnsprechpartnerTextBox->Location = System::Drawing::Point(114, 95); this->AnsprechpartnerTextBox->Name = L"AnsprechpartnerTextBox"; this->AnsprechpartnerTextBox->Size = System::Drawing::Size(100, 20); this->AnsprechpartnerTextBox->TabIndex = 6; // // StrasseTextBox // this->StrasseTextBox->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->KundenBindingSource, L"Strasse", true))); this->StrasseTextBox->Location = System::Drawing::Point(114, 121); this->StrasseTextBox->Name = L"StrasseTextBox"; this->StrasseTextBox->Size = System::Drawing::Size(100, 20); this->StrasseTextBox->TabIndex = 8; // // PostleitzahlTextBox // this->PostleitzahlTextBox->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->KundenBindingSource, L"Postleitzahl", true))); this->PostleitzahlTextBox->Location = System::Drawing::Point(114, 147); this->PostleitzahlTextBox->Name = L"PostleitzahlTextBox"; this->PostleitzahlTextBox->Size = System::Drawing::Size(100, 20); this->PostleitzahlTextBox->TabIndex = 10; // // OrtTextBox // this->OrtTextBox->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->KundenBindingSource, L"Ort", true))); this->OrtTextBox->Location = System::Drawing::Point(114, 173); this->OrtTextBox->Name = L"OrtTextBox"; this->OrtTextBox->Size = System::Drawing::Size(100, 20); this->OrtTextBox->TabIndex = 12; // // TelefonTextBox // this->TelefonTextBox->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->KundenBindingSource, L"Telefon", true))); this->TelefonTextBox->Location = System::Drawing::Point(114, 199); this->TelefonTextBox->Name = L"TelefonTextBox"; this->TelefonTextBox->Size = System::Drawing::Size(100, 20); this->TelefonTextBox->TabIndex = 14; // // TelefaxTextBox // this->TelefaxTextBox->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->KundenBindingSource, L"Telefax", true))); this->TelefaxTextBox->Location = System::Drawing::Point(114, 225); this->TelefaxTextBox->Name = L"TelefaxTextBox"; this->TelefaxTextBox->Size = System::Drawing::Size(100, 20); this->TelefaxTextBox->TabIndex = 16; // // E_MailTextBox // this->E_MailTextBox->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->KundenBindingSource, L"E-Mail", true))); this->E_MailTextBox->Location = System::Drawing::Point(114, 251); this->E_MailTextBox->Name = L"E_MailTextBox"; this->E_MailTextBox->Size = System::Drawing::Size(100, 20); this->E_MailTextBox->TabIndex = 18; // // WebsiteTextBox // this->WebsiteTextBox->DataBindings->Add((gcnew System::Windows::Forms::Binding(L"Text", this->KundenBindingSource, L"Website", true))); this->WebsiteTextBox->Location = System::Drawing::Point(114, 277); this->WebsiteTextBox->Name = L"WebsiteTextBox"; this->WebsiteTextBox->Size = System::Drawing::Size(100, 20); this->WebsiteTextBox->TabIndex = 20; // // kundenEinzel // this->AutoScaleDimensions = System::Drawing::SizeF(6, 13); this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font; this->ClientSize = System::Drawing::Size(467, 319); this->Controls->Add(KundennummerLabel); this->Controls->Add(this->KundennummerTextBox); this->Controls->Add(FirmaLabel); this->Controls->Add(this->FirmaTextBox); this->Controls->Add(AnsprechpartnerLabel); this->Controls->Add(this->AnsprechpartnerTextBox); this->Controls->Add(StrasseLabel); this->Controls->Add(this->StrasseTextBox); this->Controls->Add(PostleitzahlLabel); this->Controls->Add(this->PostleitzahlTextBox); this->Controls->Add(OrtLabel); this->Controls->Add(this->OrtTextBox); this->Controls->Add(TelefonLabel); this->Controls->Add(this->TelefonTextBox); this->Controls->Add(TelefaxLabel); this->Controls->Add(this->TelefaxTextBox); this->Controls->Add(E_MailLabel); this->Controls->Add(this->E_MailTextBox); this->Controls->Add(WebsiteLabel); this->Controls->Add(this->WebsiteTextBox); this->Controls->Add(this->KundenBindingNavigator); this->Name = L"kundenEinzel"; this->Text = L"kundenEinzel"; this->Load += gcnew System::EventHandler(this, &kundenEinzel::kundenEinzel_Load); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->RAT1DataSet))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->KundenBindingSource))->EndInit(); (cli::safe_cast<System::ComponentModel::ISupportInitialize^ >(this->KundenBindingNavigator))->EndInit(); this->KundenBindingNavigator->ResumeLayout(false); this->KundenBindingNavigator->PerformLayout(); this->ResumeLayout(false); this->PerformLayout(); } #pragma endregion private: System::Void KundenBindingNavigatorSaveItem_Click(System::Object^ sender, System::EventArgs^ e) { this->Validate(); this->KundenBindingSource->EndEdit(); this->KundenTableAdapter->Update(this->RAT1DataSet->Kunden); } private: System::Void kundenEinzel_Load(System::Object^ sender, System::EventArgs^ e) { // TODO: Diese Codezeile lädt Daten in die Tabelle "RATDataSet.Kunden". Sie können sie bei Bedarf verschieben oder entfernen. try { //this->KundenTableAdapter->Connection->ConnectionString = L"Data Source=.\\SQLEXPRESS;AttachDbFilename=" + RATStart::datenBankName + ";Integrated Security=True;Connect Timeout=30;User Instance=True"; this->KundenTableAdapter->Fill(this->RAT1DataSet->Kunden); } catch(Exception^ ex) { MessageBox::Show(ex->Message,MessageTitel + " Fehler in " +ex->Source,MessageBoxButtons::OK,MessageBoxIcon::Exclamation); //MessageBox::Show("Bitte suchen Sie erst die Datenbank \" RAT1.mdf \" auf Ihrem System.","Fehler...",MessageBoxButtons::OK,MessageBoxIcon::Error); } } }; }
Ferner brauch ich nochmal ein Gute Lösung für eine Globale String^ Konstante.
Wollte die MessageBox-Caption durch die Globale Konstante ersetzen.
Da ja in so einem Programm, doch viele MessageBoxen zusammen kommen.
Habe es jetzt mit #define gelöst, gefällt mir aber nicht.
Hast Du da einen Vorschlag?
Vermisse die Globale Vereinbarung wir bei der MFC in VC++ 6.0.
Gibt es die noch, wenn ja, auch in der WindowsForms?
-
cpp
private: System::Void KundenBindingNavigatorSaveItem_Click(System::Object^ sender, System::EventArgs^ e) { this->Validate(); this->KundenBindingSource->EndEdit(); this->KundenTableAdapter->Update(this->RAT1DataSet->Kunden); } private: System::Void kundenEinzel_Load(System::Object^ sender, System::EventArgs^ e) { // TODO: Diese Codezeile lädt Daten in die Tabelle "RATDataSet.Kunden". Sie können sie bei Bedarf verschieben oder entfernen. try { //this->KundenTableAdapter->Connection->ConnectionString = L"Data Source=.\\SQLEXPRESS;AttachDbFilename=" + RATStart::datenBankName + ";Integrated Security=True;Connect Timeout=30;User Instance=True"; this->KundenTableAdapter->Fill(this->RAT1DataSet->Kunden); } catch(Exception^ ex) { MessageBox::Show(ex->Message,MessageTitel + " Fehler in " +ex->Source,MessageBoxButtons::OK,MessageBoxIcon::Exclamation); //MessageBox::Show("Bitte suchen Sie erst die Datenbank \" RAT1.mdf \" auf Ihrem System.","Fehler...",MessageBoxButtons::OK,MessageBoxIcon::Error); } }
Header
private: System::Void KundenBindingNavigatorSaveItem_Click(System::Object^ sender, System::EventArgs^ e); private: System::Void kundenEinzel_Load(System::Object^ sender, System::EventArgs^ e);
Du kannst eine Statische Klasse anlegen mit einem statischen Member. Diesen kannst Du dann setzen.
Es wäre dann aber eleganter eine Statische Klasse zu schreiben, die eine Statische Messagebox irgendwas Methode hat und Dir das setzen des Titels gleich ganz erspart.
-
Danke, werde ich ausprobieren mit der Klasse.
Versuche mich eine bisschen, wenn es auch nicht leicht fällt an die Regeln der Datenkapselung zu halten.
Glaube auch, dass mit der Klasse ist ein gute Idee.
Oder ich kloppe mir die Konstante über ISO C++ Code in die IDE.
Da man ja leider String^ nicht Global vereinbaren kann und darf.Das andere habe ich mal eben verschoben.
Nur habe ich das Gefühl, weil ich nun wieder Mega viele Fehler (33) bekommen habe.
Das die *.h nix von der *.cpp weiß, da der Code in der *.cpp nicht mit eingebunden wird.
Funzt das bei Dir?
Sonst werde ich mal meinem Dozenten auf den Keks gehen.
Würde die Dateien auch gerne trennen.Danke vielmals für Deine Hilfe.
-
Die .h weiß nix von der .cpp das ist richtig.
Aber mom,. ich hab was vergessen:
System::Void **kundenEinzel::**KundenBindingNavigatorSaveItem
Beim Auslagern musst Du den Klassennamen vor die Methode schreiben!
-
Nix zu machen, 35 Fehler.
"kundenEinzel" wird noch nicht einmal in der Memberliste aufgeführt.
Schreibst Du Deine Projekte so?private: System::Void kundenEinzel::KundenBindingNavigatorSaveItem_Click(System::Object^ sender, System::EventArgs^ e) { this->Validate(); this->KundenBindingSource->EndEdit(); this->KundenTableAdapter->Update(this->RAT1DataSet->Kunden); }
-
Ja.
Wie gesagt, bereinige das Projekt mal, pack es und mail es mal zu. Dann kann es ich mal durch den Compiler jagen und guggen wo es klemmt.
-
Doug_HH schrieb:
private: System::Void kundenEinzel::KundenBindingNavigatorSaveItem_Click(System::Object^ sender, System::EventArgs^ e) { this->Validate(); this->KundenBindingSource->EndEdit(); this->KundenTableAdapter->Update(this->RAT1DataSet->Kunden); }
Steht das bei dir so in der cpp? Sollte zwar keine Fehler geben, aber das "private" kannst dir in der cpp sparen!
-
Nee, das steht in der Header so.
-
Du müsstest Dein Beispielprojekt angepasstim Postfach liegen haben
-
Danke Knuddlbaer, echt besser so.
Sorry, aber der Ehrgeiz hat mich eben gepackt, habe grade mein ganzes Projekt umgestrickt (ist noch nicht ganz so groß).
Ist so viel sauberer und übersichtlicher.
Wenn man das gleich von Anfang an macht, hat man danach nicht soviel Arbeit.
Super Sache, werde das au jeden Fall so weiter machen.
Ok, meine erste Antwort streichen, die Faulheit war stärker.Danke nochmal.
Gruß, Doug_HH
-
Die Diskussion hier war sehr aufschlussreich, danke.
Ich habe jetzt den Code in die .cpp gepackt, wie sich das gehört.