Using conditionals in project's main unit - IDE destroys code

依然范特西╮ 提交于 2019-12-06 02:11:00

As David says, you are stuck with the IDE believing the dpr is its own private backyard. The easiest solution is to just have everything in a separate unit and remove the conditionals from the dpr's uses clause. FastMM will come in handy in your service version as well as in your test app anyway and the distinction between vcl.forms and vcl.svcMgr can be made in that separate unit.

dpr would be reduced to:

uses
  FastMM4,
  YourAppMain,
  uJDRMServer,
  uJDRMSessions,
  uJDRMSvrCli in 'uJDRMSvrCli.pas',
  uJDRMSvrDsh in 'uJDRMSvrDsh.pas',
  JDDB in 'JDDB.pas',
  uJDRMServerTEST in 'uJDRMServerTEST.pas' {JDRMSvrTest},
  uJDRMServerThread in 'uJDRMServerThread.pas',
  uJDRMSvrMessages in 'uJDRMSvrMessages.pas';

{$R *.RES}

begin
  YourAppMain.Execute;
end;

And your main application unit would take the rest of the code from the dpr:

unit YourAppMain;

interface

procedure Execute;

implementation

uses
{$IFDEF TESTAPP}
  Vcl.Forms,
{$ELSE}
  Vcl.SvcMgr,
{$ENDIF TESTAPP}
  OtherUnits;

procedure Execute;
begin
{$IFDEF TESTAPP}
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TJDRMSvrTest, JDRMSvrTest);
{$ELSE}
  if (not Application.DelayInitialize) or (Application.Installing) then
    Application.Initialize;
  Application.CreateForm(TJDRMSvr, JDRMSvr);
{$ENDIF TESTAPP}
  Application.Run;
end;

end.

The simple answer is to just create a different project and use that as the standalone version. This is what I do with my services, and it means you can use other conditionals to suit each mode.

Yes, the IDE does that and always has done. There is no known way to stop it behaving like that. You are just going to have to suck it up.

I have similar conditionals and the way I deal with them is to use my revision control system to help me, at commit time, undo the changes that the IDE makes. So whenever I check in a .dpr file I review the differences and revert the bogus ones.

I also try to add and remove units from the project by editing the .dpr file rather than letting the IDE do it. This tends to reduce the incidence rate of the bogus mods.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!