Autor Beitrag
bruce185
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Di 27.09.05 18:44 
hi,
Ich bin gerade dabei ein Galgenbaum Spiel zu schreiben, nur da stimmt etwas nicht:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure Check(key: Char); 
var i: integer; 
  valid: boolean; 
begin 
  valid := false; 
  for i := 1 to length(Wort) do 
    if (Wort[i] = key) then//Buchstabe im Wort vorhanden 
    begin 
      if Label1.Caption[i] <> '_' then valid := true 
      else valid := false; //Wie soll bei wiederholter Nennung reagiert werden? 
      Label1.Caption[i] := key; 
    end; 
  if valid = false then //Buchstabe nicht vorhanden, entsprechend reagieren 
end;


dieser Quelltext prüft ob Das eingegebene Buchstabe im Wort vorkommt oder nicht, aber der code funktioniert nicht, ich erhalte folgende Fehlermeldung:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
[Error] Unit1.pas(80): Undeclared identifier: 'Label1'
[Error] Unit1.pas(87): Statement expected but 'PROCEDURE' found
[Warning] Unit1.pas(117): For loop control variable must be simple local variable
[Fatal Error] Project2.dpr(5): Could not compile used unit 'Unit1.pas'


wisst ihr vieleicht was ich da falsch gemacht habe, das mit Label1 regt mich auf, ich habe doch Label1 in meiner Form eingefügt, trotzdem steht da Undeclared identifier: 'Label1', wie macht man das richtig das es funktioniert, für jede hilfe bin ich euch sehr dankbar :(

MFG Andreas
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 27.09.05 18:53 
ausblenden Delphi-Quelltext
1:
Form1.Label1					


So wär's korrekt.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
bruce185 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Di 27.09.05 18:57 
cool, danke, jetzt kommt da wo Label steht keine fehler mer, nur noch Zeile 11 da wo
Form1.Label1.Caption[i] := key; steht kommt dieser fehler "[Error] Unit1.pas(102): Left side cannot be assigned to" was muss ich da umändern?, ich danke dir schonmal :)

Andreas
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 27.09.05 19:07 
Du könntest das Problem lösen, in dem du das so machst:
ausblenden Delphi-Quelltext
1:
Label1.Caption := Copy(Label1.Caption, 1, I - 1) + Key;					

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
bruce185 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 283

winXP
D7 Ent
BeitragVerfasst: Di 27.09.05 19:29 
ok, es geht, vielen dank.

Nur noch eine Frage hätte ich, und zwar wie kann ich das jetzt den Button1 zuweisen,
z.B. Button1 ist "A", wenn ich jetzt da drauf klicke, dann muss es doch irgendwie überprüfen ob es im Wort enthalten ist, wenn ja, dann soll das Buchstabe A eingefügt werden, nur noch da habe ich Probleme, ich tuh ja die Liste mit TSringList laden, das geht schon alles, wenn ich auf den Button "Neues Wort" klicke, dann kommt auch ein neues Wort, das ist schon fertig, ich muss jetzt nur noch die einzelne Wörter überprüfen, ob die im Wort enthalten sind, aber wie mache ich das jetzt, wäre dir sehr dankbar, wenn du mir das mal zeigen könntest, ich danke dir schonmal für die hilfe :)

Andreas
GTA-Place
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
EE-Regisseur
Beiträge: 5248
Erhaltene Danke: 2

WIN XP, IE 7, FF 2.0
Delphi 7, Lazarus
BeitragVerfasst: Di 27.09.05 19:57 
Da ist noch ein Fehler bei meinem Source. So ist es richtig:
ausblenden Delphi-Quelltext
1:
Label1.Caption := Copy(Label1.Caption, 1, I - 1) + Key + Copy(Label1.Caption, I + 1, Length(Label1.Caption) - I + 1);					


Um zu prüfen ob ein Buchstabe vorhanden ist, kannst du mal die Funktion Suche in der Entwickler-Ecke POS(); anschauen.

_________________
"Wer Ego-Shooter Killerspiele nennt, muss konsequenterweise jeden Horrorstreifen als Killerfilm bezeichnen." (Zeit.de)
Lannes
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2352
Erhaltene Danke: 4

Win XP, 95, 3.11, IE6
D3 Prof, D4 Standard, D2005 PE, TurboDelphi, Lazarus, D2010
BeitragVerfasst: Di 27.09.05 22:49 
Hallo,

hab mal etwas für Dich gebastelt:
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:
24:
25:
26:
//...
  Suchwort, Ergebnis : String;
  blFalsch : Boolean;
//...
implementation
{$R *.DFM}
procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
var z : Integer;
begin
  if Pos(key,Suchwort) <> 0 then
    begin
    for z := 1 to Length(Suchwort) do
      if Suchwort[z] = key then
        Ergebnis[z] := key;
    Label2.Caption := Ergebnis;
    end
     else BauGalgen;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Suchwort := 'Entwicklerecke';
  Ergebnis := StringOfChar('-',Length(Suchwort));
  Label1.Caption := Suchwort;
  Label2.Caption := Ergebnis;
end;

Schau Dir das mal genau an, dann kannst du es bestimmt in deinen Code integrieren :wink:

_________________
MfG Lannes
(Nichts ist nicht Nichts) and ('' <> nil ) and (Pointer('') = nil ) and (@('') <> nil )