我想让一个程序在一个if语句中等待几秒钟.但我的问题是它跳过第二个Sleep命令?我已经找到了答案,但似乎没有其他人有这个?
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
if Form1.shapeGreen.Brush.Color=clLime then
begin
Sleep(4000);
Form1.shapeRed.Brush.Color:=clMaroon ;
Form1.shapeYellow.Brush.Color:=clYellow;
Form1.shapeGreen.Brush.Color:=clGreen;
Sleep(3000); (it skips this (waits 0...))
Form1.shapeRed.Brush.Color:=clRed ;
Form1.shapeYellow.Brush.Color:=clOlive;
Form1.shapeGreen.Brush.Color:=clGreen;
end;
end;
Run Code Online (Sandbox Code Playgroud) 我试图使用计时器来检查文件的时间戳,以检查它是否已被修改,如果这是真的,它必须将文本文件中的行添加到richedit.问题是它每隔1/4秒(定时器间隔)不断地将行添加到richedit.我尝试了不同的方法,但无法做到正确.
procedure TForm1.Timer1Timer(Sender: TObject);
Var
Filet : textfile;
filename, readtxt : string;
filedate1, filedate2 : integer;
begin
assignfile(filet, 'S:\share.talk');
filename := 'S:\share.talk';
filedate1 := FileAge(filename);
if filedate1 <> filedate2 then begin
reset(filet);
readln(filet, readtxt);
richedit1.lines.add(readtxt);
closefile(filet);
filedate2 := filedate1;
end;//if
end;
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
我试图使一个形状沿着鼠标点击的方向移动一定距离.我尝试为鼠标点击事件的x和y创建变量,并在x和y中创建到达鼠标点击位置的距离,并使用计时器划分+截断值以使形状在该方向上移动,虽然我的问题是我需要移动特定距离的形状,无论光标在哪里,只需使用鼠标单击方向,以及使用此方法形状不会以恒定速度移动.
当前代码:鼠标按下:
mx := x;
my := y;
Run Code Online (Sandbox Code Playgroud)
计时器:
shape1.left := shape1.Left + (mx - shape1.left + 8) div 32;
shape1.top := shape1.top + (my - shape1.top + 8) div 32;
Run Code Online (Sandbox Code Playgroud)