Einzelnen Beitrag anzeigen

Benutzerbild von Sir Rufo
Sir Rufo

Registriert seit: 5. Jan 2005
Ort: Stadthagen
9.454 Beiträge
 
Delphi 10 Seattle Enterprise
 
#8

AW: Hinweis unterdrücken "Auf x zugewiesener Wert wird niemals benutzt"

  Alt 2. Jun 2014, 09:40
Hier eine Variante ohne diese Abhängigkeiten und Überflüssiges (z.B. IWaitCursor ) und vor allem auch kaskadierbar
Delphi-Quellcode:
unit WaitCursor;

interface

uses
  System.SysUtils,
  Vcl.Forms,
  Vcl.Controls;

type
  TWaitCursor = class( TInterfacedObject )
  private
    class var [weak] _Instance : TWaitCursor;
    class var _OnShow : TProc;
    class var _OnHide : TProc;
  private
    FCursor : TCursor;
  protected
    constructor Create;
  public
    destructor Destroy; override;

    class function Show : IInterface;
    class property OnShow : TProc read _OnShow write _OnShow;
    class property OnHide : TProc read _OnHide write _OnHide;
  end;

implementation

{ TWaitCursor }

constructor TWaitCursor.Create;
begin
  inherited;
  FCursor := Screen.Cursor;
  Screen.Cursor := crHourGlass;
  if Assigned( _OnShow )
  then
    _OnShow( );
end;

destructor TWaitCursor.Destroy;
begin
  _Instance := nil;
  Screen.Cursor := FCursor;
  if Assigned( _OnHide )
  then
    _OnHide( );
  inherited;
end;

class function TWaitCursor.Show : IInterface;
begin
  if not Assigned( _Instance )
  then
    _Instance := TWaitCursor.Create;
  Result := _Instance;
end;

end.
Beispiel
Delphi-Quellcode:
procedure Foo;
begin
  TWaitCursor.Show;
  Sleep( 1000 );
end;

procedure Bar;
begin
  TWaitCursor.Show;
  Foo;
end;
Kaum macht man's richtig - schon funktioniert's
Zertifikat: Sir Rufo (Fingerprint: ‎ea 0a 4c 14 0d b6 3a a4 c1 c5 b9 dc 90 9d f0 e9 de 13 da 60)

Geändert von Sir Rufo ( 2. Jun 2014 um 09:43 Uhr)
  Mit Zitat antworten Zitat