PieReg.pas
上传用户:psxgmh
上传日期:2013-04-08
资源大小:15112k
文件大小:4k
- unit PieReg;
- interface
- uses Windows, Classes, Graphics, Forms, Controls, Pies, Buttons, DesignIntf,
- DesignWindows, StdCtrls, ComCtrls, DesignEditors;
- type
- //属性、组件的编辑窗体
- TAngleEditorDlg = class(TForm)
- EAngleLabel: TLabel;
- OKButton: TButton;
- CancelButton: TButton;
- SAngleLabel: TLabel;
- STrackBar: TTrackBar;
- ETrackBar: TTrackBar;
- procedure CancelClick(Sender: TObject);
- procedure STrackBarChange(Sender: TObject);
- procedure ETrackBarChange(Sender: TObject);
- private
- FOrigStart, FOrigEnd: Integer;//记录原始角度
- FAngles: TAngles;
- procedure SetStartAngle(Value: Integer);
- procedure SetEndAngle(Value: Integer);
- procedure SetAngles(Value: TAngles);
- public
- property EditorAngles: TAngles read FAngles write SetAngles;
- end;
- //Angle属性编辑类
- TAnglesProperty = class(TClassProperty)
- public
- procedure Edit; override;
- function GetAttributes: TPropertyAttributes; override;
- end;
- //组件编辑类
- TPieEditor = class(TDefaultEditor)
- protected
- procedure EditProperty(const PropertyEditor: IProperty;
- var Continue: Boolean); override;
- public
- procedure ExecuteVerb(Index: Integer); override;
- function GetVerb(Index: Integer): string; override;
- function GetVerbCount: Integer; override;
- end;
- procedure Register;
- implementation
- uses SysUtils;
- {$R *.dfm}
- { TAngleEditorDlg }
- //===========属性对话框实现==================//
- //设置开始角度
- procedure TAngleEditorDlg.SetStartAngle(Value: Integer);
- begin
- STrackBar.Position := Value;
- SAngleLabel.Caption := 'StartAngle = '+ IntToStr(Value);
- FAngles.StartAngle := Value;
- end;
- //设置结束角度
- procedure TAngleEditorDlg.SetEndAngle(Value: Integer);
- begin
- ETrackBar.Position := Value;
- EAngleLabel.Caption := 'EndAngle = '+ IntToStr(Value);
- FAngles.EndAngle := Value;
- end;
- //当开始角度变化时,调用SetStartAngle方法来设置FAngles
- procedure TAngleEditorDlg.STrackBarChange(Sender: TObject);
- begin
- SetStartAngle(STrackBar.Position);
- end;
- //当结束角度变化时,调用SetStartAngle方法来设置FAngles
- procedure TAngleEditorDlg.ETrackBarChange(Sender: TObject);
- begin
- SetEndAngle(ETrackBar.Position);
- end;
- //设置角度,
- procedure TAngleEditorDlg.SetAngles(Value: TAngles);
- begin
- FAngles := Value;
- //将原有角度存起来,以便恢复
- FOrigStart := Value.StartAngle;
- FOrigEnd := Value.EndAngle;
- //设置开始、结束角度
- SetStartAngle(Value.StartAngle);
- SetEndAngle(Value.EndAngle);
- end;
- //取消时,恢复原先角度
- procedure TAngleEditorDlg.CancelClick(Sender: TObject);
- begin
- SetStartAngle(FOrigStart);
- SetEndAngle(FOrigEnd);
- end;
- //========属性编辑类实现============//
- procedure TAnglesProperty.Edit;
- var
- Angles: TAngles;
- AngleEditor: TAngleEditorDlg;
- begin
- //得到馅饼的原始角度
- Angles := TAngles(GetOrdValue);
- //打开属性编辑窗口
- AngleEditor := TAngleEditorDlg.Create(Application);
- try
- //将原始角度赋给窗体的EditorAngles属性
- AngleEditor.EditorAngles := Angles;
- AngleEditor.ShowModal;
- finally
- AngleEditor.Free;
- end;
- end;
- function TAnglesProperty.GetAttributes: TPropertyAttributes;
- begin
- Result := [paDialog, paSubProperties];
- end;
- //============组件编辑类的实现=============//
- procedure TPieEditor.EditProperty(const PropertyEditor: IProperty;
- var Continue: Boolean);
- var
- PropName: string;
- begin
- PropName := PropertyEditor.GetName;
- if (CompareText(PropName, 'ANGLES') = 0) then
- begin
- PropertyEditor.Edit;
- Continue := False;
- end;
- end;
- //检索组件的快捷菜单上有几个命令
- function TPieEditor.GetVerbCount: Integer;
- begin
- Result := 1;
- end;
- //根据I n d e x整型参数返回字符串形式的菜单项文本
- function TPieEditor.GetVerb(Index: Integer): string;
- begin
- if Index = 0 then
- Result := 'Edit Angles'
- else Result := '';
- end;
- procedure TPieEditor.ExecuteVerb(Index: Integer);
- begin
- if Index = 0 then Edit;
- end;
- //组件注册、属性编辑器注册、组件编辑器注册
- procedure Register;
- begin
- RegisterComponents('Samples',[TPie]);
- RegisterComponentEditor(TPie, TPieEditor);
- RegisterPropertyEditor(TypeInfo(TAngles), nil, '', TAnglesProperty);
- end;
- end.