Kylix
Tips

NEW TIPS
Database (135)
Files (612)
Forms (606)
Graphic (536)
IDE (456)
Indy (433)
Internet / LAN (590)
IntraWeb (443)
Kylix (447)
Math (561)
Misc (591)
Multimedia (496)
Objects/
ActiveX (503)

OpenTools API (438)
Printing (459)
Strings (583)
System (721)
VCL (586)

Search Tip
Top15
Add new Tip

Forum

...Change Screen.Cursor without need to restore back?
Author: KK Gian
[ Print tip ]    

Tip Rating (4):  
     



// By implementing Interface we can set the cursor without restore it in the end.
// Example: In convensional way...
var
  
Cur: TCursor;
begin
  
Cur := Screen.Cursor;
  Screen.Cursor := crSQLWait;
  //do coding here
  //What happend is that if your code did not finish, the screen cursor will
  //remain as crSQLWait.. even with try..finally block (sometimes)
  
Screen.Cursor := Cur;
end;

// By using interface, we can implement as follows
type
  
ImyCursor = interface
    
[(GUID - Ctrl - Shift - G)]
  end;
  TmyCursor = class(TInterfacedObjects, ImyCursor);
  private
  
FCursor: TCursor;
  public
constructor 
Create;
  destructor Destroy; override;
    end;

implementation

TmyCursor.Create;

begin
  
FCursor := Screen.Cursor;
end;

TmyCursor.Destroy;

begin
  
Screen.Cursor := FCursor;
  inherited;
end;

procedure....var
  
C: ImyCursor;
begin
  
C := TmyCursor.Create;
  Screen.Curosr := crSQLWait; // whatever cursor you like
  // Do coding here without worring to free it.
  // Screen Cursor will restore when the TMyCursor object get out of scope.
end;

Rate this tip:

poor
very good


Copyright © Torry's Delphi Pages Torry's Delphi Pages Maintained by Simon Grossenbacher Notes? Comments? Feel free to send... Copyright © 1996-2001