On 2016-04-18 15:27, Yuri wrote:
> I've tried to simplify the logic from your nanoedit.lpr next way:
Yes it can be simplied, depending on what you want to achieve. Nanoedit
is a text editor, so instead of simply denying a second instance, I want
to load the file the second instance attempted to do.
> It does not work: I've got a lot of instances.
I forgot to mention this in my first email... You probably forgot to
create the IPCServer instance in your main form. The IPCServer will be
started by your first instance. All other instances will detect the
server via the IPCClient code (which you already created) and quit, or
as in nanoedit's case, give the server instance the file name to load
and then quit.
The code below could also be simplified to only the StartIPCServer
method - depending on your needs.
------------[ mainform.pas ]------------------
procedure TMainForm.StartIPCServer;
begin
FIPCServer := TSimpleIPCServer.Create(self);
FIPCServer.ServerID := 'nanoedit';
FIPCServer.Global := True;
FIPCServer.StartServer;
fpgApplication.OnIdle := @CheckIPCMessages;
end;
procedure TMainForm.CheckIPCMessages(Sender: TObject);
begin
while FIPCServer.PeekMessage(1, True) do
IPCMessageReceived;
end;
procedure TMainForm.IPCMessageReceived;
begin
case FIPCServer.MsgType of
0:
begin
BringToFront;
end;
1:
begin
LoadFile(FIPCServer.StringMessage);
BringToFront;
end;
end;
end;
------------[ end ]------------------
Regards,
Graeme
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/
My public PGP key: http://tinyurl.com/graeme-pgp
------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
mseide-msegui-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mseide-msegui-talk