在delphi窗口单元中定义全局变量:
flashstr:array[1..5] of string={'f','l','a','s','h'};
使用文本的KeyPress事件操作如下:
procedure Tfrmmain.Edit1KeyPress(Sender: TObject; var Key: Char);
var
i,j:integer;
begin
if not (Key in ['F','L','A','S','H','f','l','a','s','h']) then Abort;
for i:=1 to 5 do begin //找到按入的值
if flashstr[i]=Key then begin //对它前面的值进行后移
for j:=i downto 1 do begin
if j=1 then
flashstr[j]:=key
else
flashstr[j]:=flashstr[j-1];
end;
end;
end;
Label1.Caption:='';
for i:=1 to 5 do begin
Label1.Caption:=Label1.Caption+flashstr[i]
end;
end;