TScreenCursor (C++)

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

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TCursor Save_Cursor = Screen->Cursor;
Screen->Cursor = crHourGlass;    // Show hourglass cursor .
try
{
  // Do some lengthy operation 
  int I = 0;
  int J = 0;
  int X, Y;
  const magicnumber = 150000000;
  while (I < magicnumber)
  {
    Randomize;
	while (J < magicnumber)
	{
	  Y = Random(J);
	  J++;
	}
	X = Random(I);
	I++;
  }
}
__finally
{
  Screen->Cursor = Save_Cursor; // Always restore the cursor.
}
}

Uses