Jump to content

Recommended Posts

Posted

Hello,

 

I have a problem with a custom-component derivated form TUniCanvas.

 

The problem is that the dynamic created UniTimer and also TuniThreadTimer never send any "onTimer" event.

 

I did not understand why a similar VCL component work properly.

 

Many thanks for any help....

 

 regards

unit MyUNILED;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, uniCanvas, uniTimer, uniThreadTimer;

type
  TMyUniLED = class(TUniCanvas)
    Timer1: TUniTimer;
    Timer2: TUniThreadTimer;
  private
    procedure OnLedTimer(Sender: TObject);
  protected
  public
    constructor Create(Owner: TComponent); override;
    destructor Destroy; override;
  published
  end;

procedure Register;

implementation

constructor TMyUniLED.Create(Owner: TComponent);

begin

  // Height := 16;
  // Width := 16;
  Timer1 := TUniTimer.Create(Self);
  Timer1.Enabled := True;
  Timer1.Interval := 1000;
  Timer1.OnTimer := OnLedTimer; // <- Event not fired
  Timer1.RunOnce := True;
  //
  Timer2 := TUniThreadTimer.Create(Self);
  Timer2.Enabled := True;
  Timer2.Interval := 1000;
  Timer2.OnTimer := OnLedTimer; // <- Event not fired
  inherited Create(Owner);
  Color := clRed; // only for testing
end;

procedure TMyUniLED.OnLedTimer(Sender: TObject);
var
  i: Integer;
begin
  with BitmapCanvas do
  begin
    Width := Self.Width;
    Height := Self.Height;
    For i := 0 to 30 do
    begin
      Randomize;
      Pen.Width := Random(5) + 5;
      Pen.Color := Random(64738) + 64738;
      Brush.Style := bsFDiagonal;
      Ellipse(Random(Width), Random(Height), Random(Width), Random(Height));
    end;
    Font.Color := clBlue;
    Font.Size := 18;
    TextOut(10, Trunc(Self.Height / 2), DateTimeToStr(Now));
  end;
end;

destructor TMyUniLED.Destroy;
begin
  inherited;
end;

procedure Register;
begin
  RegisterComponents('MIL_uniGUI Custom', [TMyUniLED]);
end;

end.
  • Administrators
Posted

unit MyLED;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, uniCanvas, uniTimer;

type
TMyUniLED = class(TUniCanvas)
private
Timer1: TUniTimer;
procedure OnLedTimer(Sender: TObject);
protected
public
constructor Create(Owner: TComponent); override;
destructor Destroy; override;
published
end;

procedure Register;

implementation

constructor TMyUniLED.Create(Owner: TComponent);
begin
inherited Create(Owner);
Height := 16;
Width := 16;

if WebMode then
begin
Timer1 := TUniTimer.Create(Owner);
Timer1.Enabled := True;
Timer1.Interval := 1000;
Timer1.OnTimer := OnLedTimer; // Timer1.RunOnce := True;
end;
end;

procedure TMyUniLED.OnLedTimer(Sender: TObject);
var
i: Integer;
begin
with BitmapCanvas do
begin
Width := Self.Width;
Height := Self.Height;
For i := 0 to 30 do
begin
Randomize;
Pen.Width := Random(5) + 5;
Pen.Color := Random(64738) + 64738;
Brush.Style := bsFDiagonal;
Ellipse(Random(Width), Random(Height), Random(Width), Random(Height));
end;
Font.Color := clBlue;
Font.Size := 18;
TextOut(10, Trunc(Self.Height / 2), DateTimeToStr(Now));
end;
end;

destructor TMyUniLED.Destroy;
begin
if not (csDestroying in Owner.ComponentState) then
Timer1.Free;

inherited;
end;

procedure Register;
begin
RegisterComponents('MIL_uniGUI Custom', [TMyUniLED]);
end;

end.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...