Rückgabewert einer Komponente



  • Hallo,

    habe ein Problem bei einem Rückgabewert einer Komponete. Beim Platzieren der Komponente auf der Form, wird ein Wet 0 zurückgegeben, obwohl default 1 ist.
    wo ist der Fehler ?

    in *.cpp

    //***************************************************************************
    //*****          Get - Funktion für  Option - Status
    //***********************************
    OptionIndex __fastcall TProjectLog::GetStatus()
    {
        return FStatus;
    }
    //---------------------------------------------------------------------------
    
    //***************************************************************************
    //*****          Set - Funktion für  Option - Status
    //***********************************
    void __fastcall TProjectLog::SetStatus(int Value)
    {
        FStatus = Value;
    }
    //---------------------------------------------------------------------------
    

    in *.h

    private:
    int FStatus;
    void  __fastcall    SetStatus(int);
    void  __fastcall    GetStatus();
    
    __published:
    __property  int SStatus = { read = GetStatus, write = SetStatus, default=1 };
    

    Gruß Siegfried 😞



  • Hallo,

    Der default-Wert initialisiert nicht deine property. Er ist nur für das Speichern in der dfm-Datei. Initialisieren mußt du den Wert (im Konstruktor) schon selbst.
    Zitat aus der BCB-Hilfe zu default

    Note: Declaring a default value does not set the property to that value. The component’s constructor method should initialize property values when appropriate. However, since objects always initialize their data members to 0, it is not strictly necessary for the constructor to set integer properties to 0, string properties to null, or Boolean properties to false.



  • Hallo,

    im Konstruktor habe ich nichts initialisiert.
    ich werde hier mal den Wert auf 1 setzen.

    Gruß Siegfried


Anmelden zum Antworten