DLL代码如下:library itsdll;uses
SysUtils, Classes;{$R *.res}
type
TArr=array[1..5] of string;
PTArr=^Tarr;
PReal=^Real;
Var
xs:real;
area:integer;procedure SelConst(ch:char);//确定试块的规格和受压面积
begin
case(ch)of
'A': begin xs:=1.00;area:=22500; end;
'B': begin xs:=1.05;area:=40000; end;
'C': begin xs:=0.95;area:=10000; end;
end
end;procedure Selpd(num:PReal;i:integer); //选择保留几位小数,NUM是被修约数,i是保留小数个数
var
temp:integer;
e,rest:real;//rest是按i的个数扩大e倍所留的余数
begin
case i of
1: e:=10.0;
2: e:=100.0;
3: e:=1000.0;
4: e:=10000.0;
end; temp:=round(num^*e);
if temp>(num^*e) then temp:=temp-1;
rest:=(num^*e)-temp; if (rest>0.5)then num^:=(temp+1)/e;
if (rest<0.5)then num^:=temp/e;
if (rest=0.5)then
begin
if (num^*e/2=0)then num^:=temp/e //逢5看奇偶,奇进偶不进
else num^:=(temp+1)/e;
end;
end;
function Calc(D_ITS:integer;sort:char;a:PTArr):integer;stdcall;
var
i:integer;
a_temp:array[1..4] of real;
begin
SelConst(sort);
for i:=1 to 3 do //转化成数值
begin
a_temp[i]:=StrToFloat(a^[i])*xs*1000/area;
end;
a_temp[4]:=(a_temp[1]+a_temp[2]+a_temp[3])/3; for i:=1 to 4 do //转化成字符串
begin
Selpd(@a_temp[i],1);
a^[i]:=FloatToStr(a_temp[i]);
end;
if (a_temp[3]>=D_ITS)then a^[5]:='合格'
else a^[5]:='不合格';end;exports
Calc;beginend.调用代码如下:
procedure TForm1.Button1Click(Sender: TObject);
type
TArr=array[1..5] of string;
PTArr=^TArr;
TCalcProc=Function(D_its:integer;p:char;arr:PTArr):integer;stdcall;
Var
c:TArr;
p:PTArr;
Calc_ITS:TCalcProc;
D_its:integer;
sort:char;
Hand:THandle;
begin
Hand:=LoadLibrary('itsdll.dll');
if Hand>0 then begin
@Calc_ITS:=GetProcAddress(Hand,PChar('Calc'));
if @Calc_ITS<>nil then
begin
c[1]:=Edit1.Text;
c[2]:=Edit2.Text;
c[3]:=Edit3.Text;
c[4]:=Edit3.Text;
c[5]:=Edit3.Text; if (Combobox1.text='C10') then D_its:=10;
if (Combobox1.text='C15') then D_its:=15;
if (Combobox1.text='C20') then D_its:=20;
if (Combobox1.text='C25') then D_its:=25;
if (Combobox1.text='C30') then D_its:=30;
if (Combobox1.text='C40') then D_its:=40;
if (Combobox1.text='C50') then D_its:=50; if (ComboBox2.Text='150X150X150') then sort:='A';
if (ComboBox2.Text='200X200X200') then sort:='B';
if (ComboBox2.Text='100X100X100') then sort:='C'; Calc_ITS(D_its,sort,@c); Edit4.text:=c[1];
Edit5.text:=c[2];
Edit6.text:=c[3];
Edit7.text:=c[4];
Edit8.text:=c[5]; end
else
ShowMessage('DLL函数没找到')
end
else
ShowMessage('DLL调用失败'); FreeLibrary(Hand);end;
SysUtils, Classes;{$R *.res}
type
TArr=array[1..5] of string;
PTArr=^Tarr;
PReal=^Real;
Var
xs:real;
area:integer;procedure SelConst(ch:char);//确定试块的规格和受压面积
begin
case(ch)of
'A': begin xs:=1.00;area:=22500; end;
'B': begin xs:=1.05;area:=40000; end;
'C': begin xs:=0.95;area:=10000; end;
end
end;procedure Selpd(num:PReal;i:integer); //选择保留几位小数,NUM是被修约数,i是保留小数个数
var
temp:integer;
e,rest:real;//rest是按i的个数扩大e倍所留的余数
begin
case i of
1: e:=10.0;
2: e:=100.0;
3: e:=1000.0;
4: e:=10000.0;
end; temp:=round(num^*e);
if temp>(num^*e) then temp:=temp-1;
rest:=(num^*e)-temp; if (rest>0.5)then num^:=(temp+1)/e;
if (rest<0.5)then num^:=temp/e;
if (rest=0.5)then
begin
if (num^*e/2=0)then num^:=temp/e //逢5看奇偶,奇进偶不进
else num^:=(temp+1)/e;
end;
end;
function Calc(D_ITS:integer;sort:char;a:PTArr):integer;stdcall;
var
i:integer;
a_temp:array[1..4] of real;
begin
SelConst(sort);
for i:=1 to 3 do //转化成数值
begin
a_temp[i]:=StrToFloat(a^[i])*xs*1000/area;
end;
a_temp[4]:=(a_temp[1]+a_temp[2]+a_temp[3])/3; for i:=1 to 4 do //转化成字符串
begin
Selpd(@a_temp[i],1);
a^[i]:=FloatToStr(a_temp[i]);
end;
if (a_temp[3]>=D_ITS)then a^[5]:='合格'
else a^[5]:='不合格';end;exports
Calc;beginend.调用代码如下:
procedure TForm1.Button1Click(Sender: TObject);
type
TArr=array[1..5] of string;
PTArr=^TArr;
TCalcProc=Function(D_its:integer;p:char;arr:PTArr):integer;stdcall;
Var
c:TArr;
p:PTArr;
Calc_ITS:TCalcProc;
D_its:integer;
sort:char;
Hand:THandle;
begin
Hand:=LoadLibrary('itsdll.dll');
if Hand>0 then begin
@Calc_ITS:=GetProcAddress(Hand,PChar('Calc'));
if @Calc_ITS<>nil then
begin
c[1]:=Edit1.Text;
c[2]:=Edit2.Text;
c[3]:=Edit3.Text;
c[4]:=Edit3.Text;
c[5]:=Edit3.Text; if (Combobox1.text='C10') then D_its:=10;
if (Combobox1.text='C15') then D_its:=15;
if (Combobox1.text='C20') then D_its:=20;
if (Combobox1.text='C25') then D_its:=25;
if (Combobox1.text='C30') then D_its:=30;
if (Combobox1.text='C40') then D_its:=40;
if (Combobox1.text='C50') then D_its:=50; if (ComboBox2.Text='150X150X150') then sort:='A';
if (ComboBox2.Text='200X200X200') then sort:='B';
if (ComboBox2.Text='100X100X100') then sort:='C'; Calc_ITS(D_its,sort,@c); Edit4.text:=c[1];
Edit5.text:=c[2];
Edit6.text:=c[3];
Edit7.text:=c[4];
Edit8.text:=c[5]; end
else
ShowMessage('DLL函数没找到')
end
else
ShowMessage('DLL调用失败'); FreeLibrary(Hand);end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货