rttiinspectordemopropeditors.pas

来自「delphi的的三方控件」· PAS 代码 · 共 94 行

PAS
94
字号
unit RTTIInspectorDemoPropEditors;

interface

uses cxOI, cxEdit, ImgList, cxImageComboBox, Controls;

type
  TcxImageIndexProperty = class(TcxIntegerProperty)
  public
    procedure AdjustInnerEditProperties(AProperties: TcxCustomEditProperties); override;
    function GetImages: TImageList; virtual;
    function GetAttributes: TcxPropertyAttributes; override;
    procedure SetValue(const Value: string); override;
  end;

implementation

uses SysUtils, cxVGrid;

resourcestring
  sNoImage = 'no image';

{ TcxImageIndexProperty }

function TcxImageIndexProperty.GetAttributes: TcxPropertyAttributes;
begin
  Result := [ipaMultiSelect, ipaAutoUpdate];
end;

procedure TcxImageIndexProperty.AdjustInnerEditProperties(
  AProperties: TcxCustomEditProperties);
var
  i: Integer;
  AComboBoxItem: TcxImageComboBoxItem;
  AImageComboBoxProperties: TcxImageComboBoxProperties;
  AImages: TImageList;
  procedure AssignImages;
  begin
    if AImages.Height = 16 then
      AImageComboBoxProperties.Images := AImages
    else
      AImageComboBoxProperties.LargeImages := AImages
  end;

  function GetImageList: TCustomImageList;
  begin
    if AImageComboBoxProperties.Images <> nil then
      Result := AImageComboBoxProperties.Images
    else
      Result := AImageComboBoxProperties.LargeImages;
  end;

begin
  AImageComboBoxProperties := AProperties as TcxImageComboBoxProperties;
  AImages := GetImages;
  if AImages <> nil then
  begin
    AssignImages;
    AImageComboBoxProperties.Items.Clear;
    for i:=0 to GetImageList.Count - 1 do
    begin
      AComboBoxItem := AImageComboBoxProperties.Items.Add as TcxImageComboBoxItem;
      AComboBoxItem.ImageIndex := i;
      AComboBoxItem.Value := i;
      AComboBoxItem.Description := IntToStr(i);
    end;
  end;
  AComboBoxItem := AImageComboBoxProperties.Items.Add as TcxImageComboBoxItem;
  AComboBoxItem.ImageIndex := -1;
  AComboBoxItem.Value := Integer(-1);
  AComboBoxItem.Description := sNoImage;
  AImageComboBoxProperties.OnEditValueChanged := nil;
end;

procedure TcxImageIndexProperty.SetValue(const Value: string);
begin
  if Value = sNoImage then
    SetOrdValue(-1)
  else inherited SetValue(Value);
end;

function TcxImageIndexProperty.GetImages: TImageList;
begin
  Result := nil;
  if GetComponent(0) is TcxCustomEditorRowProperties then
     Result := TcxEditorRowProperties(GetComponent(0)).Row.VerticalGrid.Images;
end;

initialization
  cxRegisterPropertyEditor(TypeInfo(TImageIndex), TcxCustomEditorRowProperties, 'ImageIndex', TcxImageIndexProperty);
  cxRegisterEditPropertiesClass(TcxImageIndexProperty, TcxImageComboBoxProperties);

end.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?