Delphi-PRAXiS
Seite 1 von 3  1 23      

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Befehl kürzen (https://www.delphipraxis.net/108278-befehl-kuerzen.html)

R34DM3 10. Feb 2008 19:23


Befehl kürzen
 
moin zusammen,

kennt jemand ne möglichkeit diesen code:

Delphi-Quellcode:
     if (gb19.Caption = Fahrzeug1.fkennung) and ((btbg19.Caption <> '4') or (falscherstatus = false) or (btbg19.Caption <> '6') or (btbg19.Caption <> '7') or (btbg19.Caption <> '8') or (btbg19.Caption <> '3') ) then btbg19.Caption := '3' else if (gb20.Caption = Fahrzeug4.fkennung) and (btbg19.Caption = '1') or (btbg19.Caption = '2') or (btbg19.Caption = '5') then falscherstatus := true;
     if (gb19.Caption = Fahrzeug2.fkennung) and ((btbg19.Caption <> '4') or (falscherstatus = false) or (btbg19.Caption <> '6') or (btbg19.Caption <> '7') or (btbg19.Caption <> '8') or (btbg19.Caption <> '3') ) then btbg19.Caption := '3' else if (gb20.Caption = Fahrzeug4.fkennung) and (btbg19.Caption = '1') or (btbg19.Caption = '2') or (btbg19.Caption = '5') then falscherstatus := true;
     if (gb19.Caption = Fahrzeug3.fkennung) and ((btbg19.Caption <> '4') or (falscherstatus = false) or (btbg19.Caption <> '6') or (btbg19.Caption <> '7') or (btbg19.Caption <> '8') or (btbg19.Caption <> '3') ) then btbg19.Caption := '3' else if (gb20.Caption = Fahrzeug4.fkennung) and (btbg19.Caption = '1') or (btbg19.Caption = '2') or (btbg19.Caption = '5') then falscherstatus := true;
     if (gb19.Caption = Fahrzeug4.fkennung) and ((btbg19.Caption <> '4') or (falscherstatus = false) or (btbg19.Caption <> '6') or (btbg19.Caption <> '7') or (btbg19.Caption <> '8') or (btbg19.Caption <> '3') ) then btbg19.Caption := '3' else if (gb20.Caption = Fahrzeug4.fkennung) and (btbg19.Caption = '1') or (btbg19.Caption = '2') or (btbg19.Caption = '5') then falscherstatus := true;

     if (gb20.Caption = Fahrzeug1.fkennung) and ((btbg20.Caption <> '4') or (falscherstatus = false) or (btbg20.Caption <> '6') or (btbg20.Caption <> '7') or (btbg20.Caption <> '8') or (btbg20.Caption <> '3') ) then btbg20.Caption := '3' else if (gb20.Caption = Fahrzeug4.fkennung) and (btbg20.Caption = '1') or (btbg20.Caption = '2') or (btbg20.Caption = '5') then falscherstatus := true;
     if (gb20.Caption = Fahrzeug2.fkennung) and ((btbg20.Caption <> '4') or (falscherstatus = false) or (btbg20.Caption <> '6') or (btbg20.Caption <> '7') or (btbg20.Caption <> '8') or (btbg20.Caption <> '3') ) then btbg20.Caption := '3' else if (gb20.Caption = Fahrzeug4.fkennung) and (btbg20.Caption = '1') or (btbg20.Caption = '2') or (btbg20.Caption = '5') then falscherstatus := true;
     if (gb20.Caption = Fahrzeug3.fkennung) and ((btbg20.Caption <> '4') or (falscherstatus = false) or (btbg20.Caption <> '6') or (btbg20.Caption <> '7') or (btbg20.Caption <> '8') or (btbg20.Caption <> '3') ) then btbg20.Caption := '3' else if (gb20.Caption = Fahrzeug4.fkennung) and (btbg20.Caption = '1') or (btbg20.Caption = '2') or (btbg20.Caption = '5') then falscherstatus := true;
     if (gb20.Caption = Fahrzeug4.fkennung) and ((btbg20.Caption <> '4') or (falscherstatus = false) or (btbg20.Caption <> '6') or (btbg20.Caption <> '7') or (btbg20.Caption <> '8') or (btbg20.Caption <> '3') ) then btbg20.Caption := '3' else if (gb20.Caption = Fahrzeug4.fkennung) and (btbg20.Caption = '1') or (btbg20.Caption = '2') or (btbg20.Caption = '5') then falscherstatus := true;
is eine procedure oder sowas zu stecken um ihn kürzer zu machen?! ^^

schonmal danke im vorraus
mfg markus

Namenloser 10. Feb 2008 19:26

Re: Befehl kürzen
 
Entschuldigung, aber HÄ? :stupid:
In dem Code versteht man echt nichts... beschreib mal bitte, was der tut.

mkinzler 10. Feb 2008 19:33

Re: Befehl kürzen
 
Du kannst ja erst mal die identischen Vergleich durchführen und dann nur noch die Unterschiede

DeddyH 10. Feb 2008 19:34

Re: Befehl kürzen
 
Lagere doch erstmal die ganzen wiederkehrenden Abfragen in eine eigene Funktion aus. Bsp:
Delphi-Quellcode:
(btbg19.Caption <> '4') or (falscherstatus = false) or (btbg19.Caption <> '6') or (btbg19.Caption <> '7') or (btbg19.Caption <> '8') or (btbg19.Caption <> '3')

omata 10. Feb 2008 20:45

Re: Befehl kürzen
 
Wenn man sich mal die Mühe macht und diese Textwüste ordentlich einrückt...

Delphi-Quellcode:
if    (gb19.Caption = Fahrzeug1.fkennung)
   and (   (btbg19.Caption <> '4')
        or (falscherstatus = false)
        or (btbg19.Caption <> '6')
        or (btbg19.Caption <> '7')
        or (btbg19.Caption <> '8')
        or (btbg19.Caption <> '3') ) then
begin
  btbg19.Caption := '3';
end
else if    (gb20.Caption = Fahrzeug4.fkennung)
        and (btbg19.Caption = '1') or (btbg19.Caption = '2') or (btbg19.Caption = '5') then
begin
  falscherstatus := true;
end;

if    (gb19.Caption = Fahrzeug2.fkennung)
   and (   (btbg19.Caption <> '4')
        or (falscherstatus = false)
        or (btbg19.Caption <> '6')
        or (btbg19.Caption <> '7')
        or (btbg19.Caption <> '8')
        or (btbg19.Caption <> '3') ) then
begin
  btbg19.Caption := '3';
end
else if    (gb20.Caption = Fahrzeug4.fkennung)
        and (btbg19.Caption = '1') or (btbg19.Caption = '2') or (btbg19.Caption = '5') then
begin
  falscherstatus := true;
end;

if    (gb19.Caption = Fahrzeug3.fkennung)
   and (   (btbg19.Caption <> '4')
        or (falscherstatus = false)
        or (btbg19.Caption <> '6')
        or (btbg19.Caption <> '7')
        or (btbg19.Caption <> '8')
        or (btbg19.Caption <> '3') ) then
begin
  btbg19.Caption := '3';
end
else if    (gb20.Caption = Fahrzeug4.fkennung)
        and (btbg19.Caption = '1') or (btbg19.Caption = '2') or (btbg19.Caption = '5') then
begin
  falscherstatus := true;
end;

if    (gb19.Caption = Fahrzeug4.fkennung)
   and (   (btbg19.Caption <> '4')
        or (falscherstatus = false)
        or (btbg19.Caption <> '6')
        or (btbg19.Caption <> '7')
        or (btbg19.Caption <> '8')
        or (btbg19.Caption <> '3') ) then
begin
  btbg19.Caption := '3';
end
else if    (gb20.Caption = Fahrzeug4.fkennung)
        and (btbg19.Caption = '1') or (btbg19.Caption = '2') or (btbg19.Caption = '5') then
begin
  falscherstatus := true;
end;

if    (gb20.Caption = Fahrzeug1.fkennung)
   and (   (btbg20.Caption <> '4')
        or (falscherstatus = false)
        or (btbg20.Caption <> '6')
        or (btbg20.Caption <> '7')
        or (btbg20.Caption <> '8')
        or (btbg20.Caption <> '3') ) then
begin
  btbg20.Caption := '3';
end
else if    (gb20.Caption = Fahrzeug4.fkennung)
        and (btbg20.Caption = '1') or (btbg20.Caption = '2') or (btbg20.Caption = '5') then
begin
  falscherstatus := true;
end;

if    (gb20.Caption = Fahrzeug2.fkennung)
   and (   (btbg20.Caption <> '4')
        or (falscherstatus = false)
        or (btbg20.Caption <> '6')
        or (btbg20.Caption <> '7')
        or (btbg20.Caption <> '8')
        or (btbg20.Caption <> '3') ) then
begin
  btbg20.Caption := '3';
end
else if    (gb20.Caption = Fahrzeug4.fkennung)
        and (btbg20.Caption = '1') or (btbg20.Caption = '2') or (btbg20.Caption = '5') then
begin
  falscherstatus := true;
end;

if     (gb20.Caption = Fahrzeug3.fkennung)
    and (   (btbg20.Caption <> '4')
         or (falscherstatus = false)
         or (btbg20.Caption <> '6')
         or (btbg20.Caption <> '7')
         or (btbg20.Caption <> '8')
         or (btbg20.Caption <> '3') ) then
begin
  btbg20.Caption := '3';
end
else if    (gb20.Caption = Fahrzeug4.fkennung)
        and (btbg20.Caption = '1') or (btbg20.Caption = '2') or (btbg20.Caption = '5') then
begin
  falscherstatus := true;
end;

if    (gb20.Caption = Fahrzeug4.fkennung)
   and (   (btbg20.Caption <> '4')
        or (falscherstatus = false)
        or (btbg20.Caption <> '6')
        or (btbg20.Caption <> '7')
        or (btbg20.Caption <> '8')
        or (btbg20.Caption <> '3') ) then
begin
  btbg20.Caption := '3';
end
else if    (gb20.Caption = Fahrzeug4.fkennung)
        and (btbg20.Caption = '1') or (btbg20.Caption = '2') or (btbg20.Caption = '5') then
begin
  falscherstatus := true;
end;
dann kann man vielleicht schon mehr erkennen.
Allerdings nur vielleicht, in Wirklichkeit wird einem dann erst das ganze schreckliche Ausmaß klar und man sollte sich diesem Code vermutlich doch nicht weiter annähren als, naja, sagen wir mal 1km.

Was mich besonders stutzig macht, sind diese komischen...
Delphi-Quellcode:
else if    (gb20.Caption = Fahrzeug4.fkennung)
        and (btbg20.Caption = '1') or (btbg20.Caption = '2') or (btbg20.Caption = '5') then
AND- und OR-Verknüpfungen. Fehlt da nicht eventuell noch ein Klammerpaar?

Also so...
Delphi-Quellcode:
else if    (gb20.Caption = Fahrzeug4.fkennung)
        and ((btbg20.Caption = '1') or (btbg20.Caption = '2') or (btbg20.Caption = '5')) then
?

Ich sehe da noch viel mehr Problemstellen, lass es aber jetzt mal dabei.
Sorry, aber da vergeht einem ja echt jeglicher Spass am Programmieren.

Traurige Grüsse
Thorsten

omata 10. Feb 2008 21:22

Re: Befehl kürzen
 
Hier doch nochmal ein Vorschlag...

Delphi-Quellcode:
type
  TMyResult = (_None, _True, _False);

function Test(FahrzeugkennungA, FahrzeugkennungB,
              CaptionA, CaptionB, CaptionC:string;
              falscherstatus:boolean):TMyResult;
begin
  Result:=_None;
  if    (CaptionA = FahrzeugkennungA)
     and (   (CaptionB <> '4')
          or (CaptionB <> '6')
          or (CaptionB <> '7')
          or (CaptionB <> '8')
          or (CaptionB <> '3')
          or not falscherstatus) then
  begin
    Result:=_True;
  end
  else if    (CaptionC = FahrzeugkennungB)
          and ((CaptionA = '1') or (CaptionA = '2') or (CaptionA = '5')) then
  begin
    Result:=_False;
  end;
end;

procedure TForm.Proc(var status:boolean);
var F4K, CapA, CapC:string;
begin
  F4K:=Fahrzeug4.fkennung;
  CapA:=gb19.Caption;
  CapC:=gb20.Caption;
  case Test(Fahrzeug1.fkennung, F4K, CapA, btbg19.Caption, CapC, status) of
    _True: btbg19.Caption:='3';
    _False: status:=true;
  end;
  case Test(Fahrzeug2.fkennung, F4K, CapA, btbg19.Caption, CapC, status) of
    _True: btbg19.Caption:='3';
    _False: status:=true;
  end;
  case Test(Fahrzeug3.fkennung, F4K, CapA, btbg19.Caption, CapC, status) of
    _True: btbg19.Caption:='3';
    _False: status:=true;
  end;
  case Test(Fahrzeug4.fkennung, F4K, CapA, btbg19.Caption, CapC, status) of
    _True: btbg19.Caption:='3';
    _False: status:=true;
  end;

  CapA:=gb20.Caption;
  CapC:=gb20.Caption;
  case Test(Fahrzeug1.fkennung, F4K, CapA, btbg20.Caption, CapC, status) of
    _True: btbg20.Caption:='3';
    _False: status:=true;
  end;
  case Test(Fahrzeug2.fkennung, F4K, CapA, btbg20.Caption, CapC, status) of
    _True: btbg20.Caption:='3';
    _False: status:=true;
  end;
  case Test(Fahrzeug3.fkennung, F4K, CapA, btbg20.Caption, CapC, status) of
    _True: btbg20.Caption:='3';
    _False: status:=true;
  end;
  case Test(Fahrzeug4.fkennung, F4K, CapA, btbg20.Caption, CapC, status) of
    _True: btbg20.Caption:='3';
    _False: status:=true;
  end;
end;
Nicht schön, aber selten...

DeddyH 10. Feb 2008 21:30

Re: Befehl kürzen
 
Zitat:

Delphi-Quellcode:
type
  TMyResult = (_None, _True, _False);

Klingt für mich nach FemaleBool: Yes, No, MayBe ;)

omata 10. Feb 2008 21:35

Re: Befehl kürzen
 
Naja, schau dir den Quellcode oben mal an. Da hier leider schreibend auf die Komponenten der Form zugegriffen wird und das leider mit TCaption über einen Referenzparameter nicht geht, musste ich mir hier etwas anderes einfallen lassen.

Bin aber auf andere Lösungen auch sehr gespannt...

fLaSh11 10. Feb 2008 21:45

Re: Befehl kürzen
 
[ot]
Sag mal, wir das ein BOS-Funk-Tool :stupid:
[/ot]

omata 10. Feb 2008 21:49

Re: Befehl kürzen
 
Ich weiss, deine Frage geht nicht an mich. Aber meine geht an dich.

Hört sich ja wirklich spannend an. Was ist das? Habe nur dies gefunden hier.

Sorry, bin eben zu blöd dafür.


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:24 Uhr.
Seite 1 von 3  1 23      

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