unit ClrComps; interface usesSysUtils, WinTypes, WinProcs, Messages, Classes,Graphics,Controls, Forms, Dialogs, DsgnIntf; typeTColorComponent = class( TComponent )privateFColor: 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; procedure Register; implementation { TMyColorProperty } function TMyColorProperty.GetAttributes: TPropertyAttributes;beginResult := [ paMultiSelect, paValueList ];end; function TMyColorProperty.GetValue: string;beginResult := ColorToString( TColor( GetOrdValue ));end; procedure TMyColorProperty.GetValues( Proc: TGetStrProc );beginProc( 'clRed' );Proc( 'clWhite' );Proc( 'clBlue' );end; procedure TMyColorProperty.SetValue( const Value: string );varNewValue: Longint;beginif IdentToColor( Value, NewValue ) and(( NewValue = clRed ) or( NewValue = clWhite ) or( NewValue = clBlue )) thenSetOrdValue( 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 ) thenbeginFColor := Value;end;end; procedure Register;beginRegisterComponents( 'Samples', [ TColorComponent ]);RegisterPropertyEditor( TypeInfo( TColor ), TColorComponent,'Color', TMyColorProperty );end; end. |
- Ed Jordan [000995]