Редактор свойства, пример которого приведен ниже, имеет ограничение на
устанавливаемые цвета: только clRed, clWhite или clBlue.
unit ClrComps;
interfaceuses
SysUtils, WinTypes, WinProcs, Messages, Classes,
Graphics, Controls, Forms, Dialogs, DsgnIntf;
type
TColorComponent = class(TComponent)
private
FColor: TColor;
protectedprocedure SetColor(Value: TColor);
publicconstructor Create(AnOwner: TComponent); override;
publishedproperty Color: TColor read FColor write SetColor;
end;
{ Это специальный редактор свойства выбора цветов... }
TMyColorProperty = class(TIntegerProperty)
publicfunction GetAttributes: TPropertyAttributes; override;
function GetValue: string; override;
procedure GetValues(Proc: TGetStrProc); override;
procedure SetValue(const Value: string); override;
end;
procedureRegister;
implementation{ TMyColorProperty }function TMyColorProperty.GetAttributes: TPropertyAttributes;
begin
Result := [paMultiSelect, paValueList];
end;
function TMyColorProperty.GetValue: string;
begin
Result := ColorToString(TColor(GetOrdValue));
end;
procedure TMyColorProperty.GetValues(Proc: TGetStrProc);
begin
Proc('clRed');
Proc('clWhite');
Proc('clBlue');
end;
procedure TMyColorProperty.SetValue(const Value: string);
var
NewValue: Longint;
beginif IdentToColor(Value, NewValue) and
((NewValue = clRed) or
(NewValue = clWhite) or
(NewValue = clBlue)) then
SetOrdValue(NewValue);
end;
{ Образец компонента... }constructor TColorComponent.Create(AnOwner: TComponent);
begininherited Create(AnOwner);
FColor := clRed;
end;
procedure TColorComponent.SetColor(Value: TColor);
beginif (Value = clRed) or
(Value = clWhite) or
(Value = clBlue) thenbegin
FColor := Value;
end;
end;
procedureRegister;
begin
RegisterComponents('Samples', [TColorComponent]);
RegisterPropertyEditor(TypeInfo(TColor), TColorComponent,
'Color', TMyColorProperty);
end;
end.
Статья Редактор свойства Color с заданными ограничениями раздела Компоненты и Классы Свойства и События может быть полезна для разработчиков на Delphi и FreePascal.
Комментарии и вопросы
Материалы статей собраны из открытых источников, владелец сайта не претендует на авторство. Там где авторство установить не удалось, материал подаётся без имени автора. В случае если Вы считаете, что Ваши права нарушены, пожалуйста, свяжитесь с владельцем сайта.