Autor Beitrag
LonghornUser
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: Mo 27.02.06 17:13 
Hallo,

ich muss für die Schule ein Kassenprogramm in Turbo Pascal schreiben und habe da ein kleines Problem. Für eine Passwortabfrage habe ich ein Feld deklariert, in das die eingegebenen Zeichen gelesen werden. Also wenn der User "Hallo" eingibt wäre das so: passwort[0] := "H", passwort[1] := "a" usw.
Jetzt möchte ich dieses Feld einmal leeren (alles 0 setzen). Aber dabei streikt Turbo Pascal:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
passwort : array[0..8of char;
{...}
if eingabe = CHR(13then begin
  for f := 0 to 8 do
  gesamt[f]:='';
end;


Und er sagt als Fehlermeldung: "Fehler 26: Typen nicht miteinander vereinbar."
Wenn ich ' ' statt '' nehme geht es, aber dann werden die Passwörter ja als nicht übereinstimmend gewertet (da ja '' nicht ' ' ist).

Was tun ?

Ciao LHUser
azubi_20
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 593

WinXP SP2, Ubuntu 8.4
D7 Enterp., D2005 Prof., Java (Eclipse 3.4.0)
BeitragVerfasst: Mo 27.02.06 17:23 
Wenn du dein array leeren willst, dann mach doch einfach Leerzeichen (was spricht dagegen?) Ansonmsten nimm statt einen Array of Char einen String. Den kannst du dann auch zurücksetzen.
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Mo 27.02.06 17:31 
Wenn du chars auf null setzen willst, dann musst du sie auf null setzen, und nicht auf '' (=Leerstring).

Also etwas so:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
passwort : array[0..8of char;  
{...}  
if eingabe = CHR(13then begin  
  for f := 0 to 8 do  
  gesamt[f]:=#0;  
end;


Beste Grüße
Tastaro
LonghornUser Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: Mo 27.02.06 17:50 
Mhm. Geht immernochnicht. Der Code ist:
ausblenden volle Höhe 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:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
procedure passwortabfrage;
var p,q,f:integer;
    gesamt:String;
begin
  cursorto(9,12);
  write('Passwortabfrage');
  cursorto(9,13);
  write('===============');
  cursorto(9,14);
  write('Bitte geben Sie das Passwort');
  cursorto(9,15);
  write('ausschließlich in kleinen Buchstaben ein.');
  cursorto(9,16);
  write('Passwort: ');
  p := 0;
  repeat
  cursorto(19+p,16);
  eingabe := readkey;
  passwort[p] := eingabe;
  if eingabe <> CHR(13then
  write('*'else begin
  cursorto(18,16);
  clreol;
  end;
  gesamt := gesamt + passwort[p];
  inc(p);
  if eingabe = CHR(13then begin
  for f := 0 to 8 do
  gesamt[f]:=#0;
  p := 0;
  end;
  until (eingabe = CHR(13)) AND (gesamt='april');
end;


Was stimmt hier nicht ?? Er sagt immer, das passwort wär falsch (also er kommt net aus der repeat schleife raus.
Thorus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 18

WinXP
Delphi 5
BeitragVerfasst: Mo 27.02.06 18:31 
Lass dir doch "gesamt" einfach mal zwischendrin ausgeben dann kannst du nachsehen was nicht funktioniert oder wo der Fehler liegt.

_________________
MfG Thorus
Tastaro
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 414
Erhaltene Danke: 23



BeitragVerfasst: Mo 27.02.06 18:39 
"gesamt" ist also ein string und kein array.

Sag das doch gleich.

Strings leert man ungefähr so:

gesamt := '';

Aber deine Abfrage wird eh nicht funktionnieren, weil du bei einem #13 den string "gesamt" leerst und ihn danach mit "April" vergleichst.

Beste Grüße
Tastaro
LonghornUser Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 796



BeitragVerfasst: Mo 27.02.06 20:03 
@ Thorus: Habe ich. Die Ausgabe stimmt

@Tastaro: Stimmt, hatte ich übersehen ;) Aber es geht trotzdem nicht :( Ich habe es jetzt so:
ausblenden volle Höhe 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:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
procedure passwortabfrage;
var p,q,f:integer;
    gesamt:String;
begin
  cursorto(9,12);
  write('Passwortabfrage');
  cursorto(9,13);
  write('===============');
  cursorto(9,14);
  write('Bitte geben Sie das Passwort');
  cursorto(9,15);
  write('ausschließlich in kleinen Buchstaben ein.');
  cursorto(9,16);
  write('Passwort: ');
  p := 0;
  gesamt := '';
  repeat
    cursorto(19+p,16);
    eingabe := readkey;
    passwort[p] := eingabe;
    if eingabe <> CHR(13then
      write('*');
    if (eingabe = CHR(13)) AND (gesamt <> 'april'then begin
      cursorto(18,16);
      clreol;
    end;
    gesamt := gesamt + passwort[p];
    inc(p);
    if (eingabe = CHR(13)) AND (gesamt <> 'april'then begin
      gesamt := '';
      for q := 0 to 8 do
      passwort[q]:=#0;
      p := 0;
    end;
  write(gesamt);
  until (eingabe = CHR(13)) AND (gesamt='april');

end;