峻
峻祁连
Unregistered / Unconfirmed
GUEST, unregistred user!
library YanCaoDll;
uses
SysUtils,
Classes,
unitToGet2Date in 'unitToGet2Date.pas' {frmGetDate},
{$R *.res}
exports
ToGet2Date,
begin
end.
======================
unit unitToGet2Date;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls;
type
TfrmGetDate = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
DateTimePickerStart: TDateTimePicker;
DateTimePickerEnd: TDateTimePicker;
Button1: TButton;
Button2: TButton;
labelStartDate: TLabel;
labelEndDate: TLabel;
Button3: TButton;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmGetDate: TfrmGetDate;
// Extern DLL Function Declaration
function ToGet2Date(Var StartDate:string; Var EndDate:string):integer;cdecl;
implementation
{$R *.dfm}
// Extern DLL Function
function ToGet2Date(Var StartDate:string ; Var EndDate:string ):integer;cdecl;
//*******************************************************************************
// 功能 制作一个对话框,要求用户指定一个起始日期,一个终止日期 *
// 输入参数 StartDate ---- "YYYY-MM-DD"的字符串,是默认的起始日期字符串 *
// EndDate ----"YYYY-MM-DD"的字符串,是默认的终止日期字符串 *
// 输出参数 StartDate ----"YYYY-MM-DD"的字符串,是由用户指定的起始日期字符串*
// EndDate ----"YYYY-MM-DD"的字符串,是由用户指定的终止日期字符串 *
// 要求:EndDate 是在 StartDate 之后,例如:SatrtDate="20011209" *
// EndDate= "20020317" *
// 函数返回值 整形 1---- 表示操作成功, *
// 0 ----- 表示用户取消日期的制定工作 *
// *
//*******************************************************************************
var
SDate,EDate :TdateTime;
begin
//Default Value
Result := 0;
try //Except
frmGetDate:=TfrmGetDate.Create(Application);
try //finally
with frmGetDate do
begin
{ //初始化===
DateTimePickerStart.Date:=strToDate(StartDate);
DateTimePickerEnd.Date:=strToDate(EndDate);
}
if showmodal = mrOK then
begin
SDate := DateTimePickerStart.Date;
EDate := DateTimePickerEnd.Date;
ShortDateFormat := 'yyyy-MM-dd';
showmessage('SDate=:'+datetostr(sdate)+#13+'Edate='+datetostr(Edate));
if SDate > EDate then
begin //操作失败==
showmessage('终止日期必须晚于起始日期!');
Result :=0;
exit;
end; //if
StartDate := DateToStr(SDate); //////////出错的地方/////////////
EndDate := DateToStr(EDate);
Result :=1; //返回值 为1
end; //if
end ;//with
finally
frmGetDate.Free;
end;
except
on E: Exception do
messageDlg('哈哈!错了, 在 frmGetDate: '+ E.message, mtError,[mbOK],0);
end;
end; //Function
end.
============================================================
MapBasic调用程序如下:
Declare Sub Main()
Declare Function ToGet2Date LIB "D:/工程/丰台/dll/YanCaoDll.dll" (sStartDate As string*12 ,sEndDate As string*12) AS Integer
Sub Main()
Dim sStartDate,sEndDate As STring*20
Dim nResult As Integer
sStartDate="2002-04-02"
sEndDate="2002-04-02"
nResult=ToGet2Date(sStartDate,sEndDate)
Print "Result="+nResult+Chr$(13)+sStartDate+Chr$(13)+sEndDate+Chr$(13)
End Sub
==========================
错误信息:
在FrmGetDate:Access violation at address 042E482E in module 'yancaoDll.dll',Read of address 3230302A
uses
SysUtils,
Classes,
unitToGet2Date in 'unitToGet2Date.pas' {frmGetDate},
{$R *.res}
exports
ToGet2Date,
begin
end.
======================
unit unitToGet2Date;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls;
type
TfrmGetDate = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
DateTimePickerStart: TDateTimePicker;
DateTimePickerEnd: TDateTimePicker;
Button1: TButton;
Button2: TButton;
labelStartDate: TLabel;
labelEndDate: TLabel;
Button3: TButton;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
frmGetDate: TfrmGetDate;
// Extern DLL Function Declaration
function ToGet2Date(Var StartDate:string; Var EndDate:string):integer;cdecl;
implementation
{$R *.dfm}
// Extern DLL Function
function ToGet2Date(Var StartDate:string ; Var EndDate:string ):integer;cdecl;
//*******************************************************************************
// 功能 制作一个对话框,要求用户指定一个起始日期,一个终止日期 *
// 输入参数 StartDate ---- "YYYY-MM-DD"的字符串,是默认的起始日期字符串 *
// EndDate ----"YYYY-MM-DD"的字符串,是默认的终止日期字符串 *
// 输出参数 StartDate ----"YYYY-MM-DD"的字符串,是由用户指定的起始日期字符串*
// EndDate ----"YYYY-MM-DD"的字符串,是由用户指定的终止日期字符串 *
// 要求:EndDate 是在 StartDate 之后,例如:SatrtDate="20011209" *
// EndDate= "20020317" *
// 函数返回值 整形 1---- 表示操作成功, *
// 0 ----- 表示用户取消日期的制定工作 *
// *
//*******************************************************************************
var
SDate,EDate :TdateTime;
begin
//Default Value
Result := 0;
try //Except
frmGetDate:=TfrmGetDate.Create(Application);
try //finally
with frmGetDate do
begin
{ //初始化===
DateTimePickerStart.Date:=strToDate(StartDate);
DateTimePickerEnd.Date:=strToDate(EndDate);
}
if showmodal = mrOK then
begin
SDate := DateTimePickerStart.Date;
EDate := DateTimePickerEnd.Date;
ShortDateFormat := 'yyyy-MM-dd';
showmessage('SDate=:'+datetostr(sdate)+#13+'Edate='+datetostr(Edate));
if SDate > EDate then
begin //操作失败==
showmessage('终止日期必须晚于起始日期!');
Result :=0;
exit;
end; //if
StartDate := DateToStr(SDate); //////////出错的地方/////////////
EndDate := DateToStr(EDate);
Result :=1; //返回值 为1
end; //if
end ;//with
finally
frmGetDate.Free;
end;
except
on E: Exception do
messageDlg('哈哈!错了, 在 frmGetDate: '+ E.message, mtError,[mbOK],0);
end;
end; //Function
end.
============================================================
MapBasic调用程序如下:
Declare Sub Main()
Declare Function ToGet2Date LIB "D:/工程/丰台/dll/YanCaoDll.dll" (sStartDate As string*12 ,sEndDate As string*12) AS Integer
Sub Main()
Dim sStartDate,sEndDate As STring*20
Dim nResult As Integer
sStartDate="2002-04-02"
sEndDate="2002-04-02"
nResult=ToGet2Date(sStartDate,sEndDate)
Print "Result="+nResult+Chr$(13)+sStartDate+Chr$(13)+sEndDate+Chr$(13)
End Sub
==========================
错误信息:
在FrmGetDate:Access violation at address 042E482E in module 'yancaoDll.dll',Read of address 3230302A