Amazon.com Widgets Fun Code of the Week #7

Fun Code of the Week #7

By Nick at February 24, 2013 00:08
Filed Under: Fun Code, Delphi

It’s all a big circle.

First, I posted a fun little way to handle the cursor in this Fun Code of the Week.

The first comment on that post was from my friend Tapper who said “What, no interface?”

Then, I post this about hints revealing errors with cursor handling as part of the demo.

And from that, we get a comment by Leif that I’m making Fun Code of the Week

So Tapper is happy, and we all have about three ways to handle the cursor. 

Wins for everyone!

 

unit CursorHandler;

interface

uses
      Controls
    ;

type
  ICursor = interface(IInterface)
  end;

function AutoCursor(const aCursor: TCursor): ICursor;

implementation

uses
  Forms;

type
  TAutoCursor = class(TInterfacedObject, ICursor)
  private
    FCursor: TCursor;
  public
    constructor Create(const aCursor: TCursor);
    destructor Destroy; override;
  end;

function AutoCursor(const aCursor: TCursor): ICursor;
begin
  Result := TAutoCursor.Create(aCursor);
end;

constructor TAutoCursor.Create(const aCursor: TCursor);
begin
  inherited Create;
  FCursor := Screen.Cursor;
  Screen.Cursor := aCursor;
end;

destructor TAutoCursor.Destroy;
begin
  Screen.Cursor := FCursor;
  inherited;
end;

end.
blog comments powered by Disqus

My Book

A Pithy Quote for You

"There are no such things as limits to growth, because there are no limits to the human capacity for intelligence, imagination, and wonder"    –  Ronald Reagan

Amazon Gift Cards

General Disclaimer

The views I express here are entirely my own and not necessarily those of any other rational person or organization.  However, I strongly recommend that you agree with pretty much everything I say because, well, I'm right.  Most of the time. Except when I'm not, in which case, you shouldn't agree with me.