Michael Van Canneyt wroteI have several remarks:
a) Your TBaseSingleInstance class contains too many methods.
It assumes you are using advancedipc.
I refactored TBaseSingleInstance so that it doesn't depend on advancedipc.
I suggest refactoring such a way that advancedipc is in the
implementation section of the class.
This is unfortunately not possible now because there are no interfaces (nor abstract classes) for TIPCServer and TIPCClient. IMO this is not a problem, if you don't want singleinstance.pp to be dependent on advancedipc.pp at all, TAdvancedSingleInstance can be easily moved into another unit - e.g. "advancedsingleinstance.pp". CustApp.pp will need to use "advancedsingleinstance.pp" in implementation section then.
If you want to have abstract classes for TIPCServer and TIPCClient, advancedipc.pp would need a bigger refactoring. Adding interfaces for them seems to be a simpler and better solution for me. - But as I said before, IMO neither interfaces nor abstract classes are needed for now. TBaseSingleInstance already introduces the bare minimum of methods needed.
or introduce TAbstractSingleInstance as a parent of
TBaseSingleInstance with the bare minimum of methods/properties.
TBaseSingleInstance is now such "TAbstractSingleInstance". You can rename it to TAbstractSingleInstance if you like.
Show quoted text 6 lines
b) There is no way to have TCustomApplication create a different
singleinstance class, for 2 reasons:
1. Your property is declared as TCustomSingleInstance.
It should be TBaseSingleInstance (or TAbstractSingleInstance)
That means that the 'enabled' property should be in
TBaseSingleInstance or TAbstractSingleInstance.
The Enabled property doesn't belong into TBaseSingleInstance - it has a meaning only in TCustomApplication. I solved it by introducing SingleInstanceEnabled in TCustomApplication.
2. You create the instance as TCustomSingleInstance.Create in the
constructor.
It should be a function CreateSingleinstance :
TCustomSingleInstance;
I solved it by introducing SingleInstanceClass. IMO it's better because SingleInstanceClass can be easily changed without the need to create a new TCustomApplication descendant and override a virtual function.
Feel free to comment on my changes.
BTW, there are some compiler hints/warnings in CustApp.pp. At least the one warning should be solved, IMO:
Compile Project, Target: sitest.exe: Success, Warnings: 1, Hints: 8
custapp.pp(175,6) Note: Local variable "l" is assigned but never used
custapp.pp(57,21) Hint: Parameter "EventType" not used
custapp.pp(57,51) Hint: Parameter "Msg" not used
custapp.pp(391,25) Hint: Local variable "B" does not seem to be initialized
custapp.pp(408,29) Warning: Local variable "I" does not seem to be
initialized
custapp.pp(408,27) Hint: Local variable "B" does not seem to be initialized
custapp.pp(453,30) Hint: Local variable "B" does not seem to be initialized
custapp.pp(502,31) Hint: Local variable "B" does not seem to be initialized
custapp.pp(524,8) Note: Local variable "SO" is assigned but never used
Ondrej