![]() |
Doppelten Code vermeiden?
moin,
Delphi-Quellcode:
procedure blubb(b: boolean);
begin case b of true: if irgendwas then begin DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); end; false: if sonstwas then begin DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); end; end; end; die 2 case teile unterscheiden sich NUR von der if abfrage, kann ich den code nicht irgendwie kleiner machen? die prozeduren innerhalb der cases sind 100% gleich |
Re: Doppelten Code vermeiden?
das wird ja immer ausgeführt, da boolean ja nur true oder false sein kann?!
/edit: sry, hab das irgendwas/sonstwas überlesen! dann pack halt den teil den du doppelt hast in eine eigene funktion! oder mach das so:
Delphi-Quellcode:
if (b and irgndwas) or ((not b) and sontwas) then
... |
Re: Doppelten Code vermeiden?
Delphi-Quellcode:
procedure blubb(b: boolean);
begin if ((b) and (irgendwas)) or ((not b) and (sonstwas)) then begin DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); end; end; |
Re: Doppelten Code vermeiden?
ahhh, danke (habs), 8)
|
Re: Doppelten Code vermeiden?
hmm? ich glaub, ich hab in Info mal zuviel aufgepasst :roll:
Code:
[s]// (a and b) or (-a and b) ... (a and b) or (c and b)
if (b and irgndwas) or ((not b) and sontwas) then // Regel: (a and b) or (c and b) = (a or c) and b // (a or c) and b if (b or (not b)) and sontwas then // Regel: a or -a = 1 // 1 and b if true and sontwas then // Regel: 1 and b = b // b if sontwas then[/s] |
Re: Doppelten Code vermeiden?
Hallo,
Zitat:
|
Re: Doppelten Code vermeiden?
stümmt :wall:
's war wohl noch zu früh ... irgendwas <> sonstwas ... 's sah heute früh irgendwie noch gleich aus :oops: dann hat der Stefan halt weiterhin die beste Lösung :angel2: |
Re: Doppelten Code vermeiden?
Also ich würde das wie Stefan machen:
Delphi-Quellcode:
mfg, mh166
procedure blubb(b: boolean);
procedure EverytimeTheSameShit; begin DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); DoSomething(); end; begin case b of true: if irgendwas then begin EverytimeTheSameShit; end; false: if sonstwas then begin EverytimeTheSameShit; end; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:43 Uhr. |
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