| View previous topic :: View next topic |
| Author |
Message |
micheln Newbie

Joined: 10 Jan 2010 Posts: 5
|
Posted: Sat Mar 06, 2010 12:54 pm Post subject: Async Request - Multithreading |
|
|
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 |
|
 |
hgourvest Site Admin
Joined: 22 Jun 2008 Posts: 617
|
Posted: Wed Mar 10, 2010 9:08 am Post subject: |
|
|
| 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 |
|
 |
micheln Newbie

Joined: 10 Jan 2010 Posts: 5
|
Posted: Mon Mar 15, 2010 8:44 pm Post subject: Merci beaucoup |
|
|
Merci beaucoup
J'essaye ça tout de suite
Encore Merci  |
|
| Back to top |
|
 |
moez-slimi Newbie

Joined: 05 Apr 2010 Posts: 1
|
Posted: Mon Apr 05, 2010 11:21 pm Post subject: Entire sample app |
|
|
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 |
|
 |
|