Delphi 7-使用TMemo.Lines检查字母

问题描述

我目前在MemoBox中输入了一组单词。 问题是如何检查TMemoBox Lines属性的每一行上的特定字母。如果在指定的单词上字母不相似,则应该是错误的,不应计入,如果答案正确,如何使单词出现在单词标签上?

还如何将guess-label属性限制为仅输入5个字母? 目前正在制作游戏:)

Set of Words here

我目前有以下代码

{***************** CheckALetter ***************}
procedure TForm1.CheckLetter(ch:char);
var
 i:integer;
 s:string;
 goodguess:boolean;
begin
 goodguess:=false;
 if not (ch in GuessedLetters)
 then
 begin
   GuessedLetters:=GuessedLetters+[ch];
   guessesLabel.caption:=guesseslabel.caption+ch+',';
   s:=Wordlabel.caption;
   for i:=1 to length(TheWord) do {see if the letter is in the word}
   begin
     if ch=Theword[i] then
     begin
       s[2*i-1]:=ch; {fill in the  letter in display}
       goodguess:=true;
     end;
   end;
   wordlabel.caption:=s;
   {if not goodguess then drawAPiece(clred);}
   If pos('_',WordLabel.caption)=0 then  {all underscores replaced by letters}
   showmessage('A reprieve!')
   else {If piececount=Hangmanlist.count}
   begin
     showmessage('Oh,oh  Goodbye!'+#13 +'(The word was '+theword+')');
     {deadlbl.visible:=true;}
   end;
 end
 else messagebeep(mb_IconExclamation);
end;

//On key presss
procedure TForm1.guess_typeKeyPress(Sender: TObject; var Key: Char);
begin
 key:=upcase(key);
 guess_type.text:='';
 If not (key in ['A'..'Z']) then
 begin
   key:=#00;
   messagebeep(mb_iconexclamation);
 end
 else  CheckLetter(key);
end;

end.

解决方法

不确定TMemo的位置。TMemo.Lines只是一个普通的TStringList,您可以创建一个

for i:=1 to MyMemo.Lines.Count do
   s := MyMemo.Lines[i-1];
   // Do somenthing with s..