![]() |
AW: Komponentenentwicklung LED über TShape ?
ahhhhh, jetzt kommt Licht ins Dunkle, vielen Dank Euch allen, ich mach mal ein bissl rum und melde mich wieder !
:stupid::stupid::stupid: Danke |
AW: Komponentenentwicklung LED über TShape ?
Hallo @all,
da bin ich wieder, soweit klappt das wohl jetzt halbwegs, noch ein paar Fragen haben sich jetzt aufgetan: Die Komponente soll die Eigenschaften aus = grau, Activ = Grün und Inactiv = Rot haben wie kann man das hier implementieren, habe bis jetzt folgenden Code: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TLED = class(TForm) HoyLed: TShape; private FActive: Boolean; procedure SetActive(const Value: Boolean); public published property Active: Boolean read FActive write SetActive; end; var LED: TLED; Shape : TShape; Brush: TShape; Color: TColor; ShowHint: Boolean; implementation {$R *.dfm} procedure TLED.SetActive(const Value: Boolean); begin if Active <> FActive then begin FActive := Active; invalidate; end; begin Shape := TShape.Create(LED); with Shape do begin Left := 30; Top := 30; Width := 30; Color := clGreen; end; end; end; end. Bin über jede Hilfe dankbar ! |
AW: Komponentenentwicklung LED über TShape ?
Wieso leitest Du denn von TForm ab? Und weshalb ein Boolean für 3 mögliche Zustände? Ich würde das etwa so angehen (ungetestet, da im Editor getippt):
Delphi-Quellcode:
P.S.: Benutze doch bitte künftig die Delphi-Tags (die "Helm"-Schaltfläche im Beitragseditor), dann ist der Code viel besser zu lesen.
type
(* Mögliche Stati *) TLEDState = (lsOff, lsActive, lsInactive); TLED = class(TGraphicControl) private FState: TLEDState; procedure SetState(const Value: TLEDState); protected procedure Paint; override; published property State: TLEDState read FState write SetState; end; procedure TLED.Paint; var LEDColor: TColor; begin inherited; case FState of lsActive: LEDColor := clGreen; lsInactive: LEDColor := clRed; else LEDColor := clGray; end; Canvas.Brush.Color := LEDColor; Canvas.Ellipse(0, 0, Width, Height); end; procedure TLED.SetState(const Value: TLEDState); begin if FState <> Value then begin FState := Value; invalidate; end; end; |
AW: Komponentenentwicklung LED über TShape ?
:lol::roll:, Danke Dir !
Alles Klar, mach ich ! |
AW: Komponentenentwicklung LED über TShape ?
Ich würde es so machen wie bei der TJvLed (
![]() Eine Farbe für den aktiven Zustand, eine Farbe für den nichtaktiven Zustand und eine Hintergrundfarbe. Bei der Simulation einer Zweifarben-LED setzt man dann eben property ColorOn jeweils auf Rot oder Grün. |
AW: Komponentenentwicklung LED über TShape ?
Ich wollte mal meine Komponente Testen, jedoch wird nix dsrgestellt :?
Delphi-Quellcode:
jemand ne Ahnung warum nichts beim Test während der Laufzeit auf meinem Formular zu sehen ist ?? Ich langsam nicht mehr :pale:
unit LedUnit;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, ExtCtrls, StdCtrls; type TLED = class(TGraphicControl) //HoyLed: TShape; private { Private declarations } FActive: Boolean; procedure SetActive(const Value: Boolean); protected { Protected declarations } public { Public declarations } published { Published declarations } property Active: Boolean read FActive write SetActive; end; var LED: TLED; Shape : TShape; Brush: TShape; Color: TColor; ShowHint: Boolean; implementation {$R *.dfm} procedure TLED.SetActive(const Value: Boolean); begin if Active <> FActive then begin FActive := Active; invalidate; end; begin Shape := TShape.Create(LED); with Shape do begin Left := 30; Top := 30; Width := 30; end; end; end; type TTriangleShape = class(TShape) private { Private declarations } protected { Protected declarations } procedure Paint; override; public { Public declarations } published { Published declarations } end; type TPointArray = array [0..2] of TPoint; PPointArray = ^TPointArray; procedure TTriangleShape.Paint; begin with Canvas do begin Polygon([Point(0, (Self.Height-2)), Point((Self.Width div 2), 0), Point(Self.Width, (Self.Height-2)), Point(0, (Self.Height-2))]); end; end; |
AW: Komponentenentwicklung LED über TShape ?
Du hast da begins und ends sowie Typdeklarationen wild im Code verteilt. Was gehört denn wozu? Und woher soll der Compiler das wissen? Und wozu ein GraphicControl und zusätzlich noch ein TShape?
|
AW: Komponentenentwicklung LED über TShape ?
Du solltest Dich erst einmal mit der Komponentenentwicklung grundsätzlich befassen.
Ein schönes Beispiel (und auch mein erstes ;-) ) ist die "Entwicklung" eines TRedPanels. Das soll in der Komponentenpalette stehen und wenn man es in´s Formular zieht soll es rot sein. Wenn Du das geschafft hast sollte es auch möglich werden, andere Komponenten zu entwickeln, die etwas komplexer sind. Mit dem TRedPanel bleibt es aber erst mal schön übersichtlich und man lernt die Abläufe kennen. Welche Delphi-Version hast Du denn? Die könntest Du auch mal in Deinem Profil angeben. |
AW: Komponentenentwicklung LED über TShape ?
Bei einer "visuellen" Komponente, muss ja auch etwas visualisiert werden.
Dieses erreicht man, indem etwas gezeichnet wird. Folglich muss die Paint-Methode entsprechend angepasst (überschrieben) werden, denn genau diese ist für das Zeichnen zuständig. Das ist so eigentlich das große Geheimnis bei dieser Art von Komponente die du haben willst. Wie und was du da zeichnest und warum (Berücksitigung von Parametern) genau so ist egal, Hauptsache es wird gezeichnet. Bei einer Änderung der Parameter wird der Komponente einfach mit
Delphi-Quellcode:
mitgeteilt, dass eine Änderung passiert ist und ein Neuzeichnen erforderlich ist.
Invalidate
Ein Code-Beispiel folgt sogleich ... |
AW: Komponentenentwicklung LED über TShape ?
*Psst* ein Code-Beispiel steht bereits da oben ;)
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 02:17 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz