掲示板システム
ホーム
アクセス解析
カテゴリ
ログアウト
カスタムコントロール:独自イベントを作成するには? (ID:21599)
名前
ホームページ(ブログ、Twitterなど)のURL (省略可)
本文
参考になねかどうか判りませんが、最初のほうの内容を読んでいて、 んじゃ貼ってみようか・・な感じです。 まだ途中なんですが・・。自分も、あまり詳しくないので、どこかおかしいかも・・。 // ダイス途中版 // Delphi を立ち上げて、「全上書き」してください。 // ラベルをクリックしても動き出しますが、再度クリックしても止まりません。 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) private { Private 宣言 } Bt2: TButton; Bt3: TButton; public { Public 宣言 } procedure Srart(Sender: TObject); procedure Stop(Sender: TObject); constructor Create(AOwner: TComponent); override; end; TDice = class(TLabel) ATimer: TTimer; private FOnClick: TNotifyEvent; FOnTimer: TNotifyEvent; public constructor Create(AOwner: TComponent); override; procedure Click; override; procedure Start; procedure Stop; procedure Timer(Sender: TObject); published property OnClick: TNotifyEvent read FOnClick write FOnClick; property OnTimer: TNotifyEvent read FOnTimer write FOnTimer; end; var Form1: TForm1; DDD0: TDice; DDD1: TDice; DDD2: TDice; implementation {$R *.dfm} // TDice クラス定義 ------------------------------ constructor TDice.Create(AOwner: TComponent); begin inherited Create(AOwner); ATimer := TTimer.Create(AOwner); ATimer.Enabled := False; ATimer.Interval := 100; // ATimer.OnTimer := OnTimer; // ??????? ATimer.OnTimer := Timer;///////////// Color := clRed; AutoSize := False; Alignment := taCenter; Height := 50; Width := 50; Font.Size := 35; Caption := '0'; end; procedure TDice.Click; begin inherited Click; { 継承メソッドを呼び出す } ATimer.Enabled := True; end; procedure TDice.Start; begin Click; end; procedure TDice.Stop; begin ATimer.Enabled := False; end; procedure TDice.Timer; begin Caption := IntToStr(Random(6)+1); end; ///////// // TForm1 クラス定義 -------------------------------- constructor TForm1.Create(AOwner: TComponent); begin inherited Create(AOwner); Bt2 := TButton.Create(self); with Bt2 do begin Parent := self; Left := 200; Top := 5; Caption := 'スタート'; OnClick := Srart; end; Bt3 := TButton.Create(self); with Bt3 do begin Parent := self; Left := 200; Top := 35; Caption := 'ストップ'; OnClick := Stop; end; DDD0 := TDice.Create(self); DDD0.Parent := self; DDD1 := TDice.Create(self); DDD1.Parent := self; DDD1.Left := DDD1.Width + 4; DDD2 := TDice.Create(self); DDD2.Parent := self; DDD2.Left := DDD1.Width*2 + 4*2; end; procedure TForm1.Srart; begin DDD0.Start; DDD1.Start; DDD2.Start; end; procedure TForm1.Stop; begin DDD0.Stop; DDD1.Stop; DDD2.Stop; end; end.
←解決時は質問者本人がここをチェックしてください。
更新する
戻る
掲示板システム
Copyright 2021 Takeshi Okamoto All Rights Reserved.