progdigy.com Forum Index progdigy.com

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Async Request - Multithreading

 
Post new topic   Reply to topic    progdigy.com Forum Index -> JSON - SuperObject
View previous topic :: View next topic  
Author Message
micheln
Newbie
Newbie


Joined: 10 Jan 2010
Posts: 5

PostPosted: Sat Mar 06, 2010 12:54 pm    Post subject: Async Request - Multithreading Reply with quote

Hi all

While trying the google demo I noticed that the GUI freezes while waiting for results.
is it possible to send the XMLhttp asynchronously or in a separate thread?
Back to top
View user's profile Send private message
hgourvest
Site Admin


Joined: 22 Jun 2008
Posts: 617

PostPosted: Wed Mar 10, 2010 9:08 am    Post subject: Reply with quote

Code:
  var
    req: IXMLHttpRequest;
  begin
    req := {$IFDEF VER210}CoXMLHTTP{$ELSE}CoXMLHTTPRequest{$ENDIF}.Create;
    req.open('GET', 'http://www.example.com', true, EmptyParam, EmptyParam);
    req.onreadystatechange := TOnReadyStateChange.Create(req);
    req.send(EmptyParam);
  end;

  TOnReadyStateChange = class(TInterfacedObject, IDispatch)
  private
    FCnx: IXMLHttpRequest;
  protected
    function GetTypeInfoCount(out Count: Integer): HResult; stdcall;
    function GetTypeInfo(Index, LocaleID: Integer; out TypeInfo): HResult; stdcall;
    function GetIDsOfNames(const IID: TGUID; Names: Pointer;
      NameCount, LocaleID: Integer; DispIDs: Pointer): HResult; stdcall;
    function Invoke(DispID: Integer; const IID: TGUID; LocaleID: Integer;
      Flags: Word; var Params; VarResult, ExcepInfo, ArgErr: Pointer): HResult; stdcall;
  public
    constructor Create(const cnx: IXMLHttpRequest);
  end;


{ TOnReadyStateChange }

constructor TOnReadyStateChange.Create(const cnx: IXMLHttpRequest);
begin
  FCnx := cnx;
end;

function TOnReadyStateChange.GetIDsOfNames(const IID: TGUID; Names: Pointer;
  NameCount, LocaleID: Integer; DispIDs: Pointer): HResult;
begin
  Result := E_NOTIMPL;
end;

function TOnReadyStateChange.GetTypeInfo(Index, LocaleID: Integer;
  out TypeInfo): HResult;
begin
  Result := E_NOTIMPL;
end;

function TOnReadyStateChange.GetTypeInfoCount(out Count: Integer): HResult;
begin
  Result := E_NOTIMPL;
end;

function TOnReadyStateChange.Invoke(DispID: Integer; const IID: TGUID;
  LocaleID: Integer; Flags: Word; var Params; VarResult, ExcepInfo,
  ArgErr: Pointer): HResult;
var
  o: ISuperObject;
begin
  if FCnx.readyState = 4 then
  begin
     // <===== your code here
     FCnx.onreadystatechange := nil;
  end;
  Result := S_OK;
end;
Back to top
View user's profile Send private message Send e-mail
micheln
Newbie
Newbie


Joined: 10 Jan 2010
Posts: 5

PostPosted: Mon Mar 15, 2010 8:44 pm    Post subject: Merci beaucoup Reply with quote

Merci beaucoup Smile
J'essaye ça tout de suite Smile


Encore Merci Smile
Back to top
View user's profile Send private message
moez-slimi
Newbie
Newbie


Joined: 05 Apr 2010
Posts: 1

PostPosted: Mon Apr 05, 2010 11:21 pm    Post subject: Entire sample app Reply with quote

could you please post the entire sample app code?
_________________
----------------------------------
The Only Thing Greater Than the Power of the Mind is the Courage of the Heart
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    progdigy.com Forum Index -> JSON - SuperObject All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group