Thema: Delphi Label => "Change"

Einzelnen Beitrag anzeigen

grenzgaenger
(Gast)

n/a Beiträge
 
#18

Re: Label => "Change"

  Alt 9. Sep 2007, 13:44
hier mal ein beispiel...

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
 tMyLabel = class(tLabel)
  private
   fOnChange: tNotifyEvent;
   function GetText: TCaption;
   procedure SetText(const Value: TCaption);
  published
   property Caption: TCaption read GetText write SetText;
   property OnChange: tNotifyEvent read fOnChange write fOnChange;
 end;

 
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private-Deklarationen }
    myLabel: tMyLabel;
    procedure SetToTest(sender: tobject);
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

{ tMyLabel }

function tMyLabel.GetText: TCaption;
begin
 inherited;
end;

procedure tMyLabel.SetText(const Value: TCaption);
begin
 if inherited caption <> value then
 begin
  inherited caption := value;
  if assigned(fOnchange) then
   fOnChange(self);
 end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 myLabel := tMyLabel.Create(self);
 myLabel.Parent := self;
 myLabel.Left := 20;
 myLabel.Top := 20;
 myLabel.OnChange := SetToTest;
 myLabel.Caption := 'test';
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
 if mylabel <> NIL then FreeAndNil(MyLabel);
end;

procedure TForm1.SetToTest(sender: tobject);
begin
 myLabel.Caption := 'nix da';
end;

end.
  Mit Zitat antworten Zitat