Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Problem with using TIdSSLIOHandlerSocketOpenSSL


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 0
Enquiring Mind

Posts: 88
Registered: 10/6/08
Problem with using TIdSSLIOHandlerSocketOpenSSL  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 9, 2018 6:56 AM
Hi,

I have a program which downloads map tiles from various OpenStreetMap tile servers. I have tried adding support for the server

https://c.tile.opentopomap.org

and a request such as

https://c.tile.opentopomap.org/15/16331/10933.png

works in my web browser. But when called from my Delphi 7 code it throws the following exception:

EIdIOHandlerPropInvalid with message 'IOHandler value is not valid'

After searching for a solution to this on the web I found the useful advice on the page:

https://stackoverflow.com/questions/11554003/tidhttp-get-eidiohandlerpropinvalid-error

So I modified my code as follows:

uses Types, Classes, SysUtils, Forms, UnitBaseTypes,
     IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, IdSSLOpenSSL,
     Graphics, JPeg, pngimage, UnitIntervalUtils, UnitRectUtils, UnitByteArrays,
     UnitEllipsoidGeometry, UnitTGPXObjectColn, UnitGraphicsUtils;
const
  {$define include_TIdSSLIOHandlerSocketOpenSSL}
{...}
var
  IdHTTP1: TIdHTTP;
  {$ifdef include_TIdSSLIOHandlerSocketOpenSSL}
  LHandler: TIdSSLIOHandlerSocketOpenSSL;
  {$endif}
 
{...}
 
procedure TMapTile.LoadImage;
var
  MapServer: TMapServer;
  MemoryStream: TMemoryStream;
  Posn: integer;
  SourceURL: string;
  Filename: string;
  FileStream: TFileStream;
begin
  if Length(FImageByteArray)= 0 then
    begin
      {Image file has not already been loaded, so load:}
      MapServer:= GetMapServer;
      {Record image file type:}
      FImageFileType:= TMapServerToTImageFileType(MapServer);
      {Check whether or not tile file is stored on client disc:}
     { Filename:= GetDirectory + '\' +
          GetMapTileFilename(MapServer, ZoomLevel, RowCoord, ColCoord); }
      Filename:= GetPathname;
      if FileExists(Filename) then
        begin
          {Image file exists on client, so record the fact, then read from disc file}
          FImageSourceLocnType:=  isClient;
          {Read byte array from file on client computer:}
          FileStream:= TFileStream.Create(Filename, fmOpenRead);
          try
            try
              SetLength(FImageByteArray, FileStream.Size);
              FileStream.Position:= 0;
              FileStream.ReadBuffer(FImageByteArray[0], FileStream.Size);
            except
              on E: Exception do begin
                E.Message:= E.Message + 'reading ' + Filename;
                raise;
              end;
            end;
          finally
            FileStream.Free;
          end;
        end
      else
        begin
          {The file does not exist on the client disc, so fetch from the server:}
          FImageSourceLocnType:=  isServer;
          {Download byte array from server:}
          MemoryStream:= TMemoryStream.Create;
          try
            {Get data from OpenStreetMap HTTP server into memory stream:}
            SourceURL:=  GetURL {GetTileURL};
            MemoryStream.Position:= 0;
            IdHTTP1.Get(SourceURL, MemoryStream);
            SetLength(FImageByteArray, MemoryStream.Size);
            MemoryStream.Position:= 0;
            MemoryStream.ReadBuffer(FImageByteArray[0], MemoryStream.Size);
          finally
            MemoryStream.Free;
          end;
        end;
    end;
end;
 
initialization
  IdHTTP1:= TIdHTTP.Create(nil);
  {$ifdef include_TIdSSLIOHandlerSocketOpenSSL}
  LHandler := TIdSSLIOHandlerSocketOpenSSL.Create(nil);
  IdHTTP1.IOHandler:= LHandler;
  {$endif}
  IdHTTP1.HandleRedirects := True;
 
finalization
  {$ifdef include_TIdSSLIOHandlerSocketOpenSSL}
  LHandler.Free;
  {$endif}
  IdHTTP1.Free;
end.
 


When I try to compile this I get the error message

[Error] UnitTOpenStreetMapImage.pas(814): Undeclared identifier: 'TIdSSLIOHandlerSocketOpenSSL'

I have checked that the files libeay32.dll, ssleay32.dll are on my system. They are, but possibly not in the right folders for Delphi.

Can anyone suggest what I need to do to get this code to compile and then to successfully download the tile whose URL I gave above?

The Indy library files on my system are very old. How do I update them?

Thanks in advance,

EM

Edited by: Enquiring Mind on Apr 9, 2018 2:57 PM
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02