我用了两个单元文件。一个是Form的(里有一个Edit, 两个Button[1, 2]) 另一个就是 TMyMath的type
TMyMath = class
private
ExtendedTemp: extended;
ExtendedIntRes: int64;
protected
public
function Rounding(x: extended): int64;
constructor create;
destructor destroy; override;
end;implementation{ TMyMath }
constructor TMyMath.create;
begin
extendedTemp := 0;
extendedintRes := 0;
end;destructor TMyMath.destroy;
begin
inherited destroy();
end;function TMyMath.Rounding(x: extended): int64; //这是求四舍五入的函数。
begin
extendedtemp := x;
while extendedtemp >= 1 do
begin
extendedtemp := extendedtemp - 1;
end;
if extendedtemp > 0.5 then
begin
extendedtemp := 1;
extendedIntRes := trunc(x + extendedtemp);
end
else
begin
extendedIntRes := trunc(x);
end;
result := extendedintres;
end;以下是调用TMyMath:procedure TForm1.Button1Click(Sender: TObject); //单击Button1。
var
x: integer;
y: double;
MyMath: TMyMath; //创建TMyMath的对象“MyMath”
begin
MyMath := TMyMath.create; //创建和初始化
try
y := strtofloat(edtinput.Text);
x := MyMath.Rounding(y);
showmessage(inttostr(x));
finally
MyMath.free; //自己创建的不能释放,调用 Destroy 也不管用。
button2.free; //控件可以释放
end; if MyMath = nil then //判断对象“MyMath”是否已经被释放?
begin
showmessage('ok');
end
else
begin
showmessage('no'); //最后的运行结果是 no
end; if button2 = nil then //判断Button2控件是否已经被释放?
begin
showmessage('ok'); //最后的运行结果是 OK
end
else
begin
showmessage('no');
end;
end;
请高手帮帮我。书上没有。。上网查了也没有在QQ群问,也无结果所以,这是最后的希望了 :)请大家帮帮忙。不要笑我的问题太菜。我会努力的。
TMyMath = class
private
ExtendedTemp: extended;
ExtendedIntRes: int64;
protected
public
function Rounding(x: extended): int64;
constructor create;
destructor destroy; override;
end;implementation{ TMyMath }
constructor TMyMath.create;
begin
extendedTemp := 0;
extendedintRes := 0;
end;destructor TMyMath.destroy;
begin
inherited destroy();
end;function TMyMath.Rounding(x: extended): int64; //这是求四舍五入的函数。
begin
extendedtemp := x;
while extendedtemp >= 1 do
begin
extendedtemp := extendedtemp - 1;
end;
if extendedtemp > 0.5 then
begin
extendedtemp := 1;
extendedIntRes := trunc(x + extendedtemp);
end
else
begin
extendedIntRes := trunc(x);
end;
result := extendedintres;
end;以下是调用TMyMath:procedure TForm1.Button1Click(Sender: TObject); //单击Button1。
var
x: integer;
y: double;
MyMath: TMyMath; //创建TMyMath的对象“MyMath”
begin
MyMath := TMyMath.create; //创建和初始化
try
y := strtofloat(edtinput.Text);
x := MyMath.Rounding(y);
showmessage(inttostr(x));
finally
MyMath.free; //自己创建的不能释放,调用 Destroy 也不管用。
button2.free; //控件可以释放
end; if MyMath = nil then //判断对象“MyMath”是否已经被释放?
begin
showmessage('ok');
end
else
begin
showmessage('no'); //最后的运行结果是 no
end; if button2 = nil then //判断Button2控件是否已经被释放?
begin
showmessage('ok'); //最后的运行结果是 OK
end
else
begin
showmessage('no');
end;
end;
请高手帮帮我。书上没有。。上网查了也没有在QQ群问,也无结果所以,这是最后的希望了 :)请大家帮帮忙。不要笑我的问题太菜。我会努力的。
解决方案 »
- 救急阿~~~有关intraweb
- 报表打印通讯录问题。
- 开发自己的文档收藏器,要能够存储文字图片,可以进行查询,不知数据库该如何选择
- 请各位高手解答我的疑惑
- 求助,给分100,adodataset的数据如何读出生成特定格式的XML文件?
- 如果当机器里没有按装acroread时,就不能掉用pdf文件,我用shellexecute来执行pdf文件,怎样使调用失败时,弹出提示,要求安装acroread
- 如何处理异常?
- 大家好,我们工作赛马的网站正式开通,请参观!
- [求助]d7从主程序无法进入bpl函数或用鼠标看bpl数据连接的值
- 兄弟们,进来看看,言者有分!
- 动态创建的指针内存如何释放
- 按下一个btn销毁当前窗口的代码怎么写
finally
FreeAndNil(MyMath);
end;
...
MyMath.free;
MyMath:=nil;
或者用FreeAndNil函数:FreeAndNil(MyMath);
var
Temp: TObject;
begin
Temp := TObject(Obj);
Pointer(Obj) := nil;
Temp.Free;
end;