Registriert seit: 25. Sep 2004
79 Beiträge
Delphi XE7 Professional
|
AW: RTTI-Fehler bei DSharp
10. Feb 2013, 19:02
Ich würde das wie folgt lösen:
Delphi-Quellcode:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, RTTI, DSharp.Core.Events,
DSharp.Core.Reflection;
type
{$M+}
TTestEvent = reference to procedure(S: string; const Args: TArray<TValue>);
{$M-}
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
procedure Button1Click(Sender: TObject);
private
FTestEvent: Event<TTestEvent>;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Format( const Format: string; const Args: array of TValue): string;
begin
Result := System.SysUtils.Format(Format, TValue.ToVarRecs(Args));
end;
procedure LogMessage( const AText: string; const AValues: array of TValue);
var
Values: TArray<TValue>;
begin
Form1.FTestEvent.Add(
procedure(S: string; const Args: TArray<TValue>)
var
LMessage: string;
begin
LMessage := Format(S, Args);
Form1.Memo1.Lines.Add(LMessage);
end);
Values := TArrayHelper.Copy<TValue>(AValues);
Form1.FTestEvent.Invoke(AText, Values);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
LogMessage(' message: %s %d', [' test', 1234]);
end;
end.
|
|
Zitat
|