Everything works ok - i just don't get the drop down list with the images
e.g. the property editor.
What do i have to do to get the correct property editor?
Sincerely,
Frank Roloff
Hi, Frank
Depends from what Delphi version are you using. In case it's a D5, you could
use one of the standard TImageIndex property editors. Below is an example of
the TComponentImageIndexPropertyEditor class descendant, it's suitable for
all components, which TImageList property has a "ImageIndex" name.
________________________________
TMyImageIndexEditor = class(TComponentImageIndexPropertyEditor)
protected
function GetImageListAt(AIndex: integer): TCustomImageList; override;
end;
{..}
function TMyImageIndexEditor.GetImageListAt(AIndex: integer):
TCustomImageList;
begin
Result:=TImageList(TypInfo.GetObjectProp(GetComponent(AIndex),
'ImageList'));
end;
register it in this way
RegisterPropertyEditor(TypeInfo(TImageIndex), TMyComponent,
'', TMyImageIndexEditor);
________________________________
In order to compile it you need to add the dclstd50.dcp the requires clause
of your package and Stdreg unit to the uses section of the unit with
editor's class (I guess you also will need to have there dsgnintf and
TypInfo units)
In case you're dealing with D6, you'll forced to write the TImageIndex
proeprty editor from the beginning on your own, as none of the
TXXXImageIndexPropertyEditor classes no longer exported (AFAIK). Below is an
example of the such editor.
________________________________
TCustomImageEditor = class(TIntegerProperty,
ICustomPropertyDrawing,
ICustomPropertyListDrawing)
protected
function GetImageList: TImageList; virtual;
public
function GetAttributes: TPropertyAttributes; override;
procedure GetValues(Proc: TGetStrProc); override;
function GetValue: string; override;
procedure SetValue(const Value: string); override;
procedure ListMeasureWidth(const Value: string;
ACanvas: TCanvas; var AWidth: Integer); virtual;
procedure ListMeasureHeight(const Value: string;
ACanvas: TCanvas; var AHeight: Integer); virtual;
procedure ListDrawValue(const Value: string;
ACanvas: TCanvas; const ARect: TRect; ASelected: Boolean);
virtual;
procedure PropDrawName(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean);
procedure PropDrawValue(ACanvas: TCanvas; const ARect: TRect;
ASelected: Boolean);
end;
{...}
function TCustomImageEditor.GetImageList: TImageList;
begin
Result:=TImageList(TypInfo.GetObjectProp(GetComponent(0), 'ImageList'));
end;
function TCustomImageEditor.GetAttributes: TPropertyAttributes;
begin
Result:=[paValueList, paRevertable];
end;
function TCustomImageEditor.GetValue: string;
begin
Result:=intToStr(GetOrdValue);
end;
procedure TCustomImageEditor.SetValue(const Value: string);
var
XValue: integer;
begin
try
XValue:=strToInt(Value);
SetOrdValue(XValue);
except
inherited SetValue(Value);
end;
end;
procedure TCustomImageEditor.GetValues(Proc: TGetStrProc);
var
XImageList: TImageList;
i: integer;
begin
XImageList:=GetImageList;
if Assigned(XImageList)
then for i:=0 to XImageList.Count-1 do Proc(intToStr(i));
end;
procedure TCustomImageEditor.ListMeasureWidth(const Value: string; ACanvas:
TCanvas;
var AWidth: Integer);
begin
AWidth:=AWidth+ACanvas.TextHeight('M');
if AWidth<17 then AWidth:=17;
end;
procedure TCustomImageEditor.ListMeasureHeight(const Value: string; ACanvas:
TCanvas;
var AHeight: Integer);
var
XImageList: TImageList;
begin
XImageList:=GetImageList;
if Assigned(XImageList)
then AHeight:=XImageList.Height+2
else AHeight:=20;
if AHeight<17 then AHeight:=17;
end;
procedure TCustomImageEditor.ListDrawValue(const Value: string; ACanvas:
TCanvas;
const ARect: TRect; ASelected:
Boolean);
var
XImageList: TImageList;
XRight: Integer;
XOldPenColor, XOldBrushColor: TColor;
begin
XImageList:=GetImageList;
XRight:=0;
try
if Assigned(XImageList) then begin
XRight:=(ARect.Bottom-ARect.Top)+ARect.Left;
XOldPenColor:=ACanvas.Pen.Color;
XOldBrushColor:=ACanvas.Brush.Color;
ACanvas.Pen.Color:=ACanvas.Brush.Color;
ACanvas.Rectangle(ARect.Left, ARect.Top, XRight, ARect.Bottom);
XImageList.DrawOverlay(ACanvas, ARect.Left+1, ARect.Top,
strToInt(Value), 0);
ACanvas.Brush.Color:=XOldBrushColor;
ACanvas.Pen.Color:=XOldPenColor;
end;
finally
DefaultPropertyListDrawValue(Value, ACanvas,
Rect(XRight, ARect.Top, ARect.Right,
ARect.Bottom),
ASelected);
end;
end;
procedure TCustomImageEditor.PropDrawName(ACanvas: TCanvas; const ARect:
TRect;
ASelected: Boolean);
begin
DefaultPropertyDrawName(Self, ACanvas, ARect);
end;
procedure TCustomImageEditor.PropDrawValue(ACanvas: TCanvas; const ARect:
TRect;
ASelected: Boolean);
var
XImageList: TImageList;
begin
XImageList:=GetImageList;
if (GetVisualValue<>'') and
Assigned(XImageList) and (XImageList.Height<17)
then ListDrawValue(GetVisualValue, ACanvas, ARect, True{ASelected})
else DefaultPropertyDrawValue(Self, ACanvas, ARect);
end;
register it in this way
RegisterPropertyEditor(TypeInfo(TImageIndex), TMyComponent,
'', TCustomImageEditor);
__________________________________________
This editor will work for all components, which have a TImageList property
with "ImageList" name, for other cases you'll need to override the
GetImageList method and point to the your imagelist.
Best regards, Serge Gubenko
Thx,
Frank
"serge gubenko" <serge_...@yahoo.com> schrieb im Newsbeitrag
news:3c619247_1@dnews...