OmniThread:如何在SetParameter中传递TRect?

时间:2014-09-23 09:04:41

标签: delphi parallel-processing delphi-xe2 omnithreadlibrary

在使用OmniThread库的程序中,如何在SetParameter中传递TRect?例如:

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;

是否有一般规则如何在SetParameter中使用不同的类型?

1 个答案:

答案 0 :(得分:4)

使用TOmniValue.FromRecord<T>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;