Autor Beitrag
gin2309
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98; Win XP
D5 Prof, D7 Prof
BeitragVerfasst: Do 08.09.05 14:37 
Hallo,
ich möchte in drei edits jeweils zwei ziffern eintragen lassen!
Weiß jemand, wie ich das so hinkriege dass nach eingeben der zweiten ziffer ins nächste edit gesprungen wird?
Also so wie beim eingeben eines key..
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 08.09.05 14:38 
Hallo!

Ich würde im OnChange-Ereignis eines jeden Edits abfragen, ob die Länge der Eingabe Zwei beträgt und dann mittels edit2.focus() (z.B.) ins nächste Feld springen.

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
gin2309 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98; Win XP
D5 Prof, D7 Prof
BeitragVerfasst: Do 08.09.05 14:44 
Schon mal ein guter ansatz!
Das Problem ist, dass die edits immer mit zwei ziffern gefüllt sind (weil Zeitangabe).
Kann ich herausbekommen an welcher stelle der cursor im edit ist?
Und kann ich irgendwie einstellen, dass man in den edits überschreiben kann?
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Do 08.09.05 14:47 
Eine Überschreibefunkltion gibt es meines Wissens nicht, aber die kann man sich selber programmieren, in dem man das OnKeyPress-ereignis abfängt. Und zur Cursorpopition habe ich bisher auch nix funktionierendes gefunden, was ich oft schade finde ;).
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 08.09.05 15:01 
Hallo!

So bekommst Du sowohl das Springen als auch das Überschreiben hin:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
  cursorPos : Integer;
  temp : String;
begin
  cursorPos := edit1.SelStart;
  inc(cursorPos);

  if Length(edit1.Text) = 2 then
  begin
    temp := edit1.Text;
    temp[cursorPos] := Key;
    edit1.Text := temp;
    Key := #0;
  end;

  if cursorPos = 2 then
    edit2.SetFocus
  else
    edit1.SelStart := cursorPos;
end;


Grüße
Christian

P.S.: Kann man vielleicht noch verfeinern. Ich weiß z.B. gerade nicht, wie sich obiger Code verhält, wenn Text markiert ist, SelLength also nicht Null ist.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
gin2309 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98; Win XP
D5 Prof, D7 Prof
BeitragVerfasst: Do 08.09.05 15:35 
Super geil!
Genau das isses!!!
Vielen Dank!
gin2309 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 16

Win 98; Win XP
D5 Prof, D7 Prof
BeitragVerfasst: Fr 09.09.05 16:16 
Mir ist noch aufgefallen, dass es mit der backspace -taste probleme gibt. Es wird als weiteres Zeichen eingegeben.
Für alle die, die den obigen Code benutzen, hier noch die kleine Änderung die gemacht werden muss:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
  cursorPos := edit1.SelStart;
  inc(cursorPos);

  if (Length(edit1.Text) = 2)and(key<>#8then
  begin
    temp := edit1.Text;
    temp[cursorPos] := Key;
    edit1.Text := temp;
    Key := #0;
  end;


Moderiert von user profile iconKlabautermann: Code- durch Delphi-Tags ersetzt.