全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:4069
推到 Plurk!
推到 Facebook!

XE7 DLL中封装DbGrid报错

尚未結案
wuhs
一般會員


發表:1
回覆:6
積分:1
註冊:2015-09-24

發送簡訊給我
#1 引用回覆 回覆 發表時間:2015-09-24 22:31:21 IP:61.141.xxx.xxx 訂閱
一个简单的DLL专案,里面有一个VCL Form,Form上放一个DBGrid,或DbGridEh,在IDE环境下运行报错,如图:



这是DLL窗体单元的引用:

uses

Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,

Vcl.Graphics,Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.DBGrids;

这是DLL工程单元的引用

uses

sharemem,

Vcl.Forms,

System.SysUtils,

System.Classes,

Unit2 in 'Unit2.pas' {Form2};

这是exe工程单元的引用

uses

sharemem,

Vcl.Forms,

Unit1 in 'Unit1.pas' {Form1},

应该没有什么问题的。D7下也是这么干的。

在IDE环境下,可以编译,不报错,但运行就报一楼的错。

编译好了运行,程序退出时报错如下图:





各位先进,有招吗?
------
wuhs
編輯記錄
wuhs 重新編輯於 2015-09-26 12:17:20, 註解 無‧
wuhs
一般會員


發表:1
回覆:6
積分:1
註冊:2015-09-24

發送簡訊給我
#2 引用回覆 回覆 發表時間:2015-09-26 16:00:57 IP:61.141.xxx.xxx 訂閱
李维,李大师在吗?帮帮忙啦!
------
wuhs
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#3 引用回覆 回覆 發表時間:2015-10-16 08:04:59 IP:61.224.xxx.xxx 未訂閱
不是很有把握解決, 不過D7可以不代表XE7也可以,
建議把 sharemem 拿掉看看, 其他我也沒招,
或者改 xe8以後的版本

另外, 李維大師不太可能會看這個, 也不可能回覆這個吧!
wuhs
一般會員


發表:1
回覆:6
積分:1
註冊:2015-09-24

發送簡訊給我
#4 引用回覆 回覆 發表時間:2015-10-16 11:26:51 IP:59.40.xxx.xxx 訂閱
总算有个人回复了,谢谢,拿掉sharemem更死定了,不过我试试。
------
wuhs
JamesJuan
中階會員


發表:2
回覆:76
積分:80
註冊:2003-04-08

發送簡訊給我
#5 引用回覆 回覆 發表時間:2015-10-16 15:37:02 IP:60.250.xxx.xxx 未訂閱
不好意思,懶得找 XE7 環境測試,直接用 DX10 測 @ Windows 10



運作起來正確無誤











兩個專案均未引用 ShareMem,因為不需要(沒有傳遞 string 型別的參數)



關閉也很正常…



這種應該不需要動用到李大師吧...派我們這種小嘍嘍就可以了



編輯記錄
JamesJuan 重新編輯於 2015-10-16 15:39:00, 註解 無‧
JamesJuan 重新編輯於 2015-10-16 15:39:55, 註解 無‧
wuhs
一般會員


發表:1
回覆:6
積分:1
註冊:2015-09-24

發送簡訊給我
#6 引用回覆 回覆 發表時間:2015-10-20 00:52:52 IP:114.244.xxx.xxx 訂閱
谢谢兄弟,但我试了,去掉也不行,退出时,仍报216错误。


这是DLL库文件代码:
library Project3;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses

Vcl.Forms,
System.SysUtils,
System.Classes,
Unit2 in 'Unit2.pas' {Form2};

{$R *.res}

var DLLApp: TApplication;
DllScr: TScreen;

const
DLL_PROCESS_DETACH = 0;
DLL_PROCESS_ATTACH = 1;
DLL_THREAD_ATTACH = 2;
DLL_THREAD_DETACH = 3;

procedure DLLUnLoadProc(Reason: Integer); register;
begin
try
if Reason = DLL_PROCESS_DETACH then
begin
Application := DLLApp;
Screen := DLLScr;
end;
except
on e: exception do
Application.MessageBox(PChar(E.Message), '系统提示');
end;
end;

Exports
ShowForm2;

begin
try
DLLApp := Application;
DLLScr := Screen;
DllProc:= @DLLUnLoadProc;

except
on E: Exception do
begin
Application.MessageBox(PChar(E.Message),'系统提示');
end;
end;
end.

//////////////////////////////////////////////////////////////////////////////////
这是内部Form代码
unit Unit2;

interface

uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics,Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Grids, Vcl.DBGrids;

type
TForm2 = class(TForm)
DBGrid1: TDBGrid;
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form2: TForm2;
Procedure ShowForm2(App: TApplication; Scr: TScreen);stdcall;

implementation

{$R *.dfm}

Procedure ShowForm2(App: TApplication; Scr: TScreen);stdcall;
begin
If Assigned(Form2) then Form2.BringToFront
else begin
Application:= App;
Screen:= Scr;
Form2:= TForm2.Create(Application);
Form2.Show;
end;
end;


procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
Form2:=nil;
end;

end.
------
wuhs
wuhs
一般會員


發表:1
回覆:6
積分:1
註冊:2015-09-24

發送簡訊給我
#7 引用回覆 回覆 發表時間:2015-11-21 15:12:28 IP:59.40.xxx.xxx 訂閱
兄弟,能把您的源吗贴上来看一下吗?
------
wuhs
JamesJuan
中階會員


發表:2
回覆:76
積分:80
註冊:2003-04-08

發送簡訊給我
#8 引用回覆 回覆 發表時間:2015-11-23 10:41:44 IP:60.250.xxx.xxx 未訂閱
source code 已經上傳至下述網址,請參閱
http://1drv.ms/1PIWW71
wuhs
一般會員


發表:1
回覆:6
積分:1
註冊:2015-09-24

發送簡訊給我
#9 引用回覆 回覆 發表時間:2015-11-30 11:18:04 IP:218.241.xxx.xxx 訂閱
大陆政府把大部分境外网站都封了,上不到你给的网址,能邮件到HHtask@163.com吗,谢谢!
------
wuhs
blue
中階會員


發表:169
回覆:136
積分:81
註冊:2002-04-15

發送簡訊給我
#10 引用回覆 回覆 發表時間:2016-02-29 15:38:59 IP:122.146.xxx.xxx 訂閱
以前寫Shell extension 時也常發生這個錯誤,
換個版本後就正常了,
謝謝!
wuhs
一般會員


發表:1
回覆:6
積分:1
註冊:2015-09-24

發送簡訊給我
#11 引用回覆 回覆 發表時間:2016-02-29 15:56:31 IP:59.40.xxx.xxx 訂閱
谢谢,估计是XE7本身有问题,反正问了一大圈没有得到一个靠谱的回答,您的回答可能算是最靠谱的了。
------
wuhs
系統時間:2024-04-25 20:00:35
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!