频道分类

delphi - 右滚动文字

作者:admin 来源: 日期:2020/6/11 14:06:22 人气: 标签:

 
procedure TForm1.Timer2Timer(Sender: TObject);
const
{$WRITEABLECONST ON}
  ScrollingText : string = 'This is right scrolling text ';
{$WRITEABLECONST OFF}
var
  ScrollPosition: Integer;
begin
  Label2.Caption := ScrollingText;
  for ScrollPosition := (Length(ScrollingText) - 1) downto 2 do
    begin
      ScrollingText[ScrollPosition] := Label2.Caption[ScrollPosition - 1];
      ScrollingText[1] := Label2.Caption[Length(ScrollingText) - 1];
    end;
end;


但是我建议不要使用可写常量,也不要使用for循环:

procedure TForm1.FormCreate(Sender: TObject);
begin
  ...
  Label2.Caption := 'This is right scrolling text ';
end;

procedure TForm1.Timer2Timer(Sender: TObject);
var
  S: String;
begin
  S := Label2.Caption;
  S := S[Length(S)] + Copy(S, 1, Length(S) - 1);
  Label2.Caption := S;
end;


上一篇:delphi xe 启动关闭Start Page 页错误提示下一篇:没有资料