问题
In a program using the OmniThread library, how can I pass a TRect in SetParameter? Example:
procedure TestParameters(const ATask: IOmniTask);
begin
// how can I access the TRect here?
end;
FTestTask := CreateTask(TestParameters, 'TestParameters')
.MonitorWith(OTLMonitor)
.SetParameter('FormRect', Self.ClientRect) // does not work
.Run;
Is there a general rule how to use different types in SetParameter?
回答1:
Use TOmniValue.FromRecord<T>
and TOmniValue.ToRecord<T>
.
procedure TestParameters(const ATask: IOmniTask);
var
formRect: TRect;
begin
formRect := ATask.Param['FormRect'].ToRecord<TRect>;
end;
FTestTask := CreateTask(TestParameters, 'TestParameters')
.MonitorWith(OTLMonitor)
.SetParameter('FormRect', TOmniValue.FromRecord<TRect>(ClientRect))
.Run;
来源:https://stackoverflow.com/questions/25991056/omnithread-how-to-pass-a-trect-in-setparameter