Delphi-PRAXiS
Seite 2 von 5     12 34     Letzte »    

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Neuen Beitrag zur Code-Library hinzufügen (https://www.delphipraxis.net/33-neuen-beitrag-zur-code-library-hinzufuegen/)
-   -   Komponentenentwicklung LED über TShape ? (https://www.delphipraxis.net/176730-komponentenentwicklung-led-ueber-tshape.html)

Chris211183 23. Sep 2013 10:40

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

Chris211183 24. Sep 2013 10:43

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 !

DeddyH 24. Sep 2013 13:26

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:
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;
P.S.: Benutze doch bitte künftig die Delphi-Tags (die "Helm"-Schaltfläche im Beitragseditor), dann ist der Code viel besser zu lesen.

Chris211183 25. Sep 2013 11:16

AW: Komponentenentwicklung LED über TShape ?
 
:lol::roll:, Danke Dir !

Alles Klar, mach ich !

sx2008 25. Sep 2013 12:37

AW: Komponentenentwicklung LED über TShape ?
 
Ich würde es so machen wie bei der TJvLed (sourcecode):
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.

Chris211183 27. Sep 2013 09:50

AW: Komponentenentwicklung LED über TShape ?
 
Ich wollte mal meine Komponente Testen, jedoch wird nix dsrgestellt :?

Delphi-Quellcode:
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;
jemand ne Ahnung warum nichts beim Test während der Laufzeit auf meinem Formular zu sehen ist ?? Ich langsam nicht mehr :pale:

DeddyH 27. Sep 2013 10:41

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?

stahli 27. Sep 2013 12:28

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.

Sir Rufo 27. Sep 2013 13:04

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:
Invalidate
mitgeteilt, dass eine Änderung passiert ist und ein Neuzeichnen erforderlich ist.

Ein Code-Beispiel folgt sogleich ...

DeddyH 27. Sep 2013 13:09

AW: Komponentenentwicklung LED über TShape ?
 
*Psst* ein Code-Beispiel steht bereits da oben ;)


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:22 Uhr.
Seite 2 von 5     12 34     Letzte »    

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz