Delphi 重写控件的一个例子。

时间:2023-03-09 15:19:03
Delphi  重写控件的一个例子。
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.