hi im new to delphi. how to use the two function at the same time? function a(...):integer; function b(...):integer;
because b waits until a is finshed.
hi im new to delphi. how to use the two function at the same time? function a(...):integer; function b(...):integer;
because b waits until a is finshed.
It is done using threads. It is an advanced topic, however, and you can better first learn the basics of programming before you start with threads.
you probobly need Multi-threading. you can start with tutorial in about.com
there's also "AsyncCalls" library which does what you need. Please have a look at http://andy.jgknet.de/blog/?page_id=100
Assuming Delphi 2009 or above and using OmniThreadLibrary:
uses OtlParallel;
var
aRes: integer;
bRes: integer;
begin
Parallel.Join(
procedure begin
aRes := a();
end,
procedure begin
bRes := b();
end);
end.
Or for purists who don't like anonymous functions:
uses OtlParallel;
var
aRes: integer;
bRes: integer;
procedure CalcA;
begin
aRes := a();
end;
procedure CalcB;
begin
bRes := b();
end;
begin
Parallel.Join(CalcA, CalcB);
end.
(It work work the same if CalcA and CalcB are methods, not plain procedures.)
As others have stated, the field of multithreading programming is full of danger. Make sure that your two functions are not modifying same structures, not outputing data to a same destination and, most of all, that they are not using GUI in any way.
can you explain in detail? because, maybe we can find another solution for you...
best regards,