Delphi-PRAXiS
Seite 1 von 2  1 2      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi If not XY in [...] mit reellen Typen (https://www.delphipraxis.net/46370-if-not-xy-%5B-%5D-mit-reellen-typen.html)

engine 23. Mai 2005 21:42


If not XY in [...] mit reellen Typen
 
Hallo DP,

ich muss einen Radius mit einer Werkzeugliste vergleichen.
Wenn der "Radius" nicht in der Liste vorhanden ist, soll ein Fehler ausgegeben werden.
Zur Zeit verwende ich diesen Code.

Delphi-Quellcode:
var
  Radius : extended;
.
.
.

Radius := StrToFloat(Form1.StringGrid1.Cells[4, i]);
if Radius <> 3.4 then
  if Radius <> 4.25 then
    if Radius <> 5.1 then
      if Radius <> 6 then
        if Radius <> 7 then
          if Radius <> 8.75 then
            if Radius <> 10.5 then
              if Radius <> 13.25 then
                if Radius <> 16 then
                begin
                  Form1.StringGrid1.Cells[9, i] := 'ERROR';
                end;
Der Code funktioniert, die Schreibweise gefällt mir jedoch nicht.
Ich suche eher etwas wie
Delphi-Quellcode:
if not (Radius in [1,2,3]) then ...
Habt ihr eine Idee wie der Code vereinfacht werden kann?

Hansa 23. Mai 2005 21:47

Re: If not XY in [...] mit reellen Typen
 
Das ist "Case". -> OH

JasonDX 23. Mai 2005 21:58

Re: If not XY in [...] mit reellen Typen
 
Zitat:

Zitat von Hansa
Das ist "Case". -> OH

Case funktioniert auch nur mit ordinalen Typen, also nicht mit beispielsweise strings oder floats (=reals)

Was du (mal ganz spezifisch den fall betrachtet) tun könntest wäre folgendes:
statt
Delphi-Quellcode:
Radius := StrToFloat(Form1.StringGrid1.Cells[4, i]);
if Radius <> 3.4 then
  if Radius <> 4.25 then
    if Radius <> 5.1 then
      if Radius <> 6 then
        if Radius <> 7 then
          if Radius <> 8.75 then
            if Radius <> 10.5 then
              if Radius <> 13.25 then
                if Radius <> 16 then
                begin
                  Form1.StringGrid1.Cells[9, i] := 'ERROR';
                end;
dasda
Delphi-Quellcode:
Radius: integer;
Radius := round(StrToFloat(Form1.StringGrid1.Cells[4, i]) * 100);
if not (Radius in [340, 425, 510, 600, 700, 875, 1050, 1325, 1600]) then
  Form1.StringGrid1.Cells[9, i] := 'ERROR';
schreiben

Oder du schreibst dir eine Funktion:
Delphi-Quellcode:
function IsWertIn(Wert: extended; Werte: array of extended): boolean;
begin
  result := true;
  for i := 0 to high(Werte) do
    if Wert = Werte[i] then //vorsicht hier: extendeds vergleichen sollte man nicht, sondern mit einer abweichung von +/- 0.josef vergleichen
      exit;
  result := false;
end;

engine 23. Mai 2005 21:58

Re: If not XY in [...] mit reellen Typen
 
Zitat:

Zitat von Hansa
Das ist "Case". -> OH

Ja, "Case" funktioniert prima mit Ordinale Typen, aber nicht mit "extended".

engine 23. Mai 2005 22:10

Re: If not XY in [...] mit reellen Typen
 
Delphi-Quellcode:
Radius: integer;
Radius := round(StrToFloat(Form1.StringGrid1.Cells[4, i]) * 100);
if not (Radius in [340, 425, 510, 600, 700, 875, 1050, 1325, 1600]) then
  Form1.StringGrid1.Cells[9, i] := 'ERROR';
Das sieht gut aus...

Danke

DGL-luke 23. Mai 2005 22:36

Re: If not XY in [...] mit reellen Typen
 
Zitat:

+/- 0.josef
AHA?! :gruebel:
also wenn du +/-.adolf geschrieben hättest, würd ich mir ja sorgen um dich machen, Chimaira, aber so hab ich einfach null ahung, was du meinst....

Nicodius 23. Mai 2005 22:38

Re: If not XY in [...] mit reellen Typen
 
wen ner aus österreich kommt hats ne bedeutung :)


sagt man so 0 komma josef ;)

leddl 23. Mai 2005 22:39

Re: If not XY in [...] mit reellen Typen
 
Er hätte auch +/- 0.x schreiben können. Hauptsache, du gibst ein bestimmtes Intervall an, in dem sich die Werte befinden müssen.

DGL-luke 23. Mai 2005 22:46

Re: If not XY in [...] mit reellen Typen
 
ah sehr schön. muss ich doch noch ne fremdsprache lernen. :lol:

Nicodius 23. Mai 2005 22:48

Re: If not XY in [...] mit reellen Typen
 
abseits noch ne frage


ordinal und primitiv ist dasselbe oder?


Alle Zeitangaben in WEZ +1. Es ist jetzt 15:36 Uhr.
Seite 1 von 2  1 2      

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz