OmniThread: How to pass a TRect in SetParameter?

荒凉一梦 提交于 2019-12-10 11:54:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!