Delphi 2007のTCustomComboBoxに基づいてカスタムコントロールを作成しようとしていますが、最初のハードルに悩まされています。DelphiでTCustomComboBoxの子孫を作成する
私はDrawItemをオーバーライドする必要があるように見えますが、動作していないように、stdctrls.pasのTCustomComboBoxのソースを見て、表示されているテキストを最初に表示します。オーバーライドされたメソッド内のコードは決して実行されません。
私はいくつかのオープンソースコンポーネントのソースコードを見て、どのようにしているかを見てきましたが、まだ迷っています。ここで
は、私がこれまでに(あまり明らかに)持っているものである
type
TKeyValueComboBox = class(TCustomComboBox)
private
{ Private declarations }
//FColumns:Integer;
protected
{ Protected declarations }
procedure DrawItem(Index: Integer; Rect: TRect; State: TOwnerDrawState);override;
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
published
end;
そして
procedure TKeyValueComboBox.DrawItem(Index: Integer; Rect: TRect;
State: TOwnerDrawState);
begin
TControlCanvas(Canvas).UpdateTextFlags;
if Assigned(OnDrawItem) then OnDrawItem(Self, Index, Rect, State)
else
begin
Canvas.FillRect(Rect);
Canvas.TextOut(Rect.Left + 2, Rect.Top, Items[Index]+'-HELLO');
end;
end;
誰もが、私は火の私のオーバーライドされたバージョンを取得するために使用するために必要なものの方法を知っていますか?または私が間違っていることは何ですか?
ご協力いただければ幸いです。