我有一个用于更改音量的滑块,但是在用户更改后,我淡出为新值(在此过程中使用当前音量更新滑块)。在更新位置时,我使用滑块TAG属性指示程序更改,但是以某种方式,这仍会触发我的新目标音量例程,从而取消整个提示。我在做什么错?
procedure TMain.VolumeBarChange(Sender:TObject);
begin
try
If VolumeBar.Tag=0 then Begin;
StartVolumeFade(IncSecond(Now,3),VolumeBar.Position);
LogWrite('Volume changed via slider.',debug);
End else begin;
LogWrite('Ignoring Volumebar change.',debug);
end;
except
end;
end;
和
procedure TMain.UpdateVolumeBar;
Var
CurrentVolume:Integer;
Begin;
VolumeBar.Tag:=1;
try
CurrentVolume:=GetPlayerVolume;
If CurrentVolume>-1 then Begin;
VolumeBar.Enabled:=TRUE;
VolumeBar.Position:=CurrentVolume;
end else Begin;
VolumeBar.Enabled:=FALSE;
VolumeBar.Position:=0;
End;
except
//removed for post
End;
VolumeBar.Tag:=0;
End;
为什么这不起作用?我感觉OnChange事件触发得太晚了(在我的UpdateVolumebar完成后)...:-/
只需检查发件人。如果事件是由用户触发的(从GUI,点击等),则发送方不应为NIL(通常为对象本身,在这种情况下为滑块组件)。另一方面,当您通过软件调用事件时,您可以将任何对象作为发送者传递(我有时使用NIL来检测从何处触发事件,或者将我需要在事件内部处理的对象传递给对象)。
(对不起,它应该放在一个简单的注释中,但是得分太低,无法做到)。