Problems with TIdNotify

Giganews Newsgroups
Subject: Problems with TIdNotify
Posted by:  Michal Hruby (mh…@zoznam.sk)
Date: Tue, 06 Feb 2007

Hello, I'd like to ask if this is correct way to use TIdNotify class.

  TListBoxNotify = class(TIdNotify)
  private
    FText: WideString;
  protected
    procedure DoNotify; override;
  public
    class procedure AddItemToListBox(Text: WideString);
  end;

procedure TListBoxNotify.DoNotify;
begin
  MainWindow.TntListBox1.Items.Add(TimeToStr(Now)+' '+FText);
end;

class procedure TListBoxNotify.AddItemToListBox(Text: WideString);
begin
  with Create do begin
    FText := Text;
    Notify;
  end;
end;

// usage in TCPServer onExecute:
TListBoxNotify.AddItemToListBox(WideFormat(_('Uploaded %s to %s'),
[UTF8Decode(filename), AContext.Connection.Socket.Binding.PeerIP]));

The reason why I'm asking is because sometimes I see two *same* lines in
the listbox (while sometimes not even one, and of course everything is
working fine if running with Delphi debugger), and I'm 100% sure that
the AddItemToListBox in onExecute event is called only once. Any
suggestions? (tried with latest Indy snapshot)

Replies