当然主程序调用DLL第一次时报错'access violation at address 0253d7e0 in module 'sgzd_tj.dll'.read of address 00000230',选确定后,调用的窗体出来了,一切正常,关闭后,重新现调用就不会报错了,每次运行程序调用DLL的第一次都会报错,网上搜了很多关于,access violation的贴子,都没用.抱着最后的希望,看看那位高手可以指点一下,先谢了.
dll:
library sgzd_tj;uses
SysUtils,
Classes,
zztzd in 'zztzd.pas' {zd_tj},
Unit3 in 'Unit3.pas' {zd_cp},
Unit1 in 'Unit1.pas' {tj_yl},
Unit2 in 'Unit2.pas' {zd_ps},
Unit4 in 'Unit4.pas' {zd_cpyl},
Unit5 in 'Unit5.pas' {zd_yltj},
Unit6 in 'Unit6.pas' {Form6};{$R *.res}
exports
zd_tjdll;begin
end.
dll的主zztzd.pas:
private
{ Private declarations }
wlbm,bm,gg,ys,cs:string; public { Public declarations }
end;var
zd_tj: Tzd_tj;
procedure zd_tjcreate;
procedure zd_tjfree;
procedure zd_tjdll(dl_xm:string);stdcall;implementation
uses Unit1,unit2,unit3,Unit4,unit5,unit6;{$R *.dfm}
procedure zd_tjcreate;
begin
zd_tj:=tzd_tj.create(application);
end;
procedure zd_tjfree;
begin
if Assigned(zd_tj) then zd_tj.free;
end;
procedure zd_tjdll(dl_xm:string);stdcall;
begin
try
zd_tjcreate;
dl_xm:=dl_xm;
zd_tj.showmodal;
finally
zd_tjfree;
end; end;
function RoundEx(Value: Extended; RoundMode: TFPURoundingMode = rmUp): Int64;
var
RM: TFPURoundingMode;
begin
RM := GetRoundMode;
try
SetRoundMode(RoundMode);
Result := Round(Value);
finally
SetRoundMode(RM);
end;
end;//另外还有5个窗体代友太多了不贴了.
主调程序:
public
{ Public declarations }
end;
var
zd_handle:thandle;
implementationuses Unit1, Unit25;{$R *.dfm}procedure TFrame4.BitBtn1Click(Sender: TObject);
var
zd:procedure(dl_xm:string);stdcall;
begin
zd_handle:=LoadLibrary(PChar('sgzd_tj'));
if zd_handle<=0 then
begin
Application.MessageBox('动态库不存在!','提示',64);
Exit;
end
else
begin
try
@zd:=GetProcAddress(zd_handle,'zd_tjdll');
zd(Form1.dl_xm);
except
Application.MessageBox('动态库加载失败!','提示',64);
Exit;
end;
end;end;
dll:
library sgzd_tj;uses
SysUtils,
Classes,
zztzd in 'zztzd.pas' {zd_tj},
Unit3 in 'Unit3.pas' {zd_cp},
Unit1 in 'Unit1.pas' {tj_yl},
Unit2 in 'Unit2.pas' {zd_ps},
Unit4 in 'Unit4.pas' {zd_cpyl},
Unit5 in 'Unit5.pas' {zd_yltj},
Unit6 in 'Unit6.pas' {Form6};{$R *.res}
exports
zd_tjdll;begin
end.
dll的主zztzd.pas:
private
{ Private declarations }
wlbm,bm,gg,ys,cs:string; public { Public declarations }
end;var
zd_tj: Tzd_tj;
procedure zd_tjcreate;
procedure zd_tjfree;
procedure zd_tjdll(dl_xm:string);stdcall;implementation
uses Unit1,unit2,unit3,Unit4,unit5,unit6;{$R *.dfm}
procedure zd_tjcreate;
begin
zd_tj:=tzd_tj.create(application);
end;
procedure zd_tjfree;
begin
if Assigned(zd_tj) then zd_tj.free;
end;
procedure zd_tjdll(dl_xm:string);stdcall;
begin
try
zd_tjcreate;
dl_xm:=dl_xm;
zd_tj.showmodal;
finally
zd_tjfree;
end; end;
function RoundEx(Value: Extended; RoundMode: TFPURoundingMode = rmUp): Int64;
var
RM: TFPURoundingMode;
begin
RM := GetRoundMode;
try
SetRoundMode(RoundMode);
Result := Round(Value);
finally
SetRoundMode(RM);
end;
end;//另外还有5个窗体代友太多了不贴了.
主调程序:
public
{ Public declarations }
end;
var
zd_handle:thandle;
implementationuses Unit1, Unit25;{$R *.dfm}procedure TFrame4.BitBtn1Click(Sender: TObject);
var
zd:procedure(dl_xm:string);stdcall;
begin
zd_handle:=LoadLibrary(PChar('sgzd_tj'));
if zd_handle<=0 then
begin
Application.MessageBox('动态库不存在!','提示',64);
Exit;
end
else
begin
try
@zd:=GetProcAddress(zd_handle,'zd_tjdll');
zd(Form1.dl_xm);
except
Application.MessageBox('动态库加载失败!','提示',64);
Exit;
end;
end;end;
library sgzd_tj;
uses
sharemem, SysUtils,
Classes,
library sgzd_tj;uses
sharemem,
SysUtils,
Classes,
zztzd in 'zztzd.pas' {zd_tj},
Unit3 in 'Unit3.pas' {zd_cp},
Unit1 in 'Unit1.pas' {tj_yl},
begin
try
zd_tjcreate;
dl_xm:=dl_xm; /// DLL哪里有? dl_Xm???????
zd_tj.showmodal;
finally
zd_tjfree;
end; end;
dl_xm:=dl_xm前面这个dl_xm声明在type前面,可以不带窗体名(这两天在网上看的)这个东东搞死我的,不过现在搞定了.原因出在这里:
if(Screen.width<> 1024)then
begin
Height:=750;//longint(Height)*longint(Screen.Height)DIV 768;
Width:=1024;//longint(Width)*longint(Screen.Width)DIV 1024;//窗口大小调整
zd_tj.Position:=poScreenCenter; //罪魁祸首1
end
else
begin
zd_tj.Position:=poOwnerFormCenter;//罪魁祸首2
end;
在这里特别感谢starluck ,因为我的好多问题,他(她)都有在帮我解答,再次感谢.