AGB  ·  Datenschutz  ·  Impressum  







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

Eingabebedingungen

Ein Thema von CIADelphianer · begonnen am 26. Aug 2010 · letzter Beitrag vom 26. Aug 2010
 
Benutzerbild von himitsu
himitsu

Registriert seit: 11. Okt 2003
Ort: Elbflorenz
44.398 Beiträge
 
Delphi 12 Athens
 
#6

AW: Eingabebedingungen

  Alt 26. Aug 2010, 11:54
Delphi-Quellcode:
procedure TForm1.EditISOCodeKeyPress(Sender: TObject; var Key: Char);
begin
  if not (Key in [#8, '1'..'4', 'A'..'H', 'K'..'N', 'P'])
    and (EditISOCode.SelStart = 0) then
  begin
    Key := #0; // Ignoriert die Tastatureingabe
    StatusBar.SimpleText := 'An der ersten Stelle des ISOCodes kann nur 1, 2, 3, 4, A,B,C,D,E,F,G,H,K,L,M,N oder P stehen.';
  end
  else
    // 2. Zeichen
    if not (Key in [#8, '0', '2', '5', '6', '8', 'C'..'F', 'L'..'N', 'P'])
      and (EditISOCode.SelStart = 1) then
    begin
      Key := #0; // Ignoriert die Tastatureingabe
      StatusBar.SimpleText := 'An der zweiten Stelle des ISOCodes kann nur 0,2,5,6,8,C,D,E,F,L,M,N oder P stehen.';
    end
    else
      // 3. Zeichen
      if not (Key in [#8, 'G', 'V', 'R', 'H', 'U', 'T', 'B', 'P', 'S'])
        and (EditISOCode.SelStart = 2) then
      begin
        Key := #0;
        StatusBar.SimpleText := 'An der dritten Stelle des ISOCodes kann nur G,V,R,H,T,B,P,S stehen.';
     end
     else
       // 4.Zeichen
       if not (Key in [#8, '0'..'9']) and (EditISOCode.SelStart = 3) then
       begin
         Key := #0;
         // Statusbar.SimpleText:='An der vierten Stelle des ISOCodes kann nur 1,2,3,4,5,6,7,8 und 9.';
       end;

  // Bedingung vom 3. zum 4. Zeichen (z.B. G nur mit 0,1,2,3 kombinierbar)

  if (Key in ['G']) and (EditISOCode.SelStart = 2) then
  begin
    StatusBar.SimpleText := 'Mit G können Sie nur die Zahlen 0,1,2 und 3 kombinieren, sonst ungültige Containerbezeichnung!';
  end;
  if not (Key in [#8, '0'..'3']) and (EditISOCode.SelStart = 3) then
  begin
    Key := #0;
  end;

  if (Key in ['V']) and (EditISOCode.SelStart = 2) then
  begin
    StatusBar.SimpleText := 'Mit V können Sie nur die Zahlen 0,2 und 4 kombinieren, sonst ungültige Containerbezeichnung!';
  end;
  if not (Key in [#8, '0'..'2', '4']) and (EditISOCode.SelStart = 3) then
  begin
    Key := #0;
  end;

  if (Key in ['R']) and (EditISOCode.SelStart = 2) then
  begin
    StatusBar.SimpleText := 'Mit R können Sie nur die Zahlen 0,1,2 und 3 kombinieren, sonst ungültige Containerbezeichnung!';
  end;
  if not (Key in [#8, '0'..'3']) and (EditISOCode.SelStart = 3) then
  begin
    Key := #0;
  end;

  if (Key in ['H']) and (EditISOCode.SelStart = 2) then
  begin
    StatusBar.SimpleText := 'Mit H können Sie nur die Zahlen 0,1,2,3 und 4 kombinieren, sonst ungültige Containerbezeichnung!';
  end;
  if not (Key in [#8, '0'..'4']) and (EditISOCode.SelStart = 3) then
  begin
    Key := #0;
  end;

  if (Key in ['U']) and (EditISOCode.SelStart = 2) then
  begin
    StatusBar.SimpleText := 'Mit U können Sie nur die Zahlen 0,1,2,3,4 und 5 kombinieren, sonst ungültige Containerbezeichnung!';
  end;
  if not (Key in [#8, '0'..'5']) and (EditISOCode.SelStart = 3) then
  begin
    Key := #0;
  end;

  if (Key in ['T']) and (EditISOCode.SelStart = 2) then
  begin
    StatusBar.SimpleText := 'Mit T können Sie nur die Zahlen 0,1,2,3,4,5,6,7,8 und 9 kombinieren, sonst ungültige Containerbezeichnung!';
  end;
  if not (Key in [#8, '0'..'9']) and (EditISOCode.SelStart = 3) then
  begin
    Key := #0;
  end;

  if (Key in ['B']) and (EditISOCode.SelStart = 2) then
  begin
    StatusBar.SimpleText := 'Mit B können Sie nur die Zahlen 0,1,3,4,5 und 6 kombinieren, sonst ungültige Containerbezeichnung!';
  end;
  if not (Key in [#8, '0'..'6']) and (EditISOCode.SelStart = 3) then
  begin
    Key := #0;
  end;

  if (Key in ['P']) and (EditISOCode.SelStart = 2) then
  begin
    StatusBar.SimpleText := 'Mit P können Sie nur die Zahlen 0,1,2,3,4 und 5 kombinieren, sonst ungültige Containerbezeichnung!';
  end;
  if not (Key in [#8, '0'..'5']) and (EditISOCode.SelStart = 3) then
  begin
    Key := #0;
  end;

  if (Key in ['S']) and (EditISOCode.SelStart = 2) then
  begin
    StatusBar.SimpleText := 'Mit S können Sie nur die Zahlen 0,1 und 2 kombinieren, sonst ungültige Containerbezeichnung!';
  end;
  if not (Key in [#8, '0'..'2']) and (EditISOCode.SelStart = 3) then
  begin
    Key := #0;
  end;
die Ganzen if not (Key in [...]) and (EditISOCode.SelStart = ...) hängen zusammen ... das ergibt in Kurz:
Delphi-Quellcode:
if (not (Key in [#8, '0'..'3']) and (EditISOCode.SelStart = 3))
  or (not (Key in [#8, '0'..'2', '4']) and (EditISOCode.SelStart = 3))
  or (not (Key in [#8, '0'..'3']) and (EditISOCode.SelStart = 3))
  or (not (Key in [#8, '0'..'4']) and (EditISOCode.SelStart = 3))
  or (not (Key in [#8, '0'..'5']) and (EditISOCode.SelStart = 3))
  or (not (Key in [#8, '0'..'9']) and (EditISOCode.SelStart = 3))
  or (not (Key in [#8, '0'..'6']) and (EditISOCode.SelStart = 3))
  or (not (Key in [#8, '0'..'5']) and (EditISOCode.SelStart = 3))
  or (not (Key in [#8, '0'..'2']) and (EditISOCode.SelStart = 3)) then
begin
  Key := #0;
end;
Was fällt nun auf?
Egal welcher Buchstabe auf 2 liegt, es wird immer nur [#8, '0'..'2'] zugelassen.

Debugge doch einfach mal deinen Code?
- starte dein Programm gibt "23G" ein
- lege einen Haltepunkt (F5) auf den ersten Befehl dieser Methode/Prozedur
- drück auf die "3"
- und nun geh einfach mal mit F7 durch diese Methode durch ... und schon wirst du sehn wann/wo und warum Key aud #0 gesetzt wird.

Und schau dir mal jeweils das 2. IF im Post #4 an, dort wird auch nochmal der Buchstabe geprüft.
Ein Therapeut entspricht 1024 Gigapeut.

Geändert von himitsu (26. Aug 2010 um 12:00 Uhr)
  Mit Zitat antworten Zitat
 


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 02:38 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