![]() |
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 ... |
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
Try the following changes:
databuffer : array[0..4095*sizeof(char)] of char; dwNumber := sizeof(databuffer) div sizeof(char); for i := 0 to sizeof(char)-1 do databuffer[dwread*sizeof(char)-i]:=#0; untested |
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
In both Indy 9 and Indy 10 i use idhttp1.get(URL) to get the sitecontent..
|
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
Hi DelphiLover,
despite the fact that you are currently trying to use an approach without Indy for solving your problem I just wanted to let you know that the TIdHTTP component does not have the need to assign an IO handler. I am currently using the .GET of it without any assigned IO handler inside of my own commercial application. It has been working for a long time now. Using the Indy 10 shipped with Delphi < 2007 as well as the latest available D2009 release version and our own SVN version. I would suggest trying to create a clean project and use a basic test procedure to check whether it is Indy or something else involved. By the way: No matter what you hear from others - Indy 9 is more or less deprecated. Indy 10 has had some stability issues and bugs after beeing published but that's also quite some years (!) ago now. The current source is as stable as Indy 9 has been (which also has not been bug free). As you mentioned correctly some issues users have a related to the high abstraction layer Indy provides. There have been many discussions about that including comments from famous TeamB members like Peter Below or Remy LeBeau. Anyways, good luck for solving your current problem. If you try to do some further tests using Indy you're welcome to give feedback here in order to help us solving the problem. Cheers Assertor |
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
I was the one who restarted this thread after several years, i had the example code in one of my projects - found it via google and used it instead of using indy.
After a bit of research, i found out that this code works as well (and is less likely to produce errors):
Delphi-Quellcode:
Thx to Angel4585 :-)
var
idHtp1:TIdHttp; begin idHtp1:=TIdHTTP.Create(nil); Result := ''; try try Result := idHtp1.Get(AUrl); finally FreeAndNil(idhtp1); end; except ; end; end; |
Re: How to Use Indy 10 idHTTP : IOHandler value is not valid
Zitat:
Cheers Assertor |
Alle Zeitangaben in WEZ +1. Es ist jetzt 09:43 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