![]() |
How to Use Indy 10 idHTTP : IOHandler value is not valid
Hello,
Using the idHTTP component in Indy 9 was very easy, but now I want to use the Indy 10 library and I got a lot of problems, even just to get a page from the Web. This is how it goes in Indy 9:
Delphi-Quellcode:
If you do this with Indy 10 then the error message will be raised:
IdHttp:=TIdHttp.Create(NIL);
Try Page:=IdHttp.Get(URL); FStringList.Text:=Page; ..... ..... Finally IdHttp.Free; End; "EidIOHandlerPropInvalid : IOHandler value is not valid" What is the proper declaration in Indy 10 to do this? I don't want to use the components in design time but I want to create it in Runtime. Greets, Delphi Lover. |
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
Hello,
I did some more investigation and I see that working with the Indy 10 components is indeed quite difficult and misty to understand. The component builders wanted to "abstract" the Indy system further, but now it's so abstract that many users have only problems to use the source. On the web you'll see a lot of people telling that they deinstall the Indy 10 and go back to Indy 9. Although the Indy 10 is out now for some time, you'll find not a lot of examples on the web. especially not for Delphi. Very sad for these great components. If anyone know how to use the Indy 10 idHTTP component in Runtime. (with IOhandlers and Intercepts...) please help us out... So, I also used another simple way to get a page from the web, using the WinInet API. This API can work with HTTP and FTP. The interface is very C-like, but it's small and it does what I want, just get me the Webpage. (you also don't have to loop to wait for the webpage to finish...) Here is some source I found on the Web:
Delphi-Quellcode:
Uses WinInet; procedure GetWebPage; var databuffer : array[0..4095] of char; ResStr : string; hSession, hfile, hRequest: hInternet; dwindex,dwcodelen,datalen,dwread,dwNumber: cardinal; dwcode : array[1..20] of char; Str : pchar; AUrl : String; begin FStringList:=TStringList.Create; ResStr:=''; AUrl:='www.google.com'; hSession:=InternetOpen('InetURL:/1.0', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0); if assigned(hsession) then begin hfile:=InternetOpenUrl( hsession, pchar(AUrl), nil, 0, INTERNET_FLAG_RELOAD, 0); dwIndex := 0; dwCodeLen := 10; HttpQueryInfo(hfile, HTTP_QUERY_STATUS_CODE, @dwcode, dwcodeLen, dwIndex); dwNumber := sizeof(databuffer)-1; while (InternetReadfile(hfile, @databuffer, dwNumber, DwRead)) do begin if dwRead =0 then break; databuffer[dwread]:=#0; Str := pchar(@databuffer); resStr := resStr + Str; end; if assigned(hfile) then InternetCloseHandle(hfile); end; InternetCloseHandle(hsession); FStringList.text := resStr; |
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
Hi,
your code works fine for me (using Indy 10 for Win32). Could you tell us the value of "URL" in your case? |
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
This line:
databuffer[dwread]:=#0; throws an ERangeError in Delphi 2009. Anyone has an idea how to fix this ? |
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
What's the value of dwread according to the debugger when this happens?
|
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
dwRead = 8191 when this happens.
I tried to change databuffer to databuffer : array[0..8191] of char; - in this case, dwRead becomes 16383. As dwRead is the number of Bytes, the problem is: Either use Ansistring(1) or change the index(2)? 1: This would only make sense if the returned value also is Ansi-kind of string - and obviosly it is no more, else this wouldn't happen..? 2: Does not make sense for me, because "Number of Bytes to read" should equal "number of Bytes read" - shouldn't it? Can #0 be used for Unicodestrings/Chars anyway? PS: I write in english to ensure the creator of this thread could follow the discussion, too, if he wants ... |
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
Which version of Delphi do you use?
|
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
Zitat:
|
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
Maybe defining all char-/stringtypes as ANSI charset could help.
Delphi-Quellcode:
var
databuffer : array[0..4095] of Ansichar; ResStr : Ansistring; hSession, hfile, hRequest: hInternet; dwindex,dwcodelen,datalen,dwread,dwNumber: cardinal; dwcode : array[1..20] of Ansichar; Str : pAnsichar; AUrl : AnsiString; |
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
Zitat:
The following changes: dwNumber := sizeof(databuffer) - sizeof(char); ... dwLastItem := dwread div SizeOf(char); databuffer[dwLastItem]:=#0; ... do not help either as they lead to invalid data, too ... |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:50 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz