Autor Beitrag
n-regen
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 202
Erhaltene Danke: 2



BeitragVerfasst: Do 22.06.06 15:34 
Hallo zusammen.

Ich habe ein Problem bei meinem Verschlüsselungsprogramm:

Der Schlüssel darf jedes Zeichen nur einmal enthalten, aber wie bring ich das Delphi bei?

Also:

Man gibt in einem Edit den Echtwort-Schlüssel ein und der PC gibt den Schlüssel mit jedem Buchstaben nur noch einmal zurück.

Mein derzeitiger Quelltext sieht so aus:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
procedure TForm1.Button1Click(Sender: TObject);
var i, ver: integer;
begin
 for i := 1 to Length(Edit1.Text) do begin
  TLabel(FindComponent('Label'+IntToStr(i-ver))).caption := Edit1.Text[i];
  if ((pos(TLabel(FindComponent('Label'+IntToStr(i-ver))).caption, Edit1.Text) > i) and (pos(TLabel(FindComponent('Label'+IntToStr(i-ver))).caption, Edit1.Text) < i)) or ((pos(TLabel(FindComponent('Label'+IntToStr(i-ver))).caption, Edit1.Text) < i))
  then begin
   TLabel(FindComponent('Label'+IntToStr(i-ver))).caption := '';
   inc(ver)
  end;
 end;
 ver := 0
end;


Nur das geht halt nicht!

Wer kann mir sagen, was ich falsch mach oder mir nen Quelltext geben?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 22.06.06 15:48 
Moin!

user profile iconn-regen hat folgendes geschrieben:
Man gibt in einem Edit den Echtwort-Schlüssel ein und der PC gibt den Schlüssel mit jedem Buchstaben nur noch einmal zurück.

:gruebel: Mach mal ein Beispiel oder formuliere präziser. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
n-regen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 202
Erhaltene Danke: 2



BeitragVerfasst: Mo 26.06.06 13:51 
user profile iconNarses hat folgendes geschrieben:

:gruebel: Mach mal ein Beispiel oder formuliere präziser. ;)


Ich meine das so:
Rein: schlüssel
Raus: schlüe, weil halt s und l vorher schon mal vorgekommen sind.
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mo 26.06.06 13:59 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
function NurEinmalBuchstabe(s : string) : string;
var
  i : Integer;
begin
  result := '';
  if length(s) > 0 then
    for i := 1 to length(s) do
      if pos(s[i], result) = 0 then
        result := result + s[i];
end;

ungetestet.
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 26.06.06 14:04 
Moin!

Probier das mal so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
procedure TForm1.Button1Click(Sender: TObject);

  // doppelte Buchstaben filtern
  function UniqueChars(const S: String): String;
    var
      i,j: Integer;
      UsedChars: set of Char;
  begin
    Result := S; // Ergebnis zunächst übernehmen
    UsedChars := []; // noch keine Buchstaben verwendet
    j := 0; // Anzahl Zeichen im Ergebnis
    for i := 1 to Length(S) do // über alle Zeichen
      if (NOT (S[i] in UsedChars)) then begin // Zeichen noch frei?
        Inc(j); // Anzahl erhöhen (ist auch Schreibposition)
        Result[j] := S[i]; // Zeichen übernehmen
        UsedChars := UsedChars +[S[i]]; // und merken: benutzt
      end;
    SetLength(Result,j); // Länge ggfs. korrigieren
  end;

begin
  Edit1.Text := UniqueChars(Edit1.Text);
end;

getestet. ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
n-regen Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 202
Erhaltene Danke: 2



BeitragVerfasst: Di 27.06.06 17:38 
Danke! :D :D :D
Es gehen beide Varianten.
Mal schaun, ob der Rest klappt.

EDIT: Der Rest von meinem Programm!