AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Bedingt Prozedur aufrufen

Ein Thema von CRoSSi · begonnen am 24. Jan 2008 · letzter Beitrag vom 1. Feb 2008
Antwort Antwort
Seite 1 von 4  1 23     Letzte »    
CRoSSi

Registriert seit: 24. Jan 2008
11 Beiträge
 
#1

Bedingt Prozedur aufrufen

  Alt 24. Jan 2008, 09:10
Hallo,
ich bin neu hier und habe mal ne frage..

weiß jemand wie man eine prozedur bedingt einbinden kann? Also wie man sie aufruft weiß ich, das ist nicht das Problem.
hatte mir das so ca vorgestellt: if var=1 then procedure usw.. hoffe mein Problem ist nachvollziehbar.

Danke schonmal für antworten
Christoph
Alles ist relativ..
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.541 Beiträge
 
Delphi 11 Alexandria
 
#2

Re: Bedingt Prozedur aufrufen

  Alt 24. Jan 2008, 09:12
Meinst Du so?
Delphi-Quellcode:
if var = 1 then
  Machwas
else
  MachwasAnderes;
P.S.: Willkommen in der DP
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
CRoSSi

Registriert seit: 24. Jan 2008
11 Beiträge
 
#3

Re: Bedingt Prozedur aufrufen

  Alt 24. Jan 2008, 09:27
ne das ist ja klar.. man muss die przedur doch definiern, sodass man die aufrufen kann.. und ich meien die definition dass man die irgendwie in ne if packt. Konkret würde ich des so meinen:

Delphi-Quellcode:
if var=1 then
   begin
   procedure PortOut(Port : Word; Data : Byte);stdcall; external 'io.dll';
   end;
Bekomme sonst ne Fehlermeldung wo der port Treiber nicht installiert ist.
Alles ist relativ..
  Mit Zitat antworten Zitat
Benutzerbild von Die Muhkuh
Die Muhkuh

Registriert seit: 21. Aug 2003
7.332 Beiträge
 
Delphi 2009 Professional
 
#4

Re: Bedingt Prozedur aufrufen

  Alt 24. Jan 2008, 09:30
Dann musst Du die externen Funktionsaufrufe dynamisch laden und vorher prüfen, ob die Porttreiber installiert sind.

Das, was Du jetzt meinst, wird so nicht funktionieren.
  Mit Zitat antworten Zitat
Klaus01

Registriert seit: 30. Nov 2005
Ort: München
5.755 Beiträge
 
Delphi 10.4 Sydney
 
#5

Re: Bedingt Prozedur aufrufen

  Alt 24. Jan 2008, 09:33
Guten Morgen,

vielleicht kannst Du mit defines arbeiten:

Zitat von DelphiHilfe:
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.
For example,

{$DEFINE CLX}

const LibVersion = 2.1;

{$IF Defined(CLX) and (LibVersion > 2.0) }
... // this code executes
{$ELSE}
... // this code doesn't execute

{$IFEND}

{$IF Defined(CLX) }
... // this code executes
{$ELSEIF LibVersion > 2.0}
... // this code doesn't execute
{$ELSEIF LibVersion = 2.0}
... // this code doesn't execute
{$ELSE}
... // this code doesn't execute
{$IFEND}

The special functions Defined and Declared are available only within $IF and $ELSEIF blocks. Defined returns True if the argument passed to it is a defined conditional symbol. Declared returns True if the argument passed to it is a valid declared Pascal identifier visible within the current scope.

The $IF and $ELSEIF directives are terminated with $IFEND, unlike other conditional directives that use the $ENDIF terminator. This allows you to hide $IF blocks from earlier versions of the compiler (which do not support $IF or $ELSEIF) by nesting them within old-style $IFDEF blocks. For example, the following construction would not cause a compilation error:

{$UNDEF NewEdition}

{$IFDEF NewEdition}
{$IF LibVersion > 2.0}
...
{$IFEND}
{$ENDIF}

$IF supports evaluation of typed constants, but the compiler doesn't allow typed constants within constant expressions. As a result,

const Test: Integer = 5;

{$IF SizeOf(Test) > 2}

...

is valid, while

const Test: Integer = 5;

{$IF Test > 2 } // error

...

generates a compilation error.

If your code needs to be portable between various versions of Delphi (as well as Kylix), you will need to test whether or not this directive is supported by the compiler. You can surround your code with the following directives:

$IFDEF conditionalexpressions

. // code including IF directive
. // only executes if supported
$ENDIF
Klaus
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.541 Beiträge
 
Delphi 11 Alexandria
 
#6

Re: Bedingt Prozedur aufrufen

  Alt 24. Jan 2008, 09:33
Schau Dir dazu mal z.B. diesen Thread an.

[edit] @Klaus: Ich denke, bedingte Kompilierung ist nicht das, was er sucht. [/edit]
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Benutzerbild von Die Muhkuh
Die Muhkuh

Registriert seit: 21. Aug 2003
7.332 Beiträge
 
Delphi 2009 Professional
 
#7

Re: Bedingt Prozedur aufrufen

  Alt 24. Jan 2008, 09:35
Klaus,

das geht leider nicht, da er mit den DEFINES nicht überprüfen kann, ob die Porttreiber installiert sind
  Mit Zitat antworten Zitat
CRoSSi

Registriert seit: 24. Jan 2008
11 Beiträge
 
#8

Re: Bedingt Prozedur aufrufen

  Alt 24. Jan 2008, 09:36

wie mache ich das?
mir reicht das schon wenn var=1 ist dass er dann die die funktion aufruft? weil var ist entweder 1 oder 0 bei 0 soll er einfach weiter machen und bei 1 soll die funktion geladen werden. Mehr brauche ich ja nicht. Das würde locker reichen.. Aber da ist das große fragezeichen wie macht man sowas am besten?

thx schonmal
Alles ist relativ..
  Mit Zitat antworten Zitat
oki

Registriert seit: 30. Dez 2002
Ort: Brandshagen
1.819 Beiträge
 
Delphi 2007 Professional
 
#9

Re: Bedingt Prozedur aufrufen

  Alt 24. Jan 2008, 09:41
Zitat von CRoSSi:
weil var ist entweder 1 oder 0 bei 0 soll er einfach weiter machen und bei 1 soll die funktion geladen werden. Mehr brauche ich ja nicht. Das würde locker reichen.. Aber da ist das große fragezeichen wie macht man sowas am besten?

thx schonmal
Was heißt bei dir geladen? Du meinst nicht zufällig ausführen?

Wenn Die Funktion geladen werden soll (aus DLL?), dann mußt du sie wie vorher schon gesagt dynamisch einbinden. Gib aber erst mal mehr Infos was du mit laden meinst.

Gruß oki

[edit] Sorry, hatte den zweiten Post übersehen. Also aus DLL! Dann mußt du dynamisch laden und vor der Procedurezuweisung prüfen. [/edit]
42
  Mit Zitat antworten Zitat
Benutzerbild von DeddyH
DeddyH

Registriert seit: 17. Sep 2006
Ort: Barchfeld
27.541 Beiträge
 
Delphi 11 Alexandria
 
#10

Re: Bedingt Prozedur aufrufen

  Alt 24. Jan 2008, 09:43
Schau Dir entweder meinen verlinkten Thread an oder arbeite dieses Tutorial von Olli mal durch.
Detlef
"Ich habe Angst vor dem Tag, an dem die Technologie unsere menschlichen Interaktionen übertrumpft. Die Welt wird eine Generation von Idioten bekommen." (Albert Einstein)
Dieser Tag ist längst gekommen
  Mit Zitat antworten Zitat
Antwort Antwort
Seite 1 von 4  1 23     Letzte »    


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:54 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz