![]() |
AW: Komponentenentwicklung LED über TShape ?
Zitat:
|
AW: Komponentenentwicklung LED über TShape ?
Vielen Dank erstmal für eure Hilfe,
ich glaub ich fang nochmal von ganz vorn an, da wollt ich zu viel auf einmal:!:. |
AW: Komponentenentwicklung LED über TShape ?
Ich kommentiere mal das Beispiel von DeddyH
Delphi-Quellcode:
type
(* Mögliche Stati *) TLEDState = (lsOff, lsActive, lsInactive); TLED = class(TGraphicControl) private FState: TLEDState; procedure SetState(const Value: TLEDState); protected // Überschreiben der Zeichen-Methode procedure Paint; override; published // Eigenschaft für den Status property State: TLEDState read FState write SetState; end; procedure TLED.Paint; var LEDColor: TColor; begin inherited; // Abhängig vom Status die Zeichenfarbe festlegen case FState of lsActive: LEDColor := clGreen; lsInactive: LEDColor := clRed; else LEDColor := clGray; end; // Zeichnen // Hintergrundfarbe festlegen Canvas.Brush.Color := LEDColor; // Eine Ellipse zeichnen Canvas.Ellipse( 0, 0, ClientWidth, ClientHeight ); end; procedure TLED.SetState(const Value: TLEDState); begin // Ist der neue Wert ungleich dem aktuellen if FState <> Value then // dann begin // diesen neuen Wert speichern FState := Value; // und diese Komponente zum Neuzeichnen vormerken Invalidate; end; end; |
AW: Komponentenentwicklung LED über TShape ?
:thumb:
|
AW: Komponentenentwicklung LED über TShape ?
:coder: :cheer:
|
AW: Komponentenentwicklung LED über TShape ?
Oh mannnnnn, das wird ein Delphi Wochenende, bin froh, wenn zur Laufzeit überhaupt mal was in der Testform erscheint, bis jetzt ist mir da immernoch nichts gelungen.
Der Fehler liegt da speziell zwischen den Ohren :wall: |
AW: Komponentenentwicklung LED über TShape ?
Nimm Dir Zeit - das wird schon ;-)
Ich schlage nochmal das TRedPanel vor. Da musst Du nix malen und hast erst mal klare Ergebnisse. |
AW: Komponentenentwicklung LED über TShape ?
Width und Height sind > 0? Ich habe meinen eigenen Code mal ausprobiert, nach einer kleinen Erweiterung (Überschreiben des Konstruktors) tut das wie gedacht:
Delphi-Quellcode:
[edit] Einen Schönheitspreis gewinnt das natürlich nicht, aber man kann ja auch hübscher zeichen. Hier ging es ja nur um das Prinzip. [/edit]
unit uLED;
interface uses SysUtils, Classes, Controls, Graphics; type (* Mögliche Stati *) TLEDState = (lsOff, lsActive, lsInactive); TLED = class(TGraphicControl) private { Private-Deklarationen } FState: TLEDState; procedure SetState(const Value: TLEDState); protected { Protected-Deklarationen } procedure Paint; override; public { Public-Deklarationen } constructor Create(AOwner: TComponent); override; published { Published-Deklarationen } property State: TLEDState read FState write SetState; end; procedure Register; implementation procedure Register; begin RegisterComponents('Samples', [TLED]); end; { TLED } constructor TLED.Create(AOwner: TComponent); begin inherited; Width := 16; Height := 16; 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, ClientWidth, ClientHeight ); end; procedure TLED.SetState(const Value: TLEDState); begin if FState <> Value then begin FState := Value; invalidate; end; end; end. |
AW: Komponentenentwicklung LED über TShape ?
Super, danke, werd das glei mal ausprobieren :thumb: Danke euch ! Echt super hier mit eurer Hilfe !!!
|
AW: Komponentenentwicklung LED über TShape ?
So hab das mal ausprobiert, egal was ich mache, auf meiner Testform wird nichts angezeigt :oops:
Delphi-Quellcode:
Das ist der Code um die Komponente zur Laufzeit zu testen, steckt da ein Fehler drin ? bei nem anderen Project hat es so gefunzt
unit LedTestUnit;
interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Unit1; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private MyLed : TLED; { Private-Deklarationen } public { Public-Deklarationen } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin MyLed := TLed.Create(Self); MyLed.Parent := Self; MyLed := Show; end; end. |
Alle Zeitangaben in WEZ +1. Es ist jetzt 08:12 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-2025 by Thomas Breitkreuz