【发布时间】:2011-07-05 15:06:38
【问题描述】:
我有一个关于在主线程 TPanel 上单独创建主线程 TButton 的问题。 TPanel 必须设置为 TButton 的父级。
ButtonVariableName := TButton.Create (
(Form1.FindComponent('PanelNameString') as TComponent)
);
ButtonVariableName.Parent := (
(Form1.FindComponent('PanelNameString') as TWinControl)
);
不工作...
ButtonVariableName 在主线程上。
TButton.Create() 在单独的 TThread 上被调用。
ButtonVariableName.Parent 也从单独的TThread 调用。
FindComponent 似乎正在崩溃。当我删除它并在那里放置其他东西时它可以工作。从单独的TThread 调用时,FindComponent 可能不起作用,但我不确定。
任何指针^? 哈哈。
-i2programmer
【问题讨论】:
-
Windows 与创建它们的线程有关联。在实践中,这使得构建具有多个线程的 UI 几乎是不可能的。这也是没有意义的。将 UI 放在主线程中,并在线程外运行长时间运行的非可视任务。
-
放弃 - 甚至尝试将线程与 UI 控件一起使用是绝对没有意义的。
标签: multithreading delphi button panel lazarus