unit MyGrid;
interface
uses
ADODB, DB, Math, Graphics, Types, Windows, DBGridEh,
SysUtils, Classes, Controls, Grids, DBGrids;
type
TMyGrid = class(TCustomDBGridEH)
private
{ Private declarations }
FDataSet: TADOQuery;
FDataSource: TDataSource;
function GetConStr: WideString;
procedure SetConStr(const Value: WideString);
function GetSQL: WideString;
procedure SetSQL(const Value: WideString);
function GetColCount: Integer;
procedure SetColCount(const Value: Integer);
function GetActive: Boolean;
procedure SetActive(const Value: Boolean);
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent)
override;
destructor Destroy
override;
procedure ExecQuery()
overload;
procedure ExecQuery(const SQL: string)
overload;
procedure SetColumn(Col: Integer
Caption, FieldName: string);
published
{ Published declarations }
property Active :Boolean read GetActive write SetActive;
property SQL: WideString read GetSQL write SetSQL;
property ConnectionString: WideString read GetConStr write SetConStr;
property ColumnCount: Integer read GetColCount write SetColCount;
property Align;
property Anchors;
property BiDiMode;
property BorderStyle;
property Color;
property Columns stored False
//StoreColumns;
property Constraints;
property Ctl3D;
property DefaultDrawing;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property FixedColor;
property Font;
property ImeMode;
property ImeName;
property Options;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
property ShowHint;
property TabOrder;
property TabStop;
property TitleFont;
property Visible;
property OnCellClick;
property OnColEnter;
property OnColExit;
property OnColumnMoved;
property OnDrawDataCell
{ obsolete }
property OnDrawColumnCell;
property OnDblClick;
property OnDragDrop;
property OnDragOver;
property OnEditButtonClick;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
property OnTitleClick;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('WRCtrl', [TMyGrid]);
end;
{ TMyGrid }
constructor TMyGrid.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FDataSet := TADOQuery.Create(Self);
FDataSource := TDataSource.Create(Self);
FDataSource.DataSet := FDataSet;
DataSource := FDataSource;
UseMultiTitle := True;
end;
destructor TMyGrid.Destroy;
begin
FDataSet.Free;
FDataSource.Free;
inherited Destroy;
end;
procedure TMyGrid.ExecQuery;
begin
try
FDataSet.Active := True;
finally
end;
end;
procedure TMyGrid.ExecQuery(const SQL: string);
begin
Self.SQL := SQL;
ExecQuery;
end;
function TMyGrid.GetActive: Boolean;
begin
Result:=FDataSet.Active;
end;
function TMyGrid.GetColCount: Integer;
begin
Result := Columns.Count;
end;
function TMyGrid.GetConStr: WideString;
begin
Result := FDataSet.ConnectionString;
end;
function TMyGrid.GetSQL: WideString;
begin
Result := FDataSet.SQL.Text;
end;
procedure TMyGrid.SetActive(const Value: Boolean);
begin
try
FDataSet.Active :=Value;
finally
end;
end;
procedure TMyGrid.SetColCount(const Value: Integer);
var
I : Integer;
begin
Columns.Clear;
for i := 0 to Value - 1 do
Columns.Create(Self, TColumnEh);
end;
procedure TMyGrid.SetColumn(Col: Integer
Caption, FieldName: string);
begin
if Col > Columns.Count - 1 then
Exit;
Columns[Col].FieldName := FieldName;
Columns[Col].Title.Caption := Caption;
end;
procedure TMyGrid.SetConStr(const Value: WideString);
begin
if FDataSet.ConnectionString <> Value then
FDataSet.ConnectionString := Value;
end;
procedure TMyGrid.SetSQL(const Value: WideString);
begin
FDataSet.Close;
FDataSet.SQL.Text := Value;
end;
end.
先安装DBGridEH,生成此控件,然后新建ActiveX Control继承它。
Columns是没有了,只有手动设置了