【发布时间】:2018-09-27 10:36:24
【问题描述】:
我尝试做一个函数:
function MyFunction(parameter:string) : string;
begin
TThread.CreateAnonymousThread(procedure ()
var temp : string;
begin
temp := paramet;
//some works on temp variable
result := temp; <-- error here because it is a procedure
end).Start;
end;
如何让MyFunction在线程结束后返回临时变量?
我也试过这样:
function MyFunction(parameter:string) : string;
vat temp : string;
begin
TThread.CreateAnonymousThread(procedure ()
begin
temp := paramet;
//some works on temp variable
end).Start;
result := temp;
end;
以这种方式编译但返回一个空字符串。函数返回结果,不等待线程结束。
或者也许我做错了,因为我没有找到任何示例如何做到这一点?
【问题讨论】:
-
如果
MyFunction需要在退出之前等待结果,那么使用线程根本没有意义。
标签: multithreading delphi delphi-xe5