对输入的flash字符连接到flash后面,所得到的新字符中只能包含flash字符

来源:互联网 发布:java二维数组杨辉三角 编辑:程序博客网 时间:2024/05/22 08:22

在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;

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/htsoftware/archive/2010/06/24/5690661.aspx