delphi的dll用pb50调用为什么总是非法操作?(100分)

  • 主题发起人 主题发起人 jfk
  • 开始时间 开始时间
J

jfk

Unregistered / Unconfirmed
GUEST, unregistred user!
本人作了一个关于数据库dll,adoconnection,adoquery,datasource都是
动态创建,另外,用了一个第三方控件Devexpress QGrid3将检索出来的数
据保存为excel文件,结果用delphi调用n次也没出问题,一旦用pb50调用就
会出现非法操作,本人现在悬赏100大洋,请pb&delphi高手帮忙解决.
 
DLL中的函数必须使用stdcall调用,并且字符串必须以PChar得形式传递,其它开发语言
才能调用!
 
DLL中的函数有好几种声明方法,好象要用pascal 或者 stdcall 才行。你可以看看帮助
 
不好意思,两位高手我的delphi dll正如你们所说参数是pchar而且是stdcall.
 
各位大虾,给点建议,小弟实在无招可施了。
 
将被调用的函数完整地贴上来让大家看看!
 
详细代码在此请各位大虾赐教:
//SaveDataToExcel的输出值是因为pb50调用时必须有返回值,所以先暂时用
integer类型返回值1

library saveexcel;
uses
SysUtils,Classes,Dialogs,ole2,
Unit_data in 'Unit_data.pas' {Form_Data};
{$R *.RES}
Function SaveDataToExcel(P_begin_date:pchar;P_end_date:pchar;P_path:pchar):
integer;stdcall;
var
str_begin_date,str_end_date,str_path:string;
FileHandle : Integer;
begin
With TForm_data.Create(nil) do
begin
try
coinitialize(nil);
str_begin_date:=strpas(P_begin_date);
str_end_date :=strpas(P_end_date);
str_path :=strpas(p_path);
if fileexists(str_path) then
begin
FileHandle := FileOpen(str_path,fmOpenRead );
if FileHandle > 0 then
begin//如果文件存在并且没有被打开,提示是否覆盖
fileclose(filehandle);
if MessageDlg(str_path+'已经存在,是否覆盖?',
mtWarning, [mbYes, mbNo], 0) = 6 then
begin
//取数据
showdata(str_begin_date,str_end_date,str_path);
//
Grid_ship.SaveToXLS(p_path,true);
showmessage('保存成功!');
end
else
showmessage('文件未保存!');
end
else//如果文件被打开,提示出错
begin
showmessage(str_path+'已经被打开,请改名或关闭!
文件未保存!')
end
end
else //文件不存在,可以保存
begin
//去班轮数据
showdata(str_begin_date,str_end_date,str_path);
//
Grid_ship.SaveToXLS(p_path,true);
showmessage('保存成功!')
end;
close;
finally
Free;
couninitialize;
end;
end;
SaveDataToExcel:=1;
end ;
exports
SaveDataToExcel;
begin
end.
//以下是form_data中代码
unit Unit_data;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Db, ADODB, dxGrClms, dxTL, dxDBGrid, dxCntner, ExtCtrls, DBCtrls,
StdCtrls, Grids, DBGrids, dxDBTLCl, dxDBCtrl;

type
TForm_Data = class(TForm)
Grid_ship: TdxDBGrid;
Grid_shipETA_TIM: TdxDBGridDateColumn;
Grid_shipETD_TIM: TdxDBGridDateColumn;
Grid_shipSTOP_BILL_DTE: TdxDBGridDateColumn;
Grid_shipHANG_PORT_STR: TdxDBGridMaskColumn;
Grid_shipBEGIN_TIM: TdxDBGridDateColumn;
Grid_shipEND_TIM: TdxDBGridDateColumn;
Grid_shipIN_TEU_NUM: TdxDBGridMaskColumn;
Grid_shipLINE_NAM: TdxDBGridMaskColumn;
Grid_shipE_SHIP_NAM: TdxDBGridMaskColumn;
Grid_shipC_SHIP_NAM: TdxDBGridMaskColumn;
Grid_shipOUT_VOYAGE_NO: TdxDBGridMaskColumn;
Grid_shipIN_VOYAGE_NO: TdxDBGridMaskColumn;
Grid_shipctrustname: TdxDBGridColumn;
Grid_shipkaihang: TdxDBGridColumn;
Grid_shipWorkPlace: TdxDBGridColumn;
procedure FormCreate(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }

end;

var
Form_Data : TForm_Data;
ado_connect : Tadoconnection;
ado_query : Tadoquery;
ado_datasur : Tdatasource;
procedure showdata(str_begin_date:string;str_end_date:string;str_path
:string);
implementation

{$R *.DFM}
procedure showdata(str_begin_date:string;str_end_date:string;str_path:string);
begin
ado_query.Close;
ado_query.SQL.Clear;
ado_query.SQL.Append('SELECT "REGULAR_SHIP"."TRUST_COD", ');
ado_query.SQL.Append('"REGULAR_SHIP"."E_TRUST_NAM", ');
ado_query.SQL.Append('"REGULAR_SHIP"."ETA_TIM", ');
ado_query.SQL.Append('"REGULAR_SHIP"."ETD_TIM", ');
ado_query.SQL.Append('"REGULAR_SHIP"."REGULAR_DTE", ');
ado_query.SQL.Append('"REGULAR_SHIP"."STOP_BILL_DTE", ');
ado_query.SQL.Append('"REGULAR_SHIP"."HANG_PORT_STR", ');
ado_query.SQL.Append('"REGULAR_SHIP"."LOAD_PLACE_STR", ');
ado_query.SQL.Append('"REGULAR_SHIP"."BEGIN_TIM", ');
ado_query.SQL.Append('"REGULAR_SHIP"."END_TIM", ');
ado_query.SQL.Append('"REGULAR_SHIP"."IN_TEU_NUM", ');
ado_query.SQL.Append('"REGULAR_SHIP"."OUT_TEU_NUM", ');
ado_query.SQL.Append('"REGULAR_SHIP"."AGENCY_ID", ');
ado_query.SQL.Append('"REGULAR_SHIP"."TO_SHIP_ID", ');
ado_query.SQL.Append('"REGULAR_SHIP"."LINE_COD", ');
ado_query.SQL.Append('"REGULAR_SHIP"."LINE_NAM", ');
ado_query.SQL.Append('"REGULAR_SHIP"."RELET_MAN", ');
ado_query.SQL.Append('"REGULAR_SHIP"."PHONE_NO", ');
ado_query.SQL.Append('"SYS_PARAM"."E_COMPANY_NAM", ');
ado_query.SQL.Append('"SYS_PARAM"."C_COMPANY_NAM", ');
ado_query.SQL.Append('"WORK_PLACE_CODE"."C_WORK_PLACE_STR", ');
ado_query.SQL.Append('"SYS_PARAM"."ADD_STR", ');
ado_query.SQL.Append('"SYS_PARAM"."TEL_STR", ');
ado_query.SQL.Append('"SYS_PARAM"."FAX_STR", ');
ado_query.SQL.Append('"SYS_PARAM"."TLX_STR", ');
ado_query.SQL.Append('"REGULAR_SHIP"."E_SHIP_NAM", ');
ado_query.SQL.Append('"REGULAR_SHIP"."C_SHIP_NAM", ');
ado_query.SQL.Append('"REGULAR_SHIP"."OUT_VOYAGE_NO", ');
ado_query.SQL.Append('"REGULAR_SHIP"."IN_VOYAGE_NO", ');
ado_query.SQL.Append('"REGULAR_SHIP"."C_TRUST_NAM", ');
ado_query.SQL.Append('"TRUST_RECORD"."C_TRUST_NAM" ');
ado_query.SQL.Append('FROM "REGULAR_SHIP","SYS_PARAM", ');
ado_query.SQL.Append('"WORK_PLACE_CODE","TRUST_RECORD" ');
ado_query.SQL.Append('WHERE regular_ship.work_place_cod = work_place_code.work_place_cod (+) and ');
ado_query.SQL.Append('regular_ship.trust_cod = trust_record.trust_cod (+) and ');
ado_query.SQL.Append(' "REGULAR_SHIP"."ETA_TIM" >= TO_DATE('''+str_begin_date+''',''YYYY-MM-DD'') AND');
ado_query.SQL.Append(' "REGULAR_SHIP"."ETA_TIM" < TO_DATE('''+str_end_date+''',''YYYY-MM-DD'' ) ');
ado_query.ExecSQL;
ado_query.Active:=true;
end;
procedure TForm_Data.FormCreate(Sender: TObject);
begin
//create connection
ado_connect:=Tadoconnection.Create(parent);
ado_connect.ConnectionString:='Provider=MSDAORA.1;Password=ok;User ID=samis_hh;Data Source=samis_hh;Persist Security Info=True';
ado_connect.LoginPrompt:=false;
ado_connect.connected :=false;
//create adoquery
ado_query:=Tadoquery.Create(parent);
ado_query.Connection :=ado_connect;
//create datasource
ado_datasur :=Tdatasource.create(parent);
ado_datasur.DataSet:=ado_query;
//
Grid_ship.DataSource :=ado_datasur;
end;
end.

 
是不是interger的问题?
不同的系统不一样的。
你试试用pchar返回。
 
var
str_begin_date,str_end_date,str_path:string;
将string改为widestring试试
 
多人接受答案了。
 
后退
顶部