Grafische Komponenente



  • Hi,
    ich würd das so machen:

    void __fastcall TTemp::SetIMColor(TColor NewColor)
    {
          if (IMColor != NewColor) {
                IMColor = NewColor;
          	Repaint();
          }
    }
    

    Dann wirds nur beim tatsächlichen Ändern neugezeichnet.

    MfG

    Alexander Sulfrian



  • void __fastcall TTemp::SetIMColor(TColor NewColor)
    {
          if (IMColor != NewColor) {
                IMColor = NewColor;
              Repaint();
          }
    }
    

    Gute Idee.

    Ich habe nun noch die Eigenschaften PosValue, ErrorValue, NoErrorColor, ErrorColor.
    Ist ErrorValue > PosValue wird die Farbe ErrorColor benutzt, sonst NoErrorColor.
    Sollte man da so vorgehen oder anders.

    class PACKAGE TTemp : public TGraphicControl
    {
    private:
    TColor Color;
    TColor IMNoErrorColor;
    TColor IMErrorColor;
    int IMErrorValue;
    int IMPosValue;
    void __fastcall Paint(void);
    void __fastcall SetIMNoErrorColor(TColor NewColor);
    void __fastcall SetIMErrorColor(TColor NewColor);
    void __fastcall SetIMErrorValue(int NewErrorValue);
    void __fastcall SetIMPosValue(int NewPosValue);
    void DrawGrafValue(void);
    __published:
        __property TColor NoErrorColor = {read=IMNoErrorColor,write=SetIMNoErrorColor};
        __property TColor ErrorColor = {read=IMErrorColor,write=SetIMErrorColor};
        __property int  ErrorValue = {read=IMErrorValue,write=SetIMErrorValue};
    
    protected:
    public:
        __fastcall TTemp(TComponent* Owner);
        __property int  PosValue = {read=IMPosValue,write=SetIMPosValue};
    };
    
    //---------------------------------------------------------------------------
    __fastcall TTemp::TTemp(TComponent* Owner)
    	: TGraphicControl(Owner)
    {
        Height     = 100;
        Width      = 100;
    }
    //---------------------------------------------------------------------------
    void __fastcall TTemp::SetIMNoErrorColor(TColor NewColor)
    {
         IMNoErrorColor = NewColor;
    }
    //---------------------------------------------------------------------------
    void __fastcall TTemp::SetIMErrorColor(TColor NewColor)
    {
         IMErrorColor = NewColor;
    }
    //---------------------------------------------------------------------------
    void __fastcall TTemp::SetIMErrorValue(int NewErrorValue)
    {
         IMErrorValue = NewErrorValue;
    }
    //---------------------------------------------------------------------------
    void __fastcall TTemp::SetIMPosValue(int NewPosValue)
    {
         IMPosValue = NewPosValue;
         if(IMPosValue > IMErrorValue)
         {
    		Color	= IMErrorColor;
         }
         else
         {
    		Color	= IMNoErrorColor;
         }
         Repaint();
    }
    //---------------------------------------------------------------------------
    void __fastcall TTemp::Paint(void)
    {
        DrawGrafValue();
    }
    //---------------------------------------------------------------------------
    // Zeichnet eine Balckengrafig
    //---------------------------------------------------------------------------
    void TTemp::DrawGrafValue()
    {
        Canvas->Brush->Color = Color;
         Canvas->FillRect(Rect(0,0,Width,Height));
    }
    

    Und kann man ohne Probleme eine Timer Instanz erzeugen, die dann das ganze
    noch blinken lässt, oder besser nicht.



  • Hallo,

    die Eigenschaften Width sowie Height werden ja von TGraphicControl als Publisched
    geerbt.

    Wie kann ich diese Eigenschaften nun als private überschreiben.



  • Hallo

    indem du

    __property int Width;
    __property int Height;
    

    in den private-Teil deiner Klasse schreibst.
    Allerdings kann das zu unschönen Fehlern führen.

    bis bald
    akari



  • Dann kommt die Fehlermeldung _property-Variable muss initialisiert sein.



  • Hallo

    sorry, int muß da weg

    __property Width;
    __property Height;
    

    bis bald
    akari



  • Scheint irgendwie nicht richtig zu sein, die Eigenschaften tauchen nachwievor
    im OI auf.

    Ist vieleicht
    __property int Width;
    __property int Height;

    doch nicht richtig.

    TGraphicControl erbt die Eigenschaft von TControl.
    TControl::Height
    __property int Height = {read=FHeight, write=SetHeight, nodefault};

    muss ich da nicht auch noch die Membervariablen int FHeight, int SetHight mit
    überschreiben und dann unter private
    __property int Height = {read=FHeight, write=SetHeight};
    die Property überschreiben.
    Habe das schon probiert, funkt aber auch nicht.


Anmelden zum Antworten