Autor Beitrag
Ratchet
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Fr 16.04.10 11:25 
Gibt es eine Möglichkeit zwei Direktiven zu prüfen wie es in einer richtigen If-Anweisung auch möglich ist?
Ich könnte natürlich die IFDEFs verschachteln, dann muss ich aber Code doppelt schreiben, was ich vermeiden möchte.

_________________
So long, and thank's for all the fish
<°))))><>
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Fr 16.04.10 12:03 
IFDEFs verschachteln ist die übliche Vorgehensweise. Findet sich quer durch die ganze VCL.

Sowas ist also völlig normal:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
{$IFDEF WIN32}
  {$IFDEF PUREPASCAL}
   //foo
  {$ELSE}
   //bar
  {$ENDIF}
{$ENDIF}

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
Ratchet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Fr 16.04.10 12:09 
Schon klar, aber mir geht es darum doppelten Code zu vermeiden:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
{$IFDEF VER130}
  {$IFDEF SOME_DEF}
    Funktion1;
  {$ELSE}
    Funktion2;
  {$ENDIF}
{$ELSE}
  Funktion1;
{$ENDIF}


Ich will Funktion1 nur einmal im Code haben, denn in Wirklichkeit sind es mehrere Zeilen die gleich wären.

_________________
So long, and thank's for all the fish
<°))))><>
Gammatester
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 328
Erhaltene Danke: 101



BeitragVerfasst: Fr 16.04.10 13:09 
Sieh Dir mal die Onlinehilfe zur IG-Direktive {$IF expression} an. Hier die Einleitung beim englischen Delphi 6:
Zitat:
IF directive

Type Conditional compilation
Syntax {$IF expression}
Remarks

Compiles the source code that follows it if expression is True. expression must conform to Object Pascal syntax and return a Boolean value; it may contain declared constants, constant expressions, and the functions Defined and Declared.
Damit sind da Konstrukte möglich wie:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
const
  a=3;
  b=2;

{$if defined(VER140) or (((a=1) and (b=1)) or (a>0))}
 //foo
{$else}
  bar;
{$ifend}
Ratchet Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 63

Windows7 x86
D5 Ent., D2006 Arch.
BeitragVerfasst: Fr 16.04.10 14:55 
Kann es sein, dass dies mit Delphi 5 noch nicht möglich ist? Finde dazu nichts in der Hilfe und der Compiler verweigert die Arbeit ^^

EDIT: Unter Delphi 2006 habe ich nun was in der Hilfe gefunden, aber das bezieht sich auf C/C++/.NET...

_________________
So long, and thank's for all the fish
<°))))><>


Zuletzt bearbeitet von Ratchet am Fr 16.04.10 15:13, insgesamt 1-mal bearbeitet
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 16.04.10 15:13 
Nein, $IF kam erst mit Delphi 7 oder 2995 IIRC.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8553
Erhaltene Danke: 479

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Fr 16.04.10 15:23 
Ich hab hier grade kein Delphi zur Hand, aber geht nicht sowas?

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
{$IFDEF VER130}
  {$IFDEF SOME_DEF}
    {$DEFINE VER130_AND_SOME_DEF}      
  {$ENDIF}
{$ENDIF}


Dann kannst du den Fall für Funktion1 über die neue Def behandeln, und du hast den Code nur einmal. Das machen afaik auch die Jedis so.

_________________
We are, we were and will not be.