|
代码如下,编译通不过,提示类型不匹配: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] |
|