Komponentenentwicklung -> Problem bei Eigenschaften



  • Hi!!

    Ich leite gerade eine Komponente von TComboBox ab. Ich versuche eine einfach StringList als Eigenschaft zu integrieren. Leider bekomme ich einen komischen Fehler 😉

    Header:

    //---------------------------------------------------------------------------
    
    #ifndef ONMComboBoxH
    #define ONMComboBoxH
    //---------------------------------------------------------------------------
    #include <SysUtils.hpp>
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <String.h>
    //---------------------------------------------------------------------------
    class PACKAGE TONMComboBox : public TComboBox
    {
    private:
    	TStringList* FAllItems;
    	void __fastcall SetAllItems(TStringList* value);
    protected:
    public:
    	__fastcall TONMComboBox(TComponent* Owner);
    __published:
    	__property TStringList* AllItems = {read=AllItems, write=SetAllItems};
    };
    //---------------------------------------------------------------------------
    #endif
    

    C++:

    //---------------------------------------------------------------------------
    
    #include <vcl.h>
    
    #pragma hdrstop
    
    #include "ONMComboBox.h"
    #pragma package(smart_init)
    //---------------------------------------------------------------------------
    // Mit ValidCtrCheck wird sichergestellt, dass die erzeugten Komponenten
    // keine rein virtuellen Funktionen besitzen.
    //
    
    static inline void ValidCtrCheck(TONMComboBox *)
    {
    	new TONMComboBox(NULL);
    }
    //---------------------------------------------------------------------------
    __fastcall TONMComboBox::TONMComboBox(TComponent* Owner)
    	: TComboBox(Owner)
    {
    }
    //---------------------------------------------------------------------------
    namespace Onmcombobox
    {
    	void __fastcall PACKAGE Register()
    	{
    		TComponentClass classes[1] = {__classid(TONMComboBox)};
    		RegisterComponents("Standard", classes, 0);
    	}
    }
    //---------------------------------------------------------------------------
    

    Bin dankbar für jede Hilfe!!! 🙂



  • Die Fehlermeldung wäre noch nützlich glaube ich 🙄

    [Linker Fehler] Error: Ungelöste externe '__fastcall TONMComboBox::SetAllItems(Classes::TStringList *)' referenziert von C:\DOKUMENTE UND EINSTELLUNGEN\MS\DESKTOP\TONMCOMBOBOX\DEBUG_BUILD\ONMCOMBOBOX.OBJ



  • Hallo

    Was ist daran unverständlich? Ich kann in deinem Codeauszug keine Implementation für TONMComboBox::SetAllItems finden, und der Compiler auch nicht.

    bis bald
    akari



  • Hi,

    ok, das habe ich vergessen. Jetzt siehts so aus, lässt sich auch installieren, aber wenn ich dann die Komponente auf einem Form platziere bekomme ich wieder einen Fehler.

    //---------------------------------------------------------------------------
    
    #ifndef ONMComboBoxH
    #define ONMComboBoxH
    //---------------------------------------------------------------------------
    #include <SysUtils.hpp>
    #include <Classes.hpp>
    #include <Controls.hpp>
    #include <StdCtrls.hpp>
    #include <String.h>
    //---------------------------------------------------------------------------
    class PACKAGE TONMComboBox : public TComboBox
    {
    private:
    	TStringList* FAllItems;
    	void __fastcall SetAllItems(TStringList* Items){ FAllItems=Items;};
    protected:
    public:
    	__fastcall TONMComboBox(TComponent* Owner);
    __published:
    	__property TStringList* AllItems = {read=AllItems, write=SetAllItems};
    };
    //---------------------------------------------------------------------------
    #endif
    

    Fehler:

    + $0[51F06822]{rtl100.bpl } System.System.TObject.InheritsFrom (Line 9250, "system.pas" + 2) + $0
    + $0[51F06B47]{rtl100.bpl } System.System.@HandleAnyException (Line 9980, "system.pas" + 13) + $0
    + $41[7C913786]{ntdll.dll } RtlConvertUlongToLargeInteger + $41



  • *push*

    Hat denn niemand Ahnung von Komponentenentwicklung? Das Problem ist ja, dass er ja alles erfolgreich kompiliert aber beim zugreifen auf die Eigenschaft ( schon im WYSIWYG-Editor ) kommt der Fehler ganz komisch 😉 ^^



  • Hallo

    Ich glaube nicht das es gut ist einen Setter für eine TStringList anzugeben. Ein Getter sollte reichen da TStrings ja bereits alle notwenigen Bearbeitungsfunktionen hat. Du erstellst also im Konstruktor der neuen Komponente die TStringList und löscht sie im Destruktor. Über die Property kann nun die StringList bearbeitet werden.
    Und ich würde auch für den Typ der Property selber nur TStrings nehmen, so wie es auch TListBox macht.

    bis bald
    akari



  • Danke!! Hast mir sehr geholfen, hab mal wieder zu kompliziert gedacht! ^^ 😋


Anmelden zum Antworten