CSDN博客

img xray2fly

两阶段检查的代码片断

发表于2004/7/7 21:14:00  888人阅读

//移动图形对象
procedure TMoveableShape.MoveShapes(DeltaX, DeltaY: Integer);
var
  I, Pass: Integer;
  TempControl: TControl;
begin
  if not Assigned(Parent) then
    Exit;

  // Do 2 passes through controls. The first one is to check that all
  // movements are valid   两次控制,第一次为检查移动是否有效,第二次为移动
  for Pass := 1 to 2 do
  begin
    for I := 0 to Parent.ControlCount - 1 do
    begin
      TempControl := Parent.Controls[I];
      if TempControl is TMoveableShape then
      begin
        if (Pass = 1) and
          (not TMoveableShape(TempControl).ValidMove(DeltaX, DeltaY)) then
          Exit
        else
        if (Pass = 2) and TMoveableShape(TempControl).Selected then
          TMoveableShape(TempControl).Move(DeltaX, DeltaY);
      end;
    end;
  end;
end;

0 0

相关博文

我的热门文章

img
取 消
img