朋友请详细,有小实例发到我的邮箱里:delphi2005@163.com
我的小实例
1.1、在DLL里过程声明:
[red] procedure DLLDrawColumnCell(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumnEh;
State: TGridDrawState);
Stdcall;[/red]
1.2、在DLL里过程实际业务处理:
[blue]procedure DLLDrawColumnCell(Sender: TObject;const Rect: TRect;
DataCol: Integer;
Column: TColumnEh;
State: TGridDrawState);
begin
if (Sender as TDBGridEh).DataSource.DataSet.RecNo mod 2 = 0 then
(Sender as TDBGridEh).Canvas.Brush.Color := $00FFF7EE;
(Sender as TDBGridEh).Canvas.Font.Color := clWindowText;
if gdSelected in State then
(Sender as TDBGridEh).Canvas.Brush.Color:=clYellow;
(Sender as TDBGridEh).DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
[/blue]
1.3、在DLL里输出Exports
DLLDrawColumnCell;
2.1、在EXE主程序中声明:
type
[red] TDLLDrawColumnCell = procedure(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumnEh;
State: TGridDrawState);
Stdcall;[/red]
2.2、在DBGridEh1添加事件:
[blue]procedure TForm1.DBGridEh1DrawColumnCell(Sender: TObject;
const Rect: TRect;
DataCol: Integer;
Column: TColumnEh;
State: TGridDrawState);
var
LibHandle: THandle;
DLLDrawColumnCell: TDLLDrawColumnCell;
begin
LibHandle := LoadLibrary('../PubLib.dll');
if LibHandle = HINSTANCE_ERROR then
raise EDLLLoadError.Create('Unable to Load DLL');
@DLLDrawColumnCell := GetProcAddress(LibHandle, 'DLLDrawColumnCell');
if not (@DLLDrawColumnCell = nil) then
DLLDrawColumnCell(Sender,Rect,DataCol,Column,State);
end;
[/blue]当程序运行后出错,到底是哪里出现问题???