Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 10 of 22 total
Thread Waiting For Completion
Sat, Apr 16 2016 2:11 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

Is there any way to wait until something has finished?

I have a class that, via ajax, loads some data through a "fetch" method.  Problem is that the ajax on complete is a callback, as is the LoadRows for the resulting dataset, which means nothing waits.

I need to be able to :
  classInstance:=ClassType.Create;
  classInstance.FetchAll;
  classInstance.First;
  Log(classInstance.ID);

It all works if I put the code after the fetchAll in the click event of a button, because by then the data is loaded. But I want to be able to do it like above, in a sequential code block.

But it's happening so fast the data isn't ready yet. Attempts to wait in the methods don't work (tight loops with no obvious way to yield).

Would welcome either a solution or a pointer to a better way.

Cheers.
Sat, Apr 16 2016 3:07 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

The words I was looking for that seemed to escape me earlier were - can I force the normally asynchronous operations to be synchronous by some shenanigans or other?
Sun, Apr 17 2016 3:54 PMPermanent Link

squiffy

Telemix Ltd.

Avatar

Forget it.
I set a callback for afterLoad to a local proc in the calling form. Still think it's a bit ugly but it seems to work.
Mon, Apr 18 2016 10:36 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

<< Forget it. >>

You do realize that you're posting on the weekend, correct ?  I won't respond until Monday morning at the earliest.

<< I set a callback for afterLoad to a local proc in the calling form. Still think it's a bit ugly but it seems to work. >>

That's how you deal with asynchronous operations - you have them notify you when they're done.

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Apr 18 2016 10:50 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

>>>>Forget it.
>> You do realize that you're posting on the weekend, correct ?  I won't respond until Monday morning at the earliest.

Tim - please don't read me wrongly - I'm not expressing any frustration at response times. I know this is not a 24/7 help desk.

I quite literally just meant forget it. Don't worry about it. I no longer need any response as I've worked it out or worked around it. I do get the feeling (from this and other posts) that I'm quite misunderstood on here. Which is fine, as that's probably my fault for the way I speak & therefore type. But I'm honestly not getting irritable or impatient. It's just how I write, quite often amidst the fog of development.

I shall endeavour to appear less terse.
Mon, Apr 18 2016 11:22 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com


<< Tim - please don't read me wrongly - I'm not expressing any frustration at response times. I know this is not a 24/7 help desk. >>

I just got the impression from this post and the one re: 4 hours of work that you were frustrated about not getting answers.  If that's not the case, then no worries. Smile

Tim Young
Elevate Software
www.elevatesoft.com
Mon, Apr 18 2016 11:25 AMPermanent Link

squiffy

Telemix Ltd.

Avatar

>> I just got the impression from this post and the one re: 4 hours of work
>> that you were frustrated about not getting answers.  If that's not the case, then no worries. Smile

My frustration is always at my own inability to find a solution, quite often in the obvious places. I always, always assume a problem is my fault, because it nearly always is. I appreciate that I leave out context sometimes.
Tue, Sep 13 2016 1:11 AMPermanent Link

Trinione

<< I set a callback for afterLoad to a local proc in the calling form. >>

How is this done? I believe I have a need to do this.

My situation is that I am using a function to see if a unique record exists in a DataSet and I don't know how to get the information from the AfterLoad event.

Any help would be appreciated.
Tue, Sep 13 2016 6:09 AMPermanent Link

erickengelke

Avatar

Trinione wrote:

<< I set a callback for afterLoad to a local proc in the calling form. >>

>How is this done? I believe I have a need to do this. >>


>My situation is that I am using a function to see if a unique record exists in a DataSet and I don't know how to get the information from the AfterLoad event.

In the after load event, you cycle through tdataset  using tdataset.first, then tdataset.next until you either find your desired results or you hit tdataset.eof.

Erick  
Tue, Sep 13 2016 9:51 AMPermanent Link

Trinione

Erick wrote:
<< In the after load event, you cycle through tdataset  using tdataset.first, then tdataset.next until you either find your desired results or you hit tdataset.eof. >>


I mean how can I get to the calling Function program a value, True or False in this case - but it could be a string or integer, and value really.

For instance, from the code below - from a function in another program, how can the value of recFound be returned?


function RecExistsInDataSet(ds:TDataSet): boolean;
begin
 dsCustomer.Params.Clear;
 dsCustomer.Params.Add('id=' + 2);
 Database.LoadRows(dsCustomer);
end;


procedure TdmDataModule.dsCustomerAfterLoad(Sender: TObject);
var
 recFound: boolean;

begin
 recFound := False;

 if dsCustomer.RowCount > 0 then
   recFound := True;
end;
Page 1 of 3Next Page
Jump to Page:  1 2 3
Image