[SOLVED]Who can really provide the right code... lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Robert W.B. · 2012-10-08 21:41 to make lazarus work like Delphi. I use URLmon with Delphi to get an Url in text but,in Lazarus it don't work and not with synapse or curl! Is there a way for Lazarus to use URLmon from Delphi? This is the only way that keeps me to still use Delphi and not Lazarus as a professional Developtools. Synapse and CUrl!I have give up on these unsupported libraries. Have anyone the knowledge? ---------------------------------------------------------------------- User137 · 2012-10-09 01:03 Could you provide a sourcecode from simple test program that fails? Someone might be able to point out if there is mistakes. Also as far as i know, Synapse is still being actively developed. There is SVN version of it same way as Lazarus and freepascal. ---------------------------------------------------------------------- Leledumbo · 2012-10-09 03:07 QuoteSynapse and CUrl!I have give up on these unsupported libraries.Synapse IS supported and actively developed, have you ever even asked about it at least here or directly to the author? ---------------------------------------------------------------------- Robert W.B. · 2012-10-10 20:40 I tried to mail the author but,the mail-account of his, is not working! Maybe he dont want any mail! ---------------------------------------------------------------------- User137 · 2012-10-10 22:08 You can always ask here what you would have asked of him. Is there a problem setting up SVN version of Synapse, or still a problem with specific code? We cannot help without information. ---------------------------------------------------------------------- Laksen · 2012-10-10 23:14 The following works great for me. Your question was a little vague though. A mistake often made when working with Synapse is trying to access HTTPS pages without having added an SSL unit. For that you can use for example the ssl_openssl unit(requires openssl libraries installed) Code: [Select]uses classes, httpsend; function DownloadUrl(const AUrl: string): string; var ss: TStringStream; begin    ss := TStringStream.Create('');    try       if HttpGetBinary(AUrl, ss) then       begin          ss.Seek(0, soBeginning);          result := ss.DataString;       end       else          result := 'Failed to download URL';    finally       ss.Free;    end; end; ---------------------------------------------------------------------- Robert W.B. · 2012-10-11 00:33 Thanks for the code but,how do You call the URL with DownloadURL?  I use this link and it wont work!I think it has something to do that the company change the Url from Http to Https if HttpGetURL('myurl','mytextfile.txt')=True then begin some code... end; and the function function HttpGetFile(const URL: String; const FileName: String): Boolean; var   Stream: TFileStream; begin   Stream := TFileStream.Create(FileName, fmCreate);   try     Result := HttpGetBinary(URL, Stream);   finally     Stream.Free;   end; end; and it dosent work now but it has worked before the company switchfrom Http to Https ---------------------------------------------------------------------- User137 · 2012-10-11 00:43 You can test by inserting the same url directly to webbrowser, and see if it can open it either. Preferrably use browser where you don't have previous cache or possible saved passwords about it. ---------------------------------------------------------------------- Robert W.B. · 2012-10-11 00:50 The URL I use are open fine in the browser but, it don,t work with synapse! Can You provide me with the right code for downloading an URL with the function I've got! There was to missing end; in the code but they are there now. Uses http; function DownloadUrl(const AUrl: string): string; var ss: TStringStream; begin    ss := TStringStream.Create('');    try       if HttpGetBinary(AUrl, ss) then       begin          ss.Seek(0, soBeginning);          result := ss.DataString;       end       else          result := 'Failed to download URL';    finally       ss.Free; end;  and the URl should be? DownloadUrl code code ---------------------------------------------------------------------- Laksen · 2012-10-11 00:57 You have to add an SSL driver. HTTPS is not handled by default in Synapse. One such driver is openssl. To use that: Add ssl_openssl to your uses list, and install the openssl library. That should fix it ---------------------------------------------------------------------- Robert W.B. · 2012-10-11 01:06 I added ssl_openssl to my uses list but,it dont work! I cant get the url! Same problem.  Is there more code I shall provide in my function? ---------------------------------------------------------------------- Laksen · 2012-10-11 01:21 Did you also install openssl? http://www.openssl.org/ ---------------------------------------------------------------------- Robert W.B. · 2012-10-11 01:26 Sorry but, I use Windows 7 64 bit today and not Linux. Are there now Windows file to download? ---------------------------------------------------------------------- Laksen · 2012-10-11 01:34 Yes. A simple search returns this, where I also got it from: http://slproweb.com/products/Win32OpenSSL.html ---------------------------------------------------------------------- Timewarp · 2012-10-11 06:48 I'm using urlmon and I don't have problems with it, works just like in Delphi. Problem is missing urlmon.pas on something else? Show the Delphi code ---------------------------------------------------------------------- BeniBela · 2012-10-11 09:07 Btw there are also my internet tools to download a file: Code: [Select]uses bbutils, simpleinternet; .. strSaveToFileUTF8('c:\where.want.to.save.it.to.html', retrieve('http://www.google.de')); (this will use wininet on Windows, and synapse on Linux) ---------------------------------------------------------------------- Robert W.B. · 2012-10-17 15:28 Hi Timewarp. How can i use Urlmon in Lazarus? Where can i download Urlmon.pas for Lazarus? ---------------------------------------------------------------------- ludob · 2012-10-17 17:19 Quote from: robbanux on October 17, 2012, 05:28:39 pmHi Timewarp. How can i use Urlmon in Lazarus? Where can i download Urlmon.pas for Lazarus? There is no UrlMon for lazarus fpc. Most of UrlMon is interface definitions for monikers, callbacks, etc., which are hard to implement with fpc. For what you want to do you don't need this fancy stuff. Here is an easy way of doing what you want with urlmon: Code: [Select]function URLDownloadToFile(pCaller: pointer; URL: PChar; FileName: PChar; Reserved: DWORD; lpfnCB : pointer): HResult; stdcall; external 'urlmon.dll' name 'URLDownloadToFileA'; procedure TForm1.Button1Click(Sender: TObject); var Source, Dest: string; begin  Source:='http://lazarus.freepascal.org';  Dest:='C:\Windows\temp\data.txt';  if URLDownloadToFile(nil, PChar(Source), PChar(Dest), 0, nil)=0 then   showmessage('Download ok!')  else   showMessage('Error downloading '+Source); end; ---------------------------------------------------------------------- Robert W.B. · 2012-10-17 23:55 Laksen.It don't work with windows 32 bit ssl either! It's better that Lazarus developteam implement a solution like Urlmon,directly in Lazarus and take the next step to professionality! Delphi fixed Urlmon in the 1990 so, why must Lazarus be depending of Libraries, from third partners, that is not updated! If I see Lazarus implement a library like Urlmon, I will defently donate. ---------------------------------------------------------------------- Laksen · 2012-10-18 00:56 QuoteLaksen.It don't work with windows 32 bit ssl either! Why? Errors? Crashes? You mention 32 bit. Are you also compiling the program for 32bit? QuoteIt's better that Lazarus developteam implement a solution like Urlmon,directly in Lazarus and take the next step to professionality! Delphi fixed Urlmon in the 1990 so, why must Lazarus be depending of Libraries, from third partners, that is not updated! If I see Lazarus implement a library like Urlmon, I will defently donate. Given the emphasis on crossplatformity of the Lazarus system, using UrlMon would be a step away from professionality in my opinion. You could even take a look at all the documentation for the DLL(which seems to be part of Internet Explorer), http://msdn.microsoft.com/en- us/library/ms775123(v=vs.85).aspx Especially the part that says "[This documentation is preliminary and is subject to change.]". Seems a little risky, and not very professional If you really need it you can find an urlmon unit somewhere else. Download the newest version of the JEDI WIN32 headers. There it's included as JwaUrlmon.pas, which with minor changes can be used just fine. You can even find a urlmon.pas unit straight by searching on google which compiles if you insert a {$mode delphi}. I don't know the licenses of such headers, but I doubt it's a problem. I guess the reason why this thing isn't supported by Lazarus is that it strives to be crossplatform. Urlmon is a wrapper over a windows DLL, and hence not very interesting when there are open-source and crossplatform tools such as Synapse and many others available ---------------------------------------------------------------------- Timewarp · 2012-10-18 09:31 Quote from: robbanux on October 17, 2012, 05:28:39 pmHi Timewarp. How can i use Urlmon in Lazarus? Just check post by ludob, you can use other urlmon functions similar way. Quotewhen there are open-source and crossplatform tools such as Synapse and many others available When you develop only for Windows, it doesn't make sense to use extra packages / crossplatform solutions, it just adds weigth and not always work (as seen here). I have used urlmon/msxml for networking in Delphi for years, it works well no matter if user has Win98 or Win8 or https ---------------------------------------------------------------------- Robert W.B. · 2012-10-19 12:25 I'm so Bloody happy,you can't Imagine   LUDOB I got it.  UrlMon.dll is already in Windows. I don't have to mess with no other libraies. It Solved the ssl HTTPS thing and work like in Delphi. Thank You Thank You everybody for the help. Now I got to convert my heaviest program from Delphi and see if it works. Have a great weekend. I'm so happy. I Love Lazarus and thank You  Lazarus Team.  The solution: function URLDownloadToFile(pCaller: pointer; URL: PChar; FileName: PChar; Reserved: DWORD; lpfnCB : pointer): HResult; stdcall; external 'urlmon.dll' name 'URLDownloadToFileA'; procedure TForm1.Button1Click(Sender: TObject); var Source, Dest: string; begin  Source:='http://lazarus.freepascal.org';  Dest:='C:\Windows\temp\data.txt';  if URLDownloadToFile(nil, PChar(Source), PChar(Dest), 0, nil)=0 then   showmessage('Download ok!')  else   showMessage('Error downloading '+Source); end; Solution from the bugtracker. http://bugs.freepascal.org/bug_view_advanced_page.php?bug_id=23107&his tory=1 Best regards Robbanux ---------------------------------------------------------------------- BigChimp · 2012-10-19 12:36 Glad it works. I think people will appreciate a small sample program in this wiki article for reference: http://wiki.lazarus.freepascal.org/Windows_Programming_Tips#Code_snipp ets Just added it. Please review/correct PS: Hope more people "pay the wiki tax" if they are helped with code snippets etc. The wiki is becoming a very valuable source of help/information, a bit more structured than the forum/bugtracker That's just my opinion of course (and not specifically directed at the people in this thread, but in general)... ---------------------------------------------------------------------- taazz · 2012-10-19 12:52 Quote from: BigChimp on October 19, 2012, 02:36:38 pmPS: Hope more people "pay the wiki tax" if they are helped with code snippets etc. The wiki is becoming a very valuable source of help/information, a bit more structured than the forum/bugtracker That's just my opinion of course (and not specifically directed at the people in this thread, but in general)... Personally I find the wiki a bit difficult to use, the search most of the times does not bring up what I'm looking for, I have to dig around various pages to find it, and there is no index that has all the pages that I can browse for interesting information, something like the tree on the left on the chm help files for example. I have more success using google to search than the wiki and that stops me from using it really, I do not know if there is any extension to make it more noob friendly but If I were in the teams position I would be searching for a replacement. When I have some free time I will search for alternatives. Just my personal experience. ---------------------------------------------------------------------- BigChimp · 2012-10-19 13:39 Yep, everybody's different. I dislike searching through the forum If all else fails, a Google search with site:wiki.lazarus.freepascal.org probably works quite well...