[lazarus] LED Component
Jay Dubal
jay.dubal at intergold.net
Wed Feb 5 23:54:13 EST 2003
Hi there,
I made a LED component which could display digits 0 - 9 works
well on Delphi and I modified it to work on Lazarus. The unit got compiled and
the component is on the pallet BUT.... when I drop it on Form not only Lazarus
but the whole XWindows HANGSS!!!!!
I am sendin the atachment and I request to inspect the unit
before compiling. If the attachemnt is not there then here is the code for it
*****************************************************************************
START OF CODE ...
{************************************************************************
Author : Jay Dubal
version : 2.0
E-mail : delphisoft at hotpop.com, jaydubal at hotmail.com
URL : http://delphisoft.topcities.com
copyleft® DelphiSoft
This is a Free! component. You can modify it as you like
and you don'nt need to inform me. Use it at my risk as
it is fully tested and works perfectly (Delphi 6.0)
_a__
| |b
f | |
-g-- The basic 7 segment Light Emitting Diode (LED)
e | | c This version 2.0 has More real LED shape
| |
-d--
**************************************************************************}
unit JDLed;
{$mode objfpc}
interface
uses
SysUtils, Classes, Controls, Graphics, Dialogs,
LMessages, LResources, Forms, StdCtrls;
type
TJDLed = class(TGraphicControl)
private
procedure SetLedDigit(value : integer);
procedure SetLedThick(value: integer);
{ Private declarations }
protected
FDigit : integer;
FThick : integer;
procedure Paint; override;
{ Protected declarations }
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
{ Public declarations }
published
property Digit : integer read FDigit write SetLedDigit;
property Thick : integer read FThick write SetLedThick;
{ Published declarations }
end;
implementation
constructor TJDLed.Create(AOwner: TComponent);
begin
inherited Create(AOwner); { always call the inherited constructor }
FDigit := 1;
FThick := 5;
Height := 90;
Width := 50;
with Constraints do
begin
MinHeight := 30;
MinWidth := 15;
end;
end;
destructor TJDLed.Destroy;
begin
inherited Destroy;
end;
procedure TJDLed.Paint;
var
X1,X2,X3,X4,X5,X6,X7,Z,Z1 : integer;
begin
X1 := self.Height;
X2 := self.Width;
X3 := self.FThick;
Z := abs(X3 div 2);
Z1 := abs(self.Height div 2);
X4 := Z1 - Z;
X5 := Z1 + Z;
X6 := Z1 - X3 - Z;
X7 := Z1 + X3 + Z;
inherited;
with Canvas do
begin
Refresh;
Brush.Color := clBlack;
Pen.Color := clBlack;
Refresh;
Rectangle(0,0,self.Width,self.Height);
Brush.Color := clRed;
Pen.Color := clRed;
Refresh;
case FDigit of
0:
begin
Polygon([Point(Z,0),Point(X2-Z,0),Point(X2-X3-Z,X3),Point(X3 +
Z,X3)]); // a
Polygon([Point(X2-X3,X3+Z),Point(X2,Z),Point(X2,X4),Point(X2-
X3,X6)]); // b
Polygon([Point(X2-X3,X7),Point(X2,X5),Point(X2,X1-Z),Point(X2-X3,X1-X3-
Z)]); // c
Polygon([Point(X3+Z,X1-X3),Point(X2-X3-Z,X1-X3),Point(X2-Z,X1),Point(X3-
Z,X1)]); // d
Polygon([Point(0,X5),Point(X3,X7),Point(X3,X1-X3-Z),Point(0,X1-Z)]); // e
Polygon([Point(0,Z),Point(X3,X3+Z),Point(X3,X6),Point(0,X4)]); // f
end;
1:
begin
Polygon([Point(X2-X3,X3+Z),Point(X2,Z),Point(X2,X4),Point(X2-
X3,X6)]); // b
Polygon([Point(X2-X3,X7),Point(X2,X5),Point(X2,X1-Z),Point(X2-X3,X1-X3-
Z)]); // c
end;
2:
begin
Polygon([Point(Z,0),Point(X2-Z,0),Point(X2-X3-Z,X3),Point(X3 +
Z,X3)]); // a
Polygon([Point(X2-X3,X3+Z),Point(X2,Z),Point(X2,X4),Point(X2-
X3,X6)]); // b
Polygon([Point(X3+Z,X1-X3),Point(X2-X3-Z,X1-X3),Point(X2-Z,X1),Point(X3-
Z,X1)]); // d
Polygon([Point(0,X5),Point(X3,X7),Point(X3,X1-X3-Z),Point(0,X1-Z)]); // e
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1-Z - abs(Z div 4)),Point
(X2-X3-Z,Z1-Z - abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g1
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1+Z + abs(Z div 4)),Point
(X2-X3-Z,Z1+Z + abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g2
end;
3:
begin
Polygon([Point(Z,0),Point(X2-Z,0),Point(X2-X3-Z,X3),Point(X3 +
Z,X3)]); // a
Polygon([Point(X2-X3,X3+Z),Point(X2,Z),Point(X2,X4),Point(X2-
X3,X6)]); // b
Polygon([Point(X2-X3,X7),Point(X2,X5),Point(X2,X1-Z),Point(X2-X3,X1-X3-
Z)]); // c
Polygon([Point(X3+Z,X1-X3),Point(X2-X3-Z,X1-X3),Point(X2-Z,X1),Point(X3-
Z,X1)]); // d
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1-Z - abs(Z div 4)),Point
(X2-X3-Z,Z1-Z - abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g1
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1+Z + abs(Z div 4)),Point
(X2-X3-Z,Z1+Z + abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g2
end;
4:
begin
Polygon([Point(X2-X3,X3+Z),Point(X2,Z),Point(X2,X4),Point(X2-
X3,X6)]); // b
Polygon([Point(X2-X3,X7),Point(X2,X5),Point(X2,X1-Z),Point(X2-X3,X1-X3-
Z)]); // c
Polygon([Point(0,Z),Point(X3,X3+Z),Point(X3,X6),Point(0,X4)]); // f
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1-Z - abs(Z div 2)),Point
(X2-X3-Z,Z1-Z - abs(Z div 2)),Point(X2-X3 + abs(Z div 2),Z1)]); // g1
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1+Z + abs(Z div 2)),Point
(X2-X3-Z,Z1+Z + abs(Z div 2)),Point(X2-X3 + abs(Z div 2),Z1)]); // g2
end;
5:
begin
Polygon([Point(Z,0),Point(X2-Z,0),Point(X2-X3-Z,X3),Point(X3 +
Z,X3)]); // a
Polygon([Point(X2-X3,X7),Point(X2,X5),Point(X2,X1-Z),Point(X2-X3,X1-X3-
Z)]); // c
Polygon([Point(X3+Z,X1-X3),Point(X2-X3-Z,X1-X3),Point(X2-Z,X1),Point(X3-
Z,X1)]); // d
Polygon([Point(0,Z),Point(X3,X3+Z),Point(X3,X6),Point(0,X4)]); // f
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1-Z - abs(Z div 4)),Point
(X2-X3-Z,Z1-Z - abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g1
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1+Z + abs(Z div 4)),Point
(X2-X3-Z,Z1+Z + abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g2
end;
6:
begin
Polygon([Point(Z,0),Point(X2-Z,0),Point(X2-X3-Z,X3),Point(X3 +
Z,X3)]); // a
Polygon([Point(X2-X3,X7),Point(X2,X5),Point(X2,X1-Z),Point(X2-X3,X1-X3-
Z)]); // c
Polygon([Point(X3+Z,X1-X3),Point(X2-X3-Z,X1-X3),Point(X2-Z,X1),Point(X3-
Z,X1)]); // d
Polygon([Point(0,X5),Point(X3,X7),Point(X3,X1-X3-Z),Point(0,X1-Z)]); // e
Polygon([Point(0,Z),Point(X3,X3+Z),Point(X3,X6),Point(0,X4)]); // f
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1-Z - abs(Z div 4)),Point
(X2-X3-Z,Z1-Z - abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g1
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1+Z + abs(Z div 4)),Point
(X2-X3-Z,Z1+Z + abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g2
end;
7:
begin
Polygon([Point(Z,0),Point(X2-Z,0),Point(X2-X3-Z,X3),Point(X3 +
Z,X3)]); // a
Polygon([Point(X2-X3,X3+Z),Point(X2,Z),Point(X2,X4),Point(X2-
X3,X6)]); // b
Polygon([Point(X2-X3,X7),Point(X2,X5),Point(X2,X1-Z),Point(X2-X3,X1-X3-
Z)]); // c
end;
8:
begin
Polygon([Point(Z,0),Point(X2-Z,0),Point(X2-X3-Z,X3),Point(X3 +
Z,X3)]); // a
Polygon([Point(X2-X3,X3+Z),Point(X2,Z),Point(X2,X4),Point(X2-
X3,X6)]); // b
Polygon([Point(X2-X3,X7),Point(X2,X5),Point(X2,X1-Z),Point(X2-X3,X1-X3-
Z)]); // c
Polygon([Point(X3+Z,X1-X3),Point(X2-X3-Z,X1-X3),Point(X2-Z,X1),Point(X3-
Z,X1)]); // d
Polygon([Point(0,X5),Point(X3,X7),Point(X3,X1-X3-Z),Point(0,X1-Z)]); // e
Polygon([Point(0,Z),Point(X3,X3+Z),Point(X3,X6),Point(0,X4)]); // f
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1-Z - abs(Z div
4)),Point(X2-X3-Z,Z1-Z - abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g1
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1+Z + abs(Z div 4)),Point
(X2-X3-Z,Z1+Z + abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g2
end;
9:
begin
Polygon([Point(Z,0),Point(X2-Z,0),Point(X2-X3-Z,X3),Point(X3 +
Z,X3)]); // a
Polygon([Point(X2-X3,X3+Z),Point(X2,Z),Point(X2,X4),Point(X2-
X3,X6)]); // b
Polygon([Point(X2-X3,X7),Point(X2,X5),Point(X2,X1-Z),Point(X2-X3,X1-X3-
Z)]); // c
Polygon([Point(X3+Z,X1-X3),Point(X2-X3-Z,X1-X3),Point(X2-Z,X1),Point(X3-
Z,X1)]); // d
Polygon([Point(0,Z),Point(X3,X3+Z),Point(X3,X6),Point(0,X4)]); // f
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1-Z - abs(Z div 4)),Point
(X2-X3-Z,Z1-Z - abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g1
Polygon([Point(X3 - abs(Z div 2),Z1),Point(X3+Z,Z1+Z + abs(Z div 4)),Point
(X2-X3-Z,Z1+Z + abs(Z div 4)),Point(X2-X3 + abs(Z div 2),Z1)]); // g2
end;
end;
Refresh;
end;
end;
procedure TJDLed.SetLedDigit(value: integer);
begin
if (value >= 0) and (value <= 9) then
begin
FDigit := value;
Paint;
end;
end;
procedure TJDLed.SetLedThick(value: integer);
begin
if (value > 2) then
begin
FThick := Value;
Paint;
end;
end;
initialization
{$I jdledicon.lrs}
end.
END OF CODE.....
*****************************************************************************
Jay Dubal
delphisoft.topcities.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zip00009.zip
Type: application/octet-stream
Size: 2362 bytes
Desc: "laz-jdled.zip"
Url : http://localhost/pipermail/lazarus/attachments/20030205/1611a039/zip00009.obj
More information about the Lazarus
mailing list