|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
程度界面和错误提示
动态链接应用地址冲突
程序代码
nit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,math;
type
TForm1 = class(TForm)
RadioButton1: TRadioButton;
RadioButton2: TRadioButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
procedure RadioButton1Click(Sender: TObject);
procedure RadioButton2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
type
TduFunction=Function(du:String):Extended;Stdcall;
TfuduFunction=Function(fudu:String):String;Stdcall;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
DllName:String;
ProcName:pchar;
Hinst:Thandle;
Fpointer:Tfarproc;
MyduFunction:TduFunction;
MyfuduFunction:TfuduFunction;
k:integer;
begin
Getdir(0,DllName);
DllName:=DllName+'\Func.dll';
if Radiobutton1.Checked=true then
begin
ProcName:='du_fudu';
k:=1;
end
else
begin
ProcName:='fudu_du';
k:=2;
end;
Hinst:=SafeLoadLibrary(DllName);
if Hinst>0 then
try
Fpointer:=GetProcAddress(Hinst,ProcName);
if Fpointer<>Nil then
begin
if (k=1) then
begin
MyduFunction:=TduFunction(Fpointer);
Edit2.Text:=FloatToStr(MyduFunction(Edit1.Text));
end
else
begin
MyfuduFunction:=TfuduFunction(Fpointer);
Edit2.Text:=MyfuduFunction(Edit1.Text);
end;
end
else
ShowMessage('Dll Function not found !');
finally
FreeLibrary(Hinst)
end
else
ShowMessage(DllName+'Library not found !');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.Text:='';
Edit2.Text:='';
Button1.Caption:='转换';
Radiobutton1.Checked:=true;
end;
procedure TForm1.RadioButton1Click(Sender: TObject);
begin
Label1.Caption:='度 =';
Label2.Caption:='弧度';
end;
procedure TForm1.RadioButton2Click(Sender: TObject);
begin
Label1.Caption:='弧度 =';
Label2.Caption:='度';
end;
end.
动态库代码
library Project1;
{ 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
SysUtils,Classes,math;
{$R *.res}
Function du_fudu(Str:string):Extended;Stdcall;
var
i:integer;
du,fen,miao,lmiao:real;
begin
i:=Pos('.',Str);
if(i=0)then
begin
Result:=StrToFloat(copy(Str,1,length(Str)))*(pi/180);
end
else
begin
Str:= FormatFloat('0.000000',StrtoFloat(Str));
du:=StrToFloat(copy(Str,1,i-1));
fen:=StrToFloat(copy(Str,i+1,2));
miao:=StrToFloat(copy(Str,i+3,2));
lmiao:=StrToFloat(copy(Str,i+5,2));
Result:=(du+(fen/60)+(miao/3600)+(lmiao/216000))*(pi/180);
end;
end;
Function fudu_du(Str:string):string;Stdcall;
var
jiaodu,du,fen,miao,lmiao:Extended;
begin
jiaodu:=(StrToFloat(Str))*(180/pi);
du:=Floor((jiaodu*3600)/3600);
fen:=Floor(((jiaodu-du)*3600)/60);
miao:=Floor((jiaodu-du)*3600-fen*60);
lmiao:=StrToFloat(copy(FormatFloat('0.00',((jiaodu-du)*3600-fen*60-miao)),3,2));
Result:=FloatToStr(du)+'°'+FloatToStr(fen)+'′'+FloatToStr(miao)+'.'+FloatToStr(lmiao)+'″';
end;
Exports
fudu_du,du_fudu;
begin
end.
|
|