TComboBox的派生类中,如果希望对下拉框的列表显示的内容进行加工,覆盖了继承来这个方法没有效果,应该怎样做?
unit bsComboBox;
interface
uses
// SysUtils, Classes, Controls, StdCtrls;
Messages, {$IFDEF LINUX} WinUtils, {$ENDIF} Windows, SysUtils, Classes,
Controls, Forms, Menus, Graphics,StdCtrls;
type
TbsComboBox = class(TComboBox)
private
FRefName: string;
{ Private declarations }
protected
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState); overload; override;
{ Protected declarations }
public
{ Public declarations }
published
property RefName: string read FRefName write FRefName;
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Standard', [TbsComboBox]);
end;
procedure TbsComboBox.DrawItem(Index: Integer; Rect: TRect; State:
TOwnerDrawState);
var S: String;
begin
TControlCanvas(Canvas).UpdateTextFlags;
if Assigned(OnDrawItem) then OnDrawItem(Self, Index, Rect, State)
else
begin
Canvas.FillRect(Rect);
S := Copy(Items[Index],1 ,AnsiPos(Items[Index],'=') -1);
if Index >= 0 then
Canvas.TextOut(Rect.Left + 2, Rect.Top, Copy(Items[Index],1 ,AnsiPos('=',Items[Index]) -1));
end;
end;
end.