Autor Beitrag
volvox
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Do 24.05.07 14:02 
Hi, noch ne Frage:

Gibts ne Eigenschaft von nem edit die festlegt, dass nur Buchstaben oder nur Ziffern Reingeschrieben werden dürfen. Ich will v.a. Fehleingaben von Buchstaben vermeiden, wo ich mit Integers arbeite.


Moderiert von user profile iconraziel: Topic aus Sonstiges (Delphi) verschoben am Do 24.05.2007 um 15:40
jakobwenzel
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1889
Erhaltene Danke: 1

XP home, ubuntu
BDS 2006 Prof
BeitragVerfasst: Do 24.05.07 14:09 
Wurd im Forum schon oft abgehandelt, du musst auf das Ereignis OnKeyDown reagieren.

_________________
I thought what I'd do was, I'd pretend I was one of those deaf-mutes.
FiceGoesDelphi
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 485

Win XP Prof
Delphi 2006
BeitragVerfasst: Do 24.05.07 14:09 
Ich bin jetzt kein Delphi-Pro aber ich hätte es so gemacht:

Du wirst wahrscheinlich den Inhalt des EditFeldes irgendwo hin speichern oder?
Dann überprüfe doch vor dem Speichern, ob es sich um Zahlen oder Buchstaben handelt
und gebe eine Meldung raus, wenn nicht das erwartete Format eingegeben wurde.
Und breche das "Speichern" danach direkt ab.
Vllt hilft dir das ja!

_________________
<(^^<) <(^^)> (>^^)>
===================
volvox Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 112

WIN XP
Delphi 7 Personal
BeitragVerfasst: Do 24.05.07 14:15 
user profile iconjakobwenzel hat folgendes geschrieben:
Wurd im Forum schon oft abgehandelt, du musst auf das Ereignis OnKeyDown reagieren.


Ich denke mal es ist egal ob OnKeyDown oder OnChange, aber ich möchte ja wissen wie ich abfrage, ob es sich um eine Ziffer oder einen Buchstaben handelt
ZeitGeist87
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1593
Erhaltene Danke: 20

Win95-Win10
Delphi 10 Seattle, Rad Studio 2007, Delphi 7 Prof., C++, WSH, Turbo Pascal, PHP, Delphi X2
BeitragVerfasst: Do 24.05.07 14:25 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
const ziffern = ['0'..'9'];
var i: integer;
    myString: String;
begin
 myString:= 'String123';
 for i:= 1 to length(myString) do
  if (myString[i] in ziffern) then
   showmessage('Stringposition + inttostr(i) + ' ist eine Zahl')
  else
   showmessage('
Stringposition + inttostr(i) + ' ist ein Buchstabe')
end;


So hab ichs verstanden, bei dem was du vorhast.

LG
Stefan

_________________
Wer Provokationen, Ironie, Sarkasmus oder Zynismus herauslesen kann soll sie ignorieren um den Inhalt meiner Beiträge ungetrübt erfassen zu können.
oldmax
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 380


D3 Prof, D4 Prof
BeitragVerfasst: Mo 28.05.07 08:35 
Hi
Zitat:
Ich denke mal es ist egal ob OnKeyDown oder OnChange,



nicht wirklich...

Zitat:
aber ich möchte ja wissen wie ich abfrage, ob es sich um eine Ziffer oder einen Buchstaben handelt


Daher der Hinweis von Jakob....

Warum sollen wir nachsehen, wo es schon mal geschrieben steht ? Wir wollen's doch nicht wissen.

Also, der Hinweis von Jakob, die Hilfe von Delphi in Zusammenhang mit "if" sollten dir eine brauchbare Lösung bringen.
Gruß oldmax

_________________
Zier dich nich so, ich krieg dich schon....
Blawen
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 616
Erhaltene Danke: 33

Win XP, Vista, 7
Delphi 5 Prof., BDS 2006 Prof. RAD Studio XE
BeitragVerfasst: Mo 28.05.07 15:08 
Persönlich würde ich die Abfrage in eine sep. Function auslagern:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TArtikel.Edit_AnzKeyPress(Sender: TObject; var Key: Char);
begin
  IF NurZifferEingabe(Key) = False THEN Key := #0;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
Function NurZifferEingabe(var Key: Char): Boolean;

begin
  IF NOT (Key in [#8,#46,#48,#49,#50,#51,#52,#53,#54,#55,#56,#57]) THEN
    begin
      NurZifferEingabe := False;
      ShowMessage('Nur Zahlen und der Dezimalpunkt sind erlaubt!');
    end;
   ELSE NurZifferEingabe := True;
end;


Obiges Beispiel kann z.B. so abgewandelt werden:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TArtikel.Edit_AnzKeyPress(Sender: TObject; var Key: Char);  
begin  
  NurZifferEingabe(Key);  
end;

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
if NOT (Key in ['0'..'9', DecimalSeparator , #8, '-'])       
   OR ((Key = decimalseparator) AND NOT (pos(decimalseparator,text)= 0))then
     begin
       Key := Chr(0);
       Application.MessageBox('Nur Zahhlen und der Dezimalpunkt (Komma) sind erlaubt!',
                             'Achtung!', MB_OK + MB_IconWarning);
       SetFocus;
     end;


So kannst Du mehrere Functionen für die unterschiedlichsten Spezialfälle erstellen und je nach Bedarf die gewünschte Variante verwenden.
Noch eleganter wäre natürlich die Implementierung eigener Edit-Felder...

_________________
Es kompilert, wir können ausliefern.
Und es kompiliert wieder - das Update ist fertig - bitte 100 Euro ;-)
Slowfoxi
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Mo 28.05.07 15:14 
also wenn nur integers eingegeben werden sollen, könnte man auch ein spinedit nehmen

mfg