起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 188|回复: 3

【搞定】AddObject调用问题**

[复制链接]
发表于 2007-3-13 15:50:01 | 显示全部楼层 |阅读模式
代码如下,编译通不过,提示类型不匹配:Incompatible types: "TObject" and "TGridEvent"

unit KBBD1;

interface

uses
  Business.System, Business.Model, Business.Forms, Business.Data;

type
  TKBBD1 = class(TFormDoc)
    Edit1: TEdit;
    DataLabel1: TDataLabel;
    procedure FormDocCreate(Sender: TObject);
    procedure FormDocDestroy(Sender: TObject);
  private
    {private declarations}
    FGridCustomDrawColumnHeader: TStrings;
    procedure MyDataGridCustomDrawColumnHeader(Sender: TObject; AColumn: TTreeListColumn; ACanvas: TCanvas;
      ARect: TRect; var AText: string;var AColor: Integer; AFont: TFont; var AAlignment: TAlignment;
      var ASorted: TTreeListColumnSort; var ADone: Boolean);
  public
    {public declarations}
  end;

  TGridEvent = class(Object)
  public
    GridName: String;
    GridCustomDrawHeader: TTLCustomDrawHeader;
    constructor Create;
    destructor Destroy; override;
  end;

implementation

constructor TGridEvent.Create;
begin
  inherited;
end;

destructor TGridEvent.Destroy;
begin
  inherited;
end;

procedure TKBBD1.FormDocCreate(Sender: TObject);
var
  i: integer;
  dgGrid: TDataGrid;
  AGridEvent: TGridEvent;
  ALabel: TDataLabel;
begin
  FGridCustomDrawColumnHeader := TStringList.Create;
  for i := 0 to ComponentCount - 1 do
  begin
    if (Components is TDataLabel) then //标签
    begin
      ALabel := TDataLabel(Components);
      if (ALabel.DataSource <> nil) and (ALabel.DataSource.DataSet <> nil) then //判断是否挂数据集
      if TDataLabel(Components).DataSource.DataSet is TBizDataSet then
        if (TBizDataSet(TDataLabel(Components).DataSource.DataSet).BizFieldByName(TDataLabel(Components).DataField) is TBizField) then
          if TBizDataSet(TDataLabel(Components).DataSource.DataSet).BizFieldByName(TDataLabel(Components).DataField).IsRequired then
          begin
            (TDataLabel(Components)).Font.Color := Business.System.Graphics.clRed;
          end;
    end else if (Components is TDataGrid) then  //网格
    begin
      dgGrid := TDataGrid(Components);
      if (dgGrid.DataSource <> nil) and (dgGrid.DataSource.DataSet <> nil) then
      begin
        if Assigned(dgGrid.OnCustomDrawColumnHeader) then
        begin
          AGridEvent := TGridEvent.Create;
          AGridEvent.GridName := dgGrid.Name;
          AGridEvent.GridCustomDrawHeader := dgGrid.OnCustomDrawColumnHeader;
          FGridCustomDrawColumnHeader.AddObject(dgGrid.Name, AGridEvent);  //这里编译通不过
        end;
        dgGrid.OnCustomDrawColumnHeader := MyDataGridCustomDrawColumnHeader;
      end;
    end;
  end;
end;

procedure TKBBD1.MyDataGridCustomDrawColumnHeader(Sender: TObject; AColumn: TTreeListColumn; ACanvas: TCanvas;
      ARect: TRect; var AText: string;var AColor: Integer; AFont: TFont; var AAlignment: TAlignment;
      var ASorted: TTreeListColumnSort; var ADone: Boolean);
var
  iIndex: Integer;
begin
  if TBizDataSet((Sender as TDataGrid).DataSource.DataSet).BizFieldByName(TDataGridColumn(AColumn).FieldName).IsRequired then
  begin
    AFont.Color := Business.System.Graphics.clRed;
  end;
  iIndex := FGridCustomDrawColumnHeader.IndexOf((Sender as TDataGrid).Name);
  if iIndex <> -1 then
    TGridEvent(FGridCustomDrawColumnHeader.Objects[iIndex]).GridCustomDrawHeader(Sender,AColumn,ACanvas,ARect,AText,AColor,AFont,AAlignment,ASorted,ADone);
end;

procedure TKBBD1.FormDocDestroy(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to FGridCustomDrawColumnHeader.Count - 1 do
    if FGridCustomDrawColumnHeader.Objects <> nil then
      FGridCustomDrawColumnHeader.Objects.Free;
end;

end.


[B]FGridCustomDrawColumnHeader.AddObject(dgGrid.Name, AGridEvent);  //这里编译通不过[/B]
回复

使用道具 举报

 楼主| 发表于 2007-3-13 16:24:35 | 显示全部楼层
自己顶
回复 支持 反对

使用道具 举报

发表于 2007-3-13 16:46:24 | 显示全部楼层
TGridEvent = class(TObject)
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-3-13 17:19:19 | 显示全部楼层
晕,不好意思哈。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2024-12-26 21:42 , Processed in 0.040857 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表