怎么让有从TPersistent继承来的属性的控件随着该属性值的改变而改变?(请教高手)(30分)

  • 主题发起人 主题发起人 jackyxinli
  • 开始时间 开始时间
J

jackyxinli

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么让有从TPersistent继承来的属性的控件随着该属性值的改变而改变?
我的控件中有几个从TPersistent继承来的属性,但我在改变该属性值的时候,控件并未随着改变。
请问如何解决这个问题?
我的代码如下:
unit zzClock;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Clock{include types inherited from TPersistent}, zzLEDStyle;

type
TzzClock = class(TCustomControl)
private
{ Private declarations }
FHourMinute: TzzLEDHourMinute;
FSecond: TzzLEDSecond;
FAmPm: TzzLEDAMPM;
FzzLEDHourMinuteOptions: TzzLEDHourMinuteOptions;{inherited from TPersistent}
FzzLEDSecondOptions: TzzLEDSecondOptions;{inherited from TPersistent}
FzzLEDAMPMOptions: TzzLEDAMPMOptions;{inherited from TPersistent}
procedure SetzzLEDHourMinuteOptions(Value: TzzLEDHourMinuteOptions);
procedure SetzzLEDSecondOptions(Value: TzzLEDSecondOptions);
procedure SetzzLEDAMPMOptions(Value: TzzLEDAMPMOptions);
//FzzLEDOptions: TLEDOptions;
protected
{ Protected declarations }
procedure Paint; override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
{ Published declarations }
property zzLEDHourMinuteOptions: TzzLEDHourMinuteOptions read FzzLEDHourMinuteOptions write SetzzLEDHourMinuteOptions;
property zzLEDAMPMOptions: TzzLEDAMPMOptions read FzzLEDAMPMOptions write SetzzLEDAMPMOptions;
property zzLEDSecondOptions: TzzLEDSecondOptions read FzzLEDSecondOptions write SetzzLEDSecondOptions;
//property zzLEDOptions: TLEDOptions read FzzLEDOptions write FzzLEDOptions;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('ZeroZone', [TzzClock]);
end;

constructor TzzClock.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
{Initialize}
FHourMinute := TzzLEDHourMinute.Create(Self);
FSecond := TzzLEDSecond.Create(Self);
FAmPm := TzzLEDAMPM.Create(Self);

FHourMinute.Parent := Self;
FSecond.Parent := Self;
FAmPm.Parent := Self;

FzzLEDHourMinuteOptions := TzzLEDHourMinuteOptions.Create;
FzzLEDSecondOptions := TzzLEDSecondOptions.Create;
FzzLEDAMPMOptions := TzzLEDAMPMOptions.Create;

FzzLEDHourMinuteOptions.DisplayStyle := dsLED;
FzzLEDHourMinuteOptions.DisplayString := '00:00';
FzzLEDHourMinuteOptions.AutoSize := True;
FzzLEDHourMinuteOptions.Enabled := True;
FzzLEDHourMinuteOptions.Left := 0;
FzzLEDHourMinuteOptions.Top := 0;
FzzLEDHourMinuteOptions.Height := 22;
FzzLEDHourMinuteOptions.Width := 61;

FzzLEDSecondOptions.DisplayStyle := dsLED;
FzzLEDSecondOptions.DisplayString := '00';
FzzLEDSecondOptions.AutoSize := True;
FzzLEDSecondOptions.Enabled := True;
FzzLEDSecondOptions.Left := 62;
FzzLEDSecondOptions.Top := 10;
FzzLEDSecondOptions.Height := 12;
FzzLEDSecondOptions.Width := 15;

FzzLEDAMPMOptions.DisplayStyle := dsLED;
FzzLEDAMPMOptions.DisplayType := dtAM;
FzzLEDAMPMOptions.AutoSize := True;
FzzLEDAMPMOptions.Enabled := True;
FzzLEDAMPMOptions.Left := 62;
FzzLEDAMPMOptions.Top := 0;
FzzLEDAMPMOptions.Height := 12;
FzzLEDAMPMOptions.Width := 15;

FHourMinute.DisplayStyle := FzzLEDHourMinuteOptions.DisplayStyle;
FHourMinute.DisplayString := FzzLEDHourMinuteOptions.DisplayString;
FHourMinute.AutoSize := FzzLEDHourMinuteOptions.AutoSize;
FHourMinute.Enabled := FzzLEDHourMinuteOptions.Enabled;
FHourMinute.Left := FzzLEDHourMinuteOptions.Left;
FHourMinute.Top := FzzLEDHourMinuteOptions.Top;
FHourMinute.Width := FzzLEDHourMinuteOptions.Width;
FHourMinute.Height := FzzLEDHourMinuteOptions.Height;

FSecond.DisplayStyle := FzzLEDSecondOptions.DisplayStyle;
FSecond.DisplayString := FzzLEDSecondOptions.DisplayString;
FSecond.AutoSize := FzzLEDSecondOptions.AutoSize;
FSecond.Enabled := FzzLEDSecondOptions.Enabled;
FSecond.Left := FzzLEDSecondOptions.Left;
FSecond.Top := FzzLEDSecondOptions.Top;
FSecond.Width := FzzLEDSecondOptions.Width;
FSecond.Height := FzzLEDSecondOptions.Height;

FAmPm.DisplayStyle := FzzLEDAMPMOptions.DisplayStyle;
FAmPm.DisplayType := FzzLEDAMPMOptions.DisplayType;
FAmPm.AutoSize := FzzLEDAMPMOptions.AutoSize;
FAmPm.Enabled := FzzLEDAMPMOptions.Enabled;
FAmPm.Left := FzzLEDAMPMOptions.Left;
FAmPm.Top := FzzLEDAMPMOptions.Top;
FAmPm.Width := FzzLEDAMPMOptions.Width;
FAmPm.Height := FzzLEDAMPMOptions.Height;
{End}

Width := 83;
Height := 25;
end;

destructor TzzClock.Destroy;
begin
FHourMinute.Free;
FSecond.Free;
FAmPm.Free;
FzzLEDHourMinuteOptions.Free;
FzzLEDSecondOptions.Free;
FzzLEDAMPMOptions.Free;
inherited Destroy;
end;

procedure TzzClock.Paint;
begin
FHourMinute.DisplayStyle := FzzLEDHourMinuteOptions.DisplayStyle;
FHourMinute.DisplayString := FzzLEDHourMinuteOptions.DisplayString;
FHourMinute.AutoSize := FzzLEDHourMinuteOptions.AutoSize;
FHourMinute.Enabled := FzzLEDHourMinuteOptions.Enabled;
FHourMinute.Left := FzzLEDHourMinuteOptions.Left;
FHourMinute.Top := FzzLEDHourMinuteOptions.Top;
FHourMinute.Width := FzzLEDHourMinuteOptions.Width;
FHourMinute.Height := FzzLEDHourMinuteOptions.Height;

FSecond.DisplayStyle := FzzLEDSecondOptions.DisplayStyle;
FSecond.DisplayString := FzzLEDSecondOptions.DisplayString;
FSecond.AutoSize := FzzLEDSecondOptions.AutoSize;
FSecond.Enabled := FzzLEDSecondOptions.Enabled;
FSecond.Left := FzzLEDSecondOptions.Left;
FSecond.Top := FzzLEDSecondOptions.Top;
FSecond.Width := FzzLEDSecondOptions.Width;
FSecond.Height := FzzLEDSecondOptions.Height;

FAmPm.DisplayStyle := FzzLEDAMPMOptions.DisplayStyle;
FAmPm.DisplayType := FzzLEDAMPMOptions.DisplayType;
FAmPm.AutoSize := FzzLEDAMPMOptions.AutoSize;
FAmPm.Enabled := FzzLEDAMPMOptions.Enabled;
FAmPm.Left := FzzLEDAMPMOptions.Left;
FAmPm.Top := FzzLEDAMPMOptions.Top;
FAmPm.Width := FzzLEDAMPMOptions.Width;
FAmPm.Height := FzzLEDAMPMOptions.Height;

FHourMinute.Repaint;
FSecond.Repaint;
FAmPm.Repaint;
Canvas.Brush.Color := clBlack;
Canvas.FillRect(Rect(0,0,Width,Height));
end;

procedure TzzClock.SetzzLEDHourMinuteOptions(Value: TzzLEDHourMinuteOptions);
begin
FzzLEDHourMinuteOptions := Value;
RePaint;
end;

procedure TzzClock.SetzzLEDSecondOptions(Value: TzzLEDSecondOptions);
begin
FzzLEDSecondOptions := Value;
RePaint;
end;

procedure TzzClock.SetzzLEDAMPMOptions(Value: TzzLEDAMPMOptions);
begin
FzzLEDAMPMOptions := Value;
RePaint;
end;
end.
 

Similar threads

I
回复
0
查看
539
import
I
I
回复
0
查看
502
import
I
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
后退
顶部