1
Good morning,
I am creating a chat system in Delphi, and I am using thread to render the message history without the application blocking. Before several researches, I found one thing here, another there and I adapted my need, however, I have no idea if I finished and cleaned the same from memory, and I need to make that when finishing the execution the same end completely, because this chat system will be integrated into another system, and I am trying my best to avoid an exaggerated consumption.
Here’s the test code I’m using - first time using threads, I don’t even know if I’m using it correctly:
TThreadRenderMsgs = class(TThread)
private
{ Private declarations }
idPrivForm : Integer;
procedure atualizaPanel;
protected
{ Protected declarations }
procedure Execute; override;
public
{ Public declarations }
constructor Create (const CreateSuspended : Boolean);
end;
constructor TThreadRenderMsgs.Create(const CreateSuspended: Boolean);
begin
Self.FreeOnTerminate := True;
inherited Create(CreateSuspended);
end;
procedure TThreadRenderMsgs.atualizaPanel;
var
mensagem : String;
begin
mensagem := 'Teste';
DM_SocketCliente.formClientPrivMsg[idPrivForm].chrChat.Browser.MainFrame.ExecuteJavaScript('addSendMessage(''' + mensagem + ''')', 'about:blank', 0);
end;
procedure TThreadRenderMsgs.Execute;
var
i : Integer;
begin
for i := 0 to 20 do
begin
if Terminated then
Break;
Synchronize(Self.atualizaPanel);
Sleep(1000);
end;
Terminate;
end;
procedure TfrmClientePrivMsg.Button1Click(Sender: TObject);
var
threadRenderMsgs : TThreadRenderMsgs;
begin
threadRenderMsgs := TThreadRenderMsgs.Create(True);
threadRenderMsgs.Start;
threadRenderMsgs.idPrivForm := idMyPrivForm;
end;
thanks, I did some research and I realized that Ttask already met my needs.
– Paulo Vinicius