![]() |
Re: Sinnvoller Einsatz von goto
Zitat:
|
Re: Sinnvoller Einsatz von goto
Zitat:
Zitat:
|
Re: Sinnvoller Einsatz von goto
Delphi-Quellcode:
@Roter Kasten fehlt: Oh, war jmd. schneller :|
// Prüft, ob eine Datei für den Import vorhanden ist.
// Falls nicht, kann der Benutzer entscheiden, was passieren soll function CheckImportFile(const fname: TFilename; const Caption:string): Boolean; var msg: string; begin Result := false; repeat if not FileExists(fname) then msg := Format('Datei <%s> ist nicht vorhanden', [fname]) else if FileGetSize(fname) = 0 then msg := Format('Datei <%s> ist leer', [fname]) else msg := ''; if msg <> '' then begin case MessageBox(0, PChar(msg), PChar(Caption), MB_ICONWARNING or MB_ABORTRETRYIGNORE or MB_SETFOREGROUND) of idAbort: Abort; // stille Exception idIgnore: Exit; // idRetry: // noch ne Runde; end; end else Result := True; // Datei vorhanden und nicht leer until Result = true; end; |
Re: Sinnvoller Einsatz von goto
Delphi-Quellcode:
es geht aber auch ein while Result do begin ... end;
function CheckImportFile(const fname: TFilename; const Caption:string): Boolean;
var msg: string; begin Result := True; // Datei vorhanden und nicht leer repeat if not FileExists(fname) then msg := Format('Datei <%s> ist nicht vorhanden', [fname]) else if FileGetSize(fname) = 0 then msg := Format('Datei <%s> ist leer', [fname]) else Break; case MessageBox(0, PChar(msg), PChar(Caption), MB_ICONWARNING or MB_ABORTRETRYIGNORE or MB_SETFOREGROUND) of idAbort: Abort; // stille Exception idRetry: {Continue}; idIgnore: Result := False; // Datei vorhanden oder leer; der Benutzer möchte die Datei ignorieren end; until not Result; end; @BUG: =true ist böse ... sowas macht man einfach nicht. (Gründe stehen zu Genüge im Forum) |
Re: Sinnvoller Einsatz von goto
Zitat:
Trotzdem Danke für den Hinweis. EDIT: Aber müsste das nicht until result; heißen, im Moment bleibst du in der Schleife bis result unwahr ist. |
Re: Sinnvoller Einsatz von goto
Zitat:
|
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:15 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