简体   繁体   中英

Delphi 7 Indy 10 ioHandler

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 :)

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM