我想问几个问题,让我先给你解释一下,你可以看到这篇文章下面的问题。我创建了一个多线程应用程序,它从数据库中读取和更新数据。线程使用 sendmessage 与主线程通信。我将指针 TRecord 传递给 sendmessage 并将指针放在主线程中。以下是显示流程结构的代码片段:
const WM_MY_MESSAGE = WM_USER + 0;
PTestPointerRecord : ^TTestPointerRecord;
TTestPointerRecord = record
i : integer;
end;
这是扩展 TThread 类的执行事件。除非线程被暂停或终止,否则它将连续运行。
procedure TSampleThreadClass.Execute;
var
TestPointerRecord : PTestPointerRecord;
FConnection : TConnectionObject;
FQuery : TQueryObject;
begin
while not Terminated do
begin
New(PTestPointerRecord);
FConnection := TConnectionObject.Create(nil);
FQuery := TQueryObject.Create(nil);
try
FConnection.connectionstring := 'path';
FConnection.loginPrompt := False;
FConnection.open;
FQuery.connection := FConnection;
FQuery.close;
FQuery.sql.clear;
FQuery.sql.add('select column1, column2 from table');
FQuery.open;
PTestPointerRecord.i := 0;
SendMessage(frmMain.handle, WM_MY_MESSAGE, 0, integer(PTestPointerRecord));
finally
FQuery.close;
FConnection.disconnect;
FreeAndNil(FQuery);
FreeAndNil(FConnection);
sleep(250);
end;
end;
end;
这是从线程接收消息的事件。
procedure TfrmMain.message(msg : TMessage);
var
TestPointerRecord : PTestPointerRecord;
begin
TestPointerRecord := PTestPointerRecord(msg.lParam);
try
edit1.Text := inttostr(TestPointerRecord.i);
finally
Dispose(TestPointerRecord);
end;
end;
该应用程序将用作将始终连续运行的服务类型应用程序。
问题:
1. 我是否正确处理指针?
2.当我在应用程序运行时检查我的任务管理器时,我观察到在进程选项卡下,我注意到内存(私人工作集)不断增加。这样好吗?
问候所有人