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: Vernichten von Application.Processmessages

  Alt 20. Mai 2015, 13:01
Ja, ja ...

Dann ebend so ... menno

Delphi-Quellcode:
procedure TForm1.QueueMeasureTextControl( AText: TText );
begin
  TThread.ExecLater<TText>( MeasureTextControl, AText );
end;
Gut, dafür braucht man einen ThreadHelper
Delphi-Quellcode:
unit ThreadHelper;

interface

uses
  System.Classes,
  System.SysUtils;

type
  TThreadHelper = class helper for TThread
    class procedure ExecLater( AProc: TProc ); overload;
    class procedure ExecLater<T>( AProc: TProc<T>; AArg: T ); overload;
    class procedure ExecLater<T1, T2>( AProc: TProc<T1, T2>; AArg1: T1; AArg2: T2 ); overload;
    class procedure ExecLater<T1, T2, T3>( AProc: TProc<T1, T2, T3>; AArg1: T1; AArg2: T2; AArg3: T3 ); overload;
    class procedure ExecLater<T1, T2, T3, T4>( AProc: TProc<T1, T2, T3, T4>; AArg1: T1; AArg2: T2; AArg3: T3; AArg4: T4 ); overload;
  end;

implementation

{ TThreadHelper }

class procedure TThreadHelper.ExecLater( AProc: TProc );
begin
  TThread.CreateAnonymousThread(
    procedure
    begin
      TThread.Current.Synchronize(
        procedure
        begin
          AProc( );
        end );
    end ).Start( );
end;

class procedure TThreadHelper.ExecLater<T1, T2, T3, T4>( AProc: TProc<T1, T2, T3, T4>; AArg1: T1; AArg2: T2; AArg3: T3; AArg4: T4 );
begin
  TThread.CreateAnonymousThread(
    procedure
    begin
      TThread.Current.Synchronize(
        procedure
        begin
          AProc( AArg1, AArg2, AArg3, AArg4 );
        end );
    end ).Start( );
end;

class procedure TThreadHelper.ExecLater<T1, T2, T3>( AProc: TProc<T1, T2, T3>; AArg1: T1; AArg2: T2; AArg3: T3 );
begin
  TThread.CreateAnonymousThread(
    procedure
    begin
      TThread.Current.Synchronize(
        procedure
        begin
          AProc( AArg1, AArg2, AArg3 );
        end );
    end ).Start( );
end;

class procedure TThreadHelper.ExecLater<T1, T2>( AProc: TProc<T1, T2>; AArg1: T1; AArg2: T2 );
begin
  TThread.CreateAnonymousThread(
    procedure
    begin
      TThread.Current.Synchronize(
        procedure
        begin
          AProc( AArg1, AArg2 );
        end );
    end ).Start( );
end;

class procedure TThreadHelper.ExecLater<T>( AProc: TProc<T>; AArg: T );
begin
  TThread.CreateAnonymousThread(
    procedure
    begin
      TThread.Current.Synchronize(
        procedure
        begin
          AProc( AArg );
        end );
    end ).Start( );
end;

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)
  Mit Zitat antworten Zitat