Autor Beitrag
rob87
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mi 23.01.08 17:42 
Hallo

ich will mein Editfeld auf die Eingabe von Hex-Zahlen beschränken

Dass ist mein Ansatz:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
            //Hexadezimalzahlen
            if not (Key in ['0'..'9', Char(VK_BACK)]) then
              begin
                messagedlg('Bitte geben Sie nur Zahlen im Wertebereich von 0-9 bzw. A-F ein',mtInformation,[mbOK],0);
                Key := #0;
              end;
            end;

So funktionierts. Nur dass halt die Buchstaben A-F ned erlaubt sind. Aber auch wenn ich dahinter die Buchstaben, A-F eintrage, macht er nichts anderes??
ausblenden Delphi-Quelltext
1:
            if not (Key in ['0'..'9','A..F', Char(VK_BACK)]) then					



Moderiert von user profile iconGausi: Topic aus Sonstiges (Delphi) verschoben am Mi 23.01.2008 um 16:47
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 23.01.08 17:47 
Vielleicht so?
ausblenden Delphi-Quelltext
1:
 if not (Key in ['0'..'9','A'..'F''a'..'f', Char(VK_BACK)]) then					

_________________
We are, we were and will not be.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mi 23.01.08 17:47 
Hat sich erledigt. Hab die Kleinschreibweise genommen. In der Liste aber die Großschreibweise ausgeschlossen. ;-)

Aber nun nochwas? Wie kann einstellen, dass er in einem Edit-Feld Buchstaben automatisch groß macht?
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Mi 23.01.08 17:49 
Geht nicht, "manuell" so:

ausblenden Delphi-Quelltext
1:
AnsiUpperCase					

_________________
Die Lösung ist nicht siebzehn.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Mi 23.01.08 17:53 
OK. Und dass müsst ich in mein Edit1KeyPress ganz oben anordnen??

Vor den ganzen Überprüfungen auf den Inhalt, oder?

Aber versteh noch ned, wie ich den Befehl einbind?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
procedure Tfrmzahlenwandeln.Edit1KeyPress(Sender: TObject; var Key: Char);
begin

            //Hexadezimalzahlen
            if not (Key in ['0'..'9','a'..'f','A'..'F', Char(VK_BACK)]) then
              begin
                messagedlg('Bitte geben Sie nur Zahlen im Wertebereich von 0-9 bzw. A-F ein',mtInformation,[mbOK],0);
                Key := #0;
              end;
            end;
end;
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Mi 23.01.08 17:57 
Ich würds mal so probieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
case key of
  '0'..'9': ; // nothing
  'a'..'f': key := key + 26// oder so ähnlich. Musste mal in der Ascii-Tabelle nachgucken, wie man von a nach A kommt
  'A'..'F': ; // nothing  
  else begin
    key := #0;
    // ...
  end
end;

_________________
We are, we were and will not be.
Mitmischer 1703
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 754
Erhaltene Danke: 19

Win 7, Debian
Delphi Prism, Delphi 7, RAD Studio 2009 Academic, C#, C++, Java, HTML, PHP
BeitragVerfasst: Mi 23.01.08 17:57 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
procedure Tfrmzahlenwandeln.Edit1KeyPress(Sender: TObject; var Key: Char);
var key2 : String;
begin
key2 := AnsiUpperCase (String(Key));
            //Hexadezimalzahlen
            if not (Key in ['0'..'9','a'..'f','A'..'F'String(VK_BACK)]) then
              begin
                messagedlg('Bitte geben Sie nur Zahlen im Wertebereich von 0-9 bzw. A-F ein',mtInformation,[mbOK],0);
                Key := #0;
              end;
            end;
end;


Glaub' ich :nixweiss:

_________________
Die Lösung ist nicht siebzehn.
Yogu
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2598
Erhaltene Danke: 156

Ubuntu 13.04, Win 7
C# (VS 2013)
BeitragVerfasst: Mi 23.01.08 18:04 
Und was machst du dann mit Key2? Du weißt dieser Variable den großgeschriebenen Wert zu, verwendest ihn jedoch nicht mehr.

Was du machen könntest, wäre den kompletten Inhalt des Editfeldes großzuschreiben:

ausblenden Delphi-Quelltext
1:
Edit1.Text := UpperCase(Edit1.Text);					

Das Problem ist jedoch, dass der Cursor an den Anfang gesetzt wird. Du musst noch kontrollieren, wo der Cursor vorher war, und ihn dann am Ende wieder an die richtige Stelle setzen.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Do 24.01.08 08:58 
Also zusammengefasst entweder mit der Variante mit "Key2" oder mit nem Case ??
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Do 24.01.08 09:17 
Habs nicht ausprobiert, aber kann man nicht einfach
ausblenden Delphi-Quelltext
1:
2:
3:
Key := AnsiUpperCase(String(Key));
if not (Key in ['0'..'9','A..F', Char(VK_BACK)]) then
{...}

machen?! :gruebel:

_________________
Anonymes Eckenkind
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Do 24.01.08 09:20 
user profile iconMiri hat folgendes geschrieben:
Habs nicht ausprobiert, aber kann man nicht einfach
ausblenden Delphi-Quelltext
1:
2:
3:
Key := AnsiUpperCase(String(Key));
if not (Key in ['0'..'9','A..F', Char(VK_BACK)]) then
{...}

machen?! :gruebel:


Wär des Einfachste. :D Probiers nachher gleich mal aus. ;)
Kroko
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1284

W98 W2k WXP
Turbo D
BeitragVerfasst: Do 24.01.08 09:42 
ev. aller Steuerzeichen zulassen?
ausblenden Delphi-Quelltext
1:
2:
Key := AnsiUpperCase(String(Key));
if not (Key in [#01..#31,'0'..'9','A..F']) then ...

_________________
Die F1-Taste steht nicht unter Naturschutz und darf somit regelmäßig und oft benutzt werden! oder Wer lesen kann, ist klar im Vorteil!
Gausi
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 8548
Erhaltene Danke: 477

Windows 7, Windows 10
D7 PE, Delphi XE3 Prof, Delphi 10.3 CE
BeitragVerfasst: Do 24.01.08 09:46 
Es ging im weiteren Verlauf auch darum, wie man ein 'f' zu einem 'F' im Editfeld machen kann, und da brauch man dann etwas mehr ;-)

_________________
We are, we were and will not be.
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Do 24.01.08 09:48 
ausblenden Delphi-Quelltext
1:
    Key := AnsiUpperCase(String(Key));					

Funktioniert nicht. Fehlermeldung: Inkompatible Tpyen Char und String :(

user profile iconKroko hat folgendes geschrieben:
ev. aller Steuerzeichen zulassen?
ausblenden Delphi-Quelltext
1:
2:
Key := AnsiUpperCase(String(Key));
if not (Key in [#01..#31,'0'..'9','A..F']) then ...

Warum sollt ich Steuerzeichen zulassen? Gibts irgendwo ne Liste, wo sämtliche Steuerzeichen unter Delphi aufgelistet sind? Also #01 - #31 oder noch mehr?
Aber ich kann die Tab-Taste verwenden, ich kann die Pfeiltasten verwenden, des reicht eg.
Erichgue
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 86

Win XP/2000/7
TurboPacal 7.0; Delphi 2/5/7; BDS 2006/2010/XE6; C#; MSSQl 2000
BeitragVerfasst: Do 24.01.08 11:31 
user profile iconrob87 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
    Key := AnsiUpperCase(String(Key));					

Funktioniert nicht. Fehlermeldung: Inkompatible Tpyen Char und String :(


Key ist vom Typ Char und nicht Zuweisungskompatibel mit String.

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Var fText : String;
begin
  fText := AnsiUpperCase(String(Key));
  Key := fText[1];
end;


user profile iconKroko hat folgendes geschrieben:

ev. aller Steuerzeichen zulassen?
ausblenden Delphi-Quelltext
1:
2:
Key := AnsiUpperCase(String(Key));
if not (Key in [#01..#31,'0'..'9','A..F']) then ...

Warum sollt ich Steuerzeichen zulassen? Gibts irgendwo ne Liste, wo sämtliche Steuerzeichen unter Delphi aufgelistet sind? Also #01 - #31 oder noch mehr?
Aber ich kann die Tab-Taste verwenden, ich kann die Pfeiltasten verwenden, des reicht eg.


Nimm dir eine ANSI-Tabelle. Die Werte der Steuerzeichen sind identisch mit den #xx Nummern.

Erich
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 24.01.08 11:33 
user profile iconKroko hat folgendes geschrieben:
ev. aller Steuerzeichen zulassen?
ausblenden Delphi-Quelltext
1:
2:
Key := AnsiUpperCase(String(Key));
if not (Key in [#01..#31,'0'..'9','A..F']) then ...
Dies ist OnKeyPress (sonst wäre Key kein Char). Und in OnKeyPress kannst du die Steuerzeichen ignorieren, diese werden nur abgewürgt, wenn du sie in OnKeyDown/OnKeyUp mit Key := 0 entfernst ;-).
Miri
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 657


Delphi 3 Prof., Delphi 2005 PE
BeitragVerfasst: Do 24.01.08 11:34 
user profile iconErichgue hat folgendes geschrieben:
user profile iconrob87 hat folgendes geschrieben:
ausblenden Delphi-Quelltext
1:
    Key := AnsiUpperCase(String(Key));					

Funktioniert nicht. Fehlermeldung: Inkompatible Tpyen Char und String :(

Key ist vom Typ Char und nicht Zuweisungskompatibel mit String.

Dann vielleicht so?!
ausblenden Delphi-Quelltext
1:
    Key := Char(AnsiUpperCase(String(Key)));					

:gruebel: ;-)

_________________
Anonymes Eckenkind
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Do 24.01.08 11:38 
user profile iconMiri hat folgendes geschrieben:

Dann vielleicht so?!
ausblenden Delphi-Quelltext
1:
    Key := Char(AnsiUpperCase(String(Key)));					


So gehts nicht.

Aber so:
user profile iconErichgue hat folgendes geschrieben:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
Var fText : String;  
begin  
  fText := AnsiUpperCase(String(Key));  
  Key := fText[1];  
end;



Vielen Dank ;) :D
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19315
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Do 24.01.08 11:48 
Dieses ist doch die einfachste und beste Lösung. Das ist allerdings irgendwie immer so, dass die besten Lösungen ignoriert werden...
user profile iconGausi hat folgendes geschrieben:
Ich würds mal so probieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
case key of
  '0'..'9': ; // nothing
  'a'..'f': key := key + 26// oder so ähnlich. Musste mal in der Ascii-Tabelle nachgucken, wie man von a nach A kommt
  'A'..'F': ; // nothing  
  else begin
    key := #0;
    // ...
  end
end;
rob87 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 461

Win Me, Win XP Home, Win XP Prof
Delphi 2007 Enterprise
BeitragVerfasst: Do 24.01.08 11:54 
user profile iconjaenicke hat folgendes geschrieben:
Dieses ist doch die einfachste und beste Lösung. Das ist allerdings irgendwie immer so, dass die besten Lösungen ignoriert werden...
user profile iconGausi hat folgendes geschrieben:
Ich würds mal so probieren:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
case key of
  '0'..'9': ; // nothing
  'a'..'f': key := key + 26// oder so ähnlich. Musste mal in der Ascii-Tabelle nachgucken, wie man von a nach A kommt
  'A'..'F': ; // nothing  
  else begin
    key := #0;
    // ...
  end
end;


Jein. Also ich find die andere Variante "einfacher". Ob sie jetzt von der Vorgehensweise sinnvoller oder weniger sinnvoll ist, kann ich nicht beurteilen. Aber nochmal danke an alle.

*Thread schließ*