高手指点(10分)

  • 主题发起人 主题发起人 shhw
  • 开始时间 开始时间
S

shhw

Unregistered / Unconfirmed
GUEST, unregistred user!
我封装了一个DBGrid到Dll里,执行完毕时没有错误
但是关闭调用Dll的窗体时出现下面的错误:‘Invalid Point Operation’
请问怎么解决??高分相送
下面是代码:
1、调用代码
unit U_GridOut;

interface
uses ShareMem,db,dbGrids;
const FDllName='GridExport.dll';
{------------------------------设置Grid最佳列宽------------------------------}
//最佳列宽
//Procedure SetTheBestColWidth_Eh(Ahand:THandle;ADBGridEH:TdbgridEh;Exact:boolean=true);stdcall;external FDllName;
Procedure SetTheBestColWidth_DB(Ahand:THandle;DBGrid:Tdbgrid);stdcall;external FDllName;


2、dll代码
library GridExport;

uses
ShareMem,SysUtils,
forms,
DBGridEh,
dbGrids,db;

{$R *.res}
Procedure SetTheBestColWidth_DB(Ahand:THandle;aDBGrid:Tdbgrid);stdcall;
var i:integer;
MaxWidth:integer;
OrigRecNo:integer;
Exact :boolean;
s:string;
begin
Application.Handle := Ahand ;
Exact := true;
if (ADBGrid = nil) or (ADBGrid.DataSource = nil)
or (ADBGrid.DataSource.DataSet = nil) or (not ADBGrid.DataSource.DataSet.Active) then
Exit;
ADBGrid.DataSource.DataSet.DisableControls;
OrigRecNo:=ADBGrid.DataSource.DataSet.RecNo;
for i:=0 to ADBGrid.Columns.Count-1 do
begin
if not ADBGrid.Columns.Visible then continue;
MaxWidth:=ADBGrid.Canvas.TextWidth(ADBGrid.Columns.title.Caption);
ADBGrid.DataSource.DataSet.First;
while not ADBGrid.DataSource.DataSet.Eof do
begin
s:=ADBGrid.DataSource.DataSet.fieldbyname(ADBGrid.Columns.FieldName).asstring;
if (ADBGrid.DataSource.DataSet.fieldbyname(ADBGrid.Columns.FieldName).DataType in [ftBCD,ftCurrency,ftFloat]) and
Exact then
begin
if ADBGrid.Canvas.TextWidth(s+'.0000')>MaxWidth then
MaxWidth:=ADBGrid.Canvas.TextWidth(s+'.0000');
end
else
begin
if ADBGrid.Canvas.TextWidth(s)>MaxWidth then
MaxWidth:=ADBGrid.Canvas.TextWidth(s);
end;
ADBGrid.DataSource.DataSet.Next;
end;
ADBGrid.Columns.Width:=MaxWidth+10
end;
if OrigRecNo > -1 then
ADBGrid.DataSource.DataSet.RecNo:=OrigRecNo;
ADBGrid.DataSource.DataSet.EnableControls;
end;
 
这么没有高手相应啊
 
释放Dll之前,恢复设置Dll的Application.Handle为原来的值
 
后退
顶部