TScreenCursor (Delphi)

From RAD Studio Code Examples
Jump to: navigation, search

Description

Assignments to the Screen object's cursor property are typically guarded by a try...finally statement to ensure that normal cursor behavior is restored. Note that the original cursor is saved and restored. This allows cursor changes to be nested without accidentally restoring the cursor to a hard-coded value prematurely.

Code

procedure TForm1.Button1Click(Sender: TObject);
var 
  Save_Cursor : TCursor;
  I, J: Integer;
  X, Y: Word;
const
  magicnumber = 3000000;
begin
  Save_Cursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;    { Show hourglass cursor. }
  try
    { Do some lengthy operation }
  I := 0;
  J := 0;
  while I < magicnumber do
  begin
    Randomize;
    while J < magicnumber do
    begin
      Y := Random(J);
      Inc(J);
    end;
    X := Random(I);
    Inc(I);
  end;
  finally
    Screen.Cursor := Save_Cursor;  { Always restore to normal. }
  end;
end;

Uses