一个线程问题,请大家看看我的程序错在哪儿?为什么占用的内存不会失放掉啊!!,运行不久就死机啊!!!
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, ExtCtrls;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
Timer1: TTimer;
ADOQuery1: TADOQuery;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TVoice=class(TThread) //进行保存
protected
procedure Execute; override;
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TVoice.Execute;
begin
with form1.ADOQuery1 do
try
if Active then close;
SQL.Text:='select * from msghis';
Open;
if RecordCount>0 then
Begin
end;
finally
close;
end;end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
with form1.ADOQuery1 do
try
if Active then close;
SQL.Text:='select * from msghis';
Open;
if RecordCount>0 then
Begin
end;
finally
close;
end;
TVoice.create(false);
end;end.
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, ExtCtrls;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
Timer1: TTimer;
ADOQuery1: TADOQuery;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
TVoice=class(TThread) //进行保存
protected
procedure Execute; override;
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TVoice.Execute;
begin
with form1.ADOQuery1 do
try
if Active then close;
SQL.Text:='select * from msghis';
Open;
if RecordCount>0 then
Begin
end;
finally
close;
end;end;procedure TForm1.Timer1Timer(Sender: TObject);
begin
with form1.ADOQuery1 do
try
if Active then close;
SQL.Text:='select * from msghis';
Open;
if RecordCount>0 then
Begin
end;
finally
close;
end;
TVoice.create(false);
end;end.
解决方案 »
- 动态数组和数组的问题,请教高手?
- Delphi如何使用C++ template class?
- 为什么添加开机启动不成功?
- 关于标签打印机在dephi使用的问题
- delphi sql语句字符串的问题
- 一个弱弱的问题。。。。。
- 如何向客户机发送消息 ,请手请进.......
- 关于query定位某行后,显示在DBgrid某个位置上的问题(急急急)
- 在dbgrid中按某个字段对记录集进行排序的问题
- dll调用的vb转delphi
- ■ 请问如何设置EDIT文本框上中下对齐,不是左中右对齐■
- 转让经典Delphi资料:《Delphi 5高级编程》丛书、《Delphi 4开发大全》、《C++Builder 5高级编程技术》丛书
begin
FreeOnTerminate := True;//加上这句话
with form1.ADOQuery1 do
try
if Active then close;
SQL.Text:='select * from msghis';
Open;
if RecordCount>0 then
Begin
end;
finally
close;
end;end;
线程如果没有必要用,就不要用,如果要用,就最好保证:一次创建,长时间运用,然后一次销毁。madyak的的做法是能把资源销毁的,出错是可能其它的原因啊,用法有问题,建议你先调整一下用法。