unit lib.livedata;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, event.types, DateUtils;
type
// Ergebniswerte Callback
TAsyncLivedataResult =
record
ErroText:
String;
ApplicationTimestamp:
String;
OPCConncetionTimestamp:
String;
ErrorCode: Integer;
// Fehlercode im Fehlerfall, sonst 0 (=LIVEDATA_OK)
end;
TLivedataCallback =
procedure(LivedataResult: TAsyncLivedataResult)
of Object;
TLivedataThread =
class(TThread)
FLivedataResult: TAsyncLivedataResult;
FCallback: TLivedataCallback;
protected
procedure Execute;
Override;
procedure DoCallbackVCL;
public
constructor Create(Callback: TLivedataCallback);
overload;
end;
function ExecuteAsync(Callback: TLivedataCallback): Boolean;
implementation
{ EventTypes }
constructor TLivedataThread.Create(Callback: TLivedataCallback);
begin
inherited Create(TRUE);
// Thread gestoppt erzeugen
FreeOnTerminate := TRUE;
// Callback definieren
FCallback := Callback;
// Thread starten, ruft .Execute auf
Suspended := FALSE;
end;
procedure TLivedataThread.DoCallbackVCL;
begin
FCallback(FLivedataResult)
end;
procedure TLivedataThread.Execute;
begin
// Code....
// Callback
if Assigned(FCallback)
then // Callback-Funktion übergeben?
Synchronize(DoCallbackVCL);
// dann VCL-fähig ausführen
end;
function ExecuteAsync(Callback: TLivedataCallback): Boolean;
begin
Result := TRUE;
TLivedataThread.Create(Callback);
end;
end.