Thema: Delphi Matrix-Effekt

Einzelnen Beitrag anzeigen

Benutzerbild von Jens Schumann
Jens Schumann

Registriert seit: 27. Apr 2003
Ort: Bad Honnef
1.644 Beiträge
 
Delphi 2009 Professional
 
#7

Re: Matrix-Effekt

  Alt 16. Jan 2004, 19:10
Hallo,
wie wäre es mit einer Komponente.
Delphi-Quellcode:
unit JsMatrixLabel;

interface

uses
  SysUtils, Classes, Controls, StdCtrls, ExtCtrls;

type
  TJsMatrixLabel = class(TCustomLabel)
  private
    { Private-Deklarationen }
    FTimer : TTimer;
    FRun : Boolean;
    FInnerCaption : TCaption;
    FTimerEventCounter : Integer;
    function GetInterval: Integer;
    procedure SetInterval(const Value: Integer);
    procedure SetRun(const Value: Boolean);
    function GetCaption: TCaption;
    procedure SetCaption(const Value: TCaption);
    procedure TimerEvent(Sender : TObject);
  protected
    { Protected-Deklarationen }
  public
    { Public-Deklarationen }
    constructor Create(AOwner : TComponent); override;
    destructor Destroy; override;
  published
    { Published-Deklarationen }
    property Autosize;
    property Caption : TCaption read GetCaption write SetCaption;
    property Interval : Integer read GetInterval write SetInterval;
    property Run : Boolean read FRun write SetRun;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('MyComps', [TJsMatrixLabel]);
end;

{ TJsMatrixLabel }

constructor TJsMatrixLabel.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FTimer:=TTimer.Create(Self);
  FTimer.Enabled:=False;
  FTimer.OnTimer:=TimerEvent;
  FTimer.Interval:=500;
end;

destructor TJsMatrixLabel.Destroy;
begin
  FTimer.Free;
  inherited Destroy;
end;

function TJsMatrixLabel.GetCaption: TCaption;
begin
  Result:=inherited Caption;
end;

function TJsMatrixLabel.GetInterval: Integer;
begin
  Result:=FTimer.Interval;
end;

procedure TJsMatrixLabel.SetCaption(const Value: TCaption);
begin
  FInnerCaption:=Value;
  If (csDesigning in ComponentState) then
    inherited Caption:=Value
    else
      inherited Caption:='';
end;

procedure TJsMatrixLabel.SetInterval(const Value: Integer);
begin
  FTimer.Interval:=Value;
end;

procedure TJsMatrixLabel.SetRun(const Value: Boolean);
begin
  If FRun<>Value then
    begin
    FRun:=Value;
    FTimer.Enabled:=FRun;
    FTimerEventCounter:=0;
    If FRun then
      inherited Caption:='';
    If (csDesigning in ComponentState) and (Not FRun) then
      inherited Caption:=FInnerCaption
    end;
end;

procedure TJsMatrixLabel.TimerEvent(Sender: TObject);
begin
  Inc(FTimerEventCounter);
  If FTimerEventCounter<=Length(FInnerCaption) then
    inherited Caption:=inherited Caption + FInnerCaption[FTimerEventCounter]
    else
      Run:=False;
end;

end.
Ein Problem habe ich aber entdeckt und noch nicht gelöst. Wenn zur Designzeit Run auf True
gesetzt wird zeigt das Label den gewünschten Effekt. Wenn der Effekt durchgelaufen ist, wird
Run im Code wieder auf False gesetzt. Aber im OI bleibt True stehen. Erst wenn man
eine andere Eigenschaft anwählt wird wird die Run Eigenschaft im OI aktualisiert.
Das gilt analog für die Caption Eiegenschaft. Das Problem habe ich unter D5 Pro und D7 Pro.Weiß evt jemand warum das so ist ?
  Mit Zitat antworten Zitat