张志峰的博客

水滴石川,积少成多。

导航

Delphi 重写控件的一个例子。

Posted on 2013-08-21 21:05  ╰★张志峰★╮  阅读(1175)  评论(0)    收藏  举报
unit DBGridEx;
 
interface
 
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  Grids, DBGrids;
 
type
  TMyInplaceEdit = class(TInplaceEdit)
  published
    property Color;
  end;
 
  TMyDBGrid = class(TDBGrid)
  protected
    function CreateEditor: TInplaceEdit; override;
  end;
 
procedure Register;
 
implementation
 
procedure Register;
begin
  RegisterComponents('Standard', [TMyDBGrid]);
end;
 
function TMyDBGrid.CreateEditor: TInplaceEdit;
var
   aEdit: TMyInplaceEdit;
begin
  aEdit := TMyInplaceEdit.Create(Self);
  aEdit.Color := clGreen;  //单元格设置成绿色
  Result := aEdit;
end;
 
end.