Autor Beitrag
Luzifer
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Mo 10.08.09 15:22 
Hi es geht mir um folgendes: Ich möchte ein Edit in welches man beliebigen Text eingeben kann, solange der Buchstaben noch nicht im Edit vorhanden ist, wobei Groß- und Kleinschreibung in der Hinsicht beachtet werden sollten, dass das große 'F' ebenfalls ausgeschlossen werden soll, wenn das kleine 'f' schon vorhanden ist.

Mein Lösungsansatz dafür ist folgender. (In der OnKeyPress vom Edit) Es funktioniert und is soweit wunderbar, aber die Frage: kann ich das noch eleganter lösen? Denn mal ehrlich: So schick sieht das nicht aus^^
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
for i:=1 to length(swort.text) do
  if
    ((ord(key)<91and ((key = swort.text[i]) or (chr(ord(key)+32) = swort.text[i])))
    or
    ((ord(key)>91and ((key = swort.text[i]) or (chr(ord(key)-32) = swort.text[i])))
  then begin
    Key:=#0;
    showmessage('Buchstabe schon vergeben');
    break;
end;

Erläuterungen:
swort ist mein Edit
Ich habe die Eingabe bereits im Vorwege auf einfache Klein- und Großbuchstaben begrenzt.

Danke für eure Hilfe!
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: Mo 10.08.09 15:31 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
if pos(UpperCase(Key), Uppercase(swort.text)) > 0 then begin
  Key := #0;
  showmessage('Buchstabe schon vergeben');
end;


wäre eine möglichkeit ;)

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Mo 10.08.09 15:40 
ja na klar! danke dir! ich war mit meinen Gedanken weiter gewandert als ich zu den Uppercase-functionen kam, weil ich die Buchstaben ja nicht ändern wollte, aber es geht ja auch so^^
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Mo 10.08.09 17:25 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
var
    RemainingChars : set of Char;

{...}
if Key = #8 then 
begin
  RemainingChars := RemainingChars - [swort.text[Length(swort.text)]];
end
else if key in RemainingChars Then
begin
  ShowMessage('Already used!');
  key := #0;
end
else
begin
  RemainingChars := RemainingChars + [key];
end;

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Mo 10.08.09 17:28 
Moin!

Markierst du den Thread noch entsprechend, wenn dein Problem gelöst ist? Danke. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Luzifer Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 98

WinXP Pro/ Vista
D5 Enterprise/D7 Enterprise/D2005 Architect
BeitragVerfasst: Mo 10.08.09 17:49 
Auch eine sehr gute Lösung von Ben, danke dir!
na klar Narses^^