[英]MultiThreading in Delphi FMX
I'm trying to iterate though a TClientDataSet
and refresh a TLabel
and a TProgressBar
in Android, but I get this error. 我试图通过TClientDataSet
进行迭代,并在Android中刷新TLabel
和TProgressBar
,但出现此错误。 How can I fix it? 我该如何解决?
This is the execute procedure. 这是执行过程。 is the first time i'm working wuth multithreads in Delphi and i would like to know about that. 这是我第一次在Delphi中使用多线程,我想知道这一点。
I hope you can help me. 我希望你能帮助我。
procedure TThreadCatalogos.Execute;
var i : Integer;
AppPath : string;
begin
AppPath := System.IOUtils.TPath.GetPublicPath;
ProgressBar.Min := 0;
for i := round(ProgressBar.Min) to round(ProgressBar.Max) do begin
// check if Self(thread) is terminated, if so exit
if Terminated then
Exit;
Position := i;
{*******************************************}
Conexion.Open;
//CLIENTES
dsClientes.Open;
//mtClientes.EmptyDataSet;
dsClientes.First;
ProgressBar.Max := dsClientes.RecordCount;
while not dsClientes.Eof do
begin
if not mtClientes.Locate('nombre',dsClientes.FieldByName('nombre').AsString,[]) then
begin
Synchronize(procedure()
begin
mtClientes.Insert;
mtClientes.Fields[0].Value := dsClientes.FieldByName('cliente_id').Asinteger;
mtClientes.Fields[1].Value := dsClientes.FieldByName('nombre').AsString;
mtClientes.Fields[2].Value := dsClientes.FieldByName('tipo').AsString;
mtClientes.Post;
mtClientes.SaveToFile(System.IOUtils.TPath.combine(AppPath,'CLIENTES.bin'),sfBinary);
lbl.Text := 'Cliente '+floattostr(ProgressBar.Value)+' de '+floattostr(ProgressBar.Max);
ProgressBar.Value := ProgressBar.Value + 1;
end);
dsClientes.Next;
end;
//mtClientes.SaveToFile(System.IOUtils.TPath.combine(AppPath,'CLIENTES.xml'),sfXML);
mtClientes.First;
end); Exit;
end;
{************************************************}
end;
end;
To update a progress bar in a main thread from a child thread one approach is to: 要从子线程更新主线程中的进度条,一种方法是:
This prevents updating the progress bar too often and lets the thread do a very quick updates to progress. 这样可以防止过于频繁地更新进度条,并使线程可以非常快速地更新进度。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.