Question

Trying to make a simple IRC client for personal use so I installed Delphi 7 and Indy 10, note that I haven't done any work in delphi for 10 (?) years and even then it wasn't that advanced. Just for playing around.

procedure TForm1.IRCPrivateMessage(ASender: TIdContext; const ANickname,
  AHost, ATarget, AMessage: String);
begin
  if ATarget = '#channel' then
  begin
    Memo1.Lines.Add('[' + TimeToStr(Time) + '] <' + ANickname + '> ' + Amessage);
  end;
  if ATarget = '#channel2' then
  begin
    Memo2.Lines.Add('[' + TimeToStr(Time) + '] <' + ANickname + '> ' + Amessage);
  end;
end;

This will freeze the program because of two uses of Amessage?

Would be great if anyone could show me a working example of getting time, nick and message added to a memo on the privatemessage event :)

Was it helpful?

Solution

As described in the answer to the question (Delphi 2009) idIRC, MDI, and problems with hanging, IRCPrivateMessage runs in the same thread as the blocking socket. Accessing the GUI from this event handler without proper protection is not allowed.

You need to use Synchronize, Queue or other techniques like posting messages to the main thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top