Frage

Okay, also ich habe 2 Projekte für ein Spiel. Eine davon ist der Server und ist der Kunde. Ich halte die gemeinsame Einheiten in einen freigegebenen Ordner, dass ich in meinem Client / Server-Projekt verwenden aufzunehmen. Es gibt ein Problem aber: Ich habe eine Shared-Datei, die eine andere Datei für Client / Server benötigt. Beispiel: mySharedLib muss auf der Konsole, aber der Client / Server-Konsole unterscheidet sich drucken. Was sind meine Optionen? Dank

War es hilfreich?

Lösung

In your shared file you could use define compiler directive

For example

{$IFDEF MYSERVER}
    Writeln('Server');  // this code executes
{$ELSE}
    Writeln('Client');  // this code does not execute
{$ENDIF}

Then in your server project define a MYSERVER define and in your client define a MYCLIENT one, then when the shared code seperates use an {$IFDEF) statement.

From the Delphi help on conditional definitions:

The conditional directives $IFDEF, $IFNDEF, $IF, $ELSEIF, $ELSE, $ENDIF, and $IFEND allow you to compile or suppress code based on the status of a conditional symbol. $IF and $ELSEIF allow you to base conditional compilation on declared Delphi identifiers. $IFOPT compiles or suppresses code depending on whether a specified compiler switch is enabled.

This will not however work if the shared code is in a DLL or any other sort of complied shared resource such as a package.

From the Delphi help on conditional definitions:

Conditional definitions are evaluated only when source code is recompiled. If you change a conditional symbol's status and then rebuild a project, source code in unchanged units may not be recompiled. Use Project|Build All Projects to ensure everything in your project reflects the current status of conditional symbols.

Andere Tipps

If they're different, they're not really a shared file anymore.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top