Changing Deployment Target

Changing Deployment Target

We recommend you to use the SA type of project for development and basic testing of your application. Once the application is ready for deployment (or at least in beta stage), you can then test it in the actual scenario and see how it works. This way, most IntraWeb applications are born as SA and later the developer needs to change the project type. Here’s how you can do it:

1) This is a minimal SA project:

program MyProject;uses IWRtlFix, Forms, IWStart, UTF8ContentParser, Unit8 in ‘Unit8.pas’ {IWForm8: TIWAppForm}, ServerController in ‘ServerController.pas’ {IWServerController: TIWServerControllerBase}, UserSessionUnit in ‘UserSessionUnit.pas’ {IWUserSession: TIWUserSessionBase};{$R *.res}begin TIWStart.Execute(True);end.

2) This is a minimal ISAPI project:

library MyProject;uses IWRtlFix, ISAPIApp, IWInitISAPI, UTF8ContentParser, Unit7 in ‘Unit7.pas’ {IWForm7: TIWAppForm}, ServerController in ‘ServerController.pas’ {IWServerController: TIWServerControllerBase}, UserSessionUnit in ‘UserSessionUnit.pas’ {IWUserSession: TIWUserSessionBase};{$R *.RES}exports GetExtensionVersion, HttpExtensionProc, TerminateExtension;begin IWRun;end.

3) And finally, a minimal IW Lib project:

library MyProject;uses IWRtlFix, ISAPIApp, IWInitISAPI, UTF8ContentParser, Unit7 in ‘Unit7.pas’ {IWForm7: TIWAppForm}, ServerController in ‘ServerController.pas’ {IWServerController: TIWServerControllerBase}, UserSessionUnit in ‘UserSessionUnit.pas’ {IWUserSession: TIWUserSessionBase};{$R *.RES}exports GetExtensionVersion, HttpExtensionProc, TerminateExtension;begin IWRun;end.

You can create a single source file able to compile all 3 types of projects, using conditional compiler directives ($IFDEFS}:

{$DEFINE SA}{.$DEFINE ISAPI}{.$DEFINE IWLIB}{$IFDEF SA}program MyProject;{$ELSE}library MyProject;{$ENDIF}uses IWRtlFix, Forms, {$IFDEF SA} IWStart, {$ENDIF} {$IFDEF ISAPI} ISAPIApp, IWInitISAPI, {$ENDIF} {$IFDEF IWLIB} IW.Export, {$ENDIF} UTF8ContentParser, Unit8 in ‘Unit8.pas’ {IWForm8: TIWAppForm}, ServerController in ‘ServerController.pas’ {IWServerController: TIWServerControllerBase}, UserSessionUnit in ‘UserSessionUnit.pas’ {IWUserSession: TIWUserSessionBase};{$R *.res}{$IFDEF ISAPI}exports GetExtensionVersion, HttpExtensionProc, TerminateExtension;{$ENDIF}begin {$IFDEF ISAPI} IWRun; {$ELSE} {$IFDEF SA} TIWStart.Execute(True); {$ENDIF} {$ENDIF}end.

If you want to deploy as ISAPI, just add a dot in front of {$DEFINE SA} compiler directive (it then becomes {.$DEFINE SA}), and remove the dot in front of {.$DEFINE ISAPI} (it then becomes {$DEFINE ISAPI}), and you are done. Unfortunately, there are a few issues with this approach: Delphi IDE doesn’t handle {$IFDEFs} inside .DPR files well. For instance, even when you change it from “program MyProject” to “library MyProject”, the Delphi IDE still thinks that you have an EXE file. In fact most versions of Delphi will correctly create the associated binary file (EXE or DLL), but I suggest you to test it using your version of Delphi/RAD Studio.

You may also create 2 different projects, one for SA and other for ISAPI or IWLib. The drawback is that everytime you add or remove a unit to/from your project (or change some global option), you have do do it in both projects.