NMHTTP component with Delphi causing error - delphi

After several years gap I have now started using Delphi 5 again. My project uses the Netmaster NMHTTP component to download a file. It used to work but now I get the following error :-
Your browser sent a request that this server could not understand.
The request line contained invalid characters following the protocol string.
The following code executes a Get using the String urlstext.
urlstext := http://download.finance.yahoo.com/d/updatesec.csv?s= ^NMX0530+^NMX570+^NMX1350' +
'+^NMX1730+^NMX1750+^NMX1770+^NMX2350+^NMX2710+^NMX2720+^NMX2730+^NMX2750+^NMX2770+^NMX2790+' +
'^NMX3350+^NMX3530+^NMX3570+^NMX3720+^NMX3760+^NMX3780+^NMX4530+^NMX4570+^NMX5330+^NMX5370+' +
'^NMX5550+^NMX5750+^NMX6530+^NMX6570+^NMX7530+^NMX7570+^NMX8350+^NMX8530+^NMX8570+^NMX8630+' +
'^NMX8670+^NMX8770+^NMX8980+^NMX9530+^NMX9570&f=snl1c1p2&e=.csv'
NMHTTP1Form := TNMHTTP1Form.Create(Self);
try
NMHTTP1Form.NMHTTP1.Get(urlstext);
except
beep;
nmhttp1form.NMHTTP1.RequestCloseSocket;
nmhttp1form.NMHTTP1.Cancel;
MessageStr := Format('%8s %8s %-s',[DateToStr(Date),TimeToStr(Now),'failure in goonline.download ' + OutputFileName]);
Form1.MessageMemo.Lines.Add(MessageStr);
EventLog(MessageStr);
Result := False;
end;
I discovered a reference through Google that this error means a wrong HTTP version is given HTTP request. I assume this is added by the NMHTTP component (out of sight) so I am wondering how I can correct the situation.

While not strictly a correct answer -
Solution #1
Please consider upgrading to latest Delphi XE6 and use latest Indy.
The problem you have is that NMHTTP (NetMasters HTTP) implements a very old version of HTTP protocol and there is no updates.
If you are still using Delphi 5, please consider using Indy for Delphi 5 instead:
http://www.indyproject.org/download/Files/Indy9.html
Solution #2
NetMasters sells their NM (prefix: Net Masters) components without source-code. Assuming you have the source-code, you can do a hack, such as: change the header from HTTP 1.0 to HTTP 1.1.
If you do not have the source-codes for NetMasters LLC Internet components, you are out of luck. That company is no longer in business.

Related

Delphi 2007 - Compile errors on updating Indy from 10.5.1.1 to 10.6.2.0

I recently updated the stock Indy that installs with Delphi 2007 (I think it is 10.5.1.1) with 10.6.2.0, which I downloaded from GitHub.
I'm now getting a compile error:
EAttachmentFileNotFound.IfFalse (FileExists (parActualAttachmentFileID), 'File ' + parActualAttachmentFileID + ' not found.') ;
Error: E2003 Undeclared identifier: 'IfFalse'
The fragment is from my own code but I'm pretty sure that bit came from something I found probably on S/Overflow.
I received a couple of other errors also:
SMTPClient.AuthType := atDefault ;
Error: E2003 Undeclared identifier: 'atDefault'
and
SMTPClient.OnWork := EmailThread.EmailOnWork ;
Error: E2010 Incompatible types: 'Int64' and 'Integer'
but the first is a member that was renamed, and the second a data type that was changed. While these were a simple enough workaround, I'm left wondering
whether there was ever a "breaking changes" document generated.
maybe I accidentally somehow got the wrong source set.
EAttachmentFileNotFound is not a standard Indy exception, so it must be coming from your own code, or another 3rd party library.
Delphi 2007 was released almost 16 years ago. A lot has changed in Indy during that time. In fact, I think the changes you mention were actually made prior to, or maybe around, the release of Delphi 2007 (as they already existed in Indy's code in early 2008).
For instance:
in EIdException, the If(True|False) methods were removed (I don't know when exactly that change happened). In which case, you will have to use your own if and raise expressions now, eg:
if not FileExists(parActualAttachmentFileID) then
raise EAttachmentFileNotFound.Create('File ' + parActualAttachmentFileID + ' not found.');
in TIdComponent, the AWorkCount/Max parameters of the OnWork... events were changed from Integer to Int64 in 2006 (see OnWork Events changed to 64 bit on Indy's blog).
in TIdSMTP, the atDefault value was renamed to satDefault (again, I don't know exactly when this change was made).
So, you need to update your code accordingly.
I'm left wondering whether there was ever a "breaking changes" document generated.
No such document was ever created, no. However, changes that affect user code are typically announced on Indy's blog, under the Changelog category.

Invalid Pointer and Access Violation with Native Excel 3 for Delphi

I'm using Delphi 10.2 and the Native Excel 3 library to create spreadsheets.
I have the following code:
var
fWorkbook: IXLSWorkbook;
fSheet1: IXLSWorksheet;
begin
fWorkbook:=TXLSWorkbook.Create;
fSheet1:=fWorkBook.Sheets.Add;
fSheet1.Range['A1','A1'].ColumnWidth:=20;
fSheet1.Range['B1','B1'].ColumnWidth:=20;
fSheet1.Range['C1','C1'].ColumnWidth:=32;
fSheet1.Range['D1','D1'].ColumnWidth:=32;
fSheet1.Range['E1','E1'].ColumnWidth:=14;
fSheet1.Range['F1','F1'].ColumnWidth:=14;
fSheet1.Range['G1','G1'].ColumnWidth:=14;
fSheet1.Range['H1','H1'].ColumnWidth:=14;
fSheet1.Range['I1','I1'].ColumnWidth:=14;
fSheet1.Cells[1,1].Value:='Entry Type';
fSheet1.Cells[1,2].Value:='Intacct Acct #';
fSheet1.Cells[1,3].Value:='Intacct Acct # Description';
fSheet1.Cells[1,4].Value:='Store Name';
fSheet1.Cells[1,5].Value:='Department #';
fSheet1.Cells[1,6].Value:='Location ID';
fSheet1.Cells[1,7].Value:='Project ID';
fSheet1.Cells[1,8].Value:='Grant ID';
fSheet1.Cells[1,9].Value:='Net Amount';
intRow:=fWorkBook.SaveAs(Outfile);
'there is additional code after this.
end;
This code works every time on my development system. I've also used nExcel in other projects without a problem.
However, at the client's system, the fWorkbook.SaveAs generates an "Invalid Pointer" error or Access Violation. Since I cannot duplicate it, debugging is tough.
I have tried moving the SaveAs to various places (after the initial create, after the setting of column widths and where it is now).
Anyone seen this and/or have an explanation?
Thanks!
Malcolm
This problem was resolved by saving the workbook as an xlsx.

Getting Delphi to read a database with a new version of Microsoft Access

We use a Delphi 10 programme that reads in an Access database. I do not deeply understand how it does it, except that I believe it uses units called DAO.pas and DAO_TLB.pas.
I recently upgraded from Office 2007 to Office 2016, and since then the Delphi programme is unable to read from the database; it gives the error:
Project MyProj.exe raised exception class EOleSysError with message 'Class not registered'.
I have tried to search to find how to fix this but am struggling because I don't really understand what's going on under the hood. I tried to install the Access 2016 type library, but that didn't seem to make any difference.
Extremely grateful for any help.
Thanks,
Tom
EDIT: DAO.pas is here. DAO_TLB.pas is where the error is triggered; the function which errors is:
class function CoDBEngine.Create: _DBEngine;
begin
Result := CreateComObject(CLASS_DBEngine) as _DBEngine;
end;
Where CLASS_DBEngine is a constant declared as:
CLASS_DBEngine: TGUID = '{CD7791B9-43FD-42C5-AE42-8DD2811F0419}';
I have also just noticed that, when the error occurs, if I click continue rather than break, a new error appears, saying:
Class not registered, ClassID: {CD7791B9-43FD-42C5-AE42-8DD2811F0419}
i.e. the ClassID is the CLASS_DBEngine constant.

How to handle exception like download failed or invalid URL link or internet failure using TDownLoadURL?

I have an VCL app containing an object TDownloadUrl (VCL.ExtActns) used to download applications, my question is how to handle any kind of exception that restrict to download [for example:- like download failed or invalid URL link or internet failure or url not reachable or internet not available] using TDownLoadURL?.
Thanks in advance
TDownloadURL only defines 2 error messages, which are both declared in the Vcl.Consts unit:
SUrlMonDllMissing, which is raised when the Win32 URLDownloadToFile() function cannot be accessed at runtime.
SErrorDownloadingURL, which is raised when URLDownloadToFile() fails for any reason. Unfortunately, there is no way to differentiate why URLDownloadToFile() fails (although the OnProgress event may provide information about what it was doing just before the failure occurred).
The error messages are resource strings and thus can be localized, so they could potentially be in any language, not just English. And they are raised using the general SysUtils.Exception class itself, not any derived types. However, you can use them for substring matching, at least:
uses
..., Vcl.ExtActns, Vcl.Consts, System.StrUtils;
try
DownloadURL1.Filename := ...;
DownloadURL1.URL := ...;
DownloadURL1.Execute;
except
on E: Exception do
begin
if StartsText(SUrlMonDllMissing, E.Message) then
...
else if StartsText(SErrorDownloadingURL, E.Message) then
...
else
...
end;
end;
If you need more detailed error information, you might try calling URLDownloadToFile() directly, as it returns an HRESULT value. However,
be careful by the following gotcha in the documentation:
URLDownloadToFile returns S_OK even if the file cannot be created and the download is canceled. If the szFileName parameter contains a file path, ensure that the destination directory exists before calling URLDownloadToFile. For best control over the download and its progress, an IBindStatusCallback interface is recommended.
If that does not solve your issue, then you should use a different HTTP client API/library to perform the download, such as the HTTP client in Indy, ICS, Synapse, WinInet/WinHTTP, libCURL, etc.
I've not used this component, but it likely generates different exception types based on the errors it encounters. If that's the case then the article here covers handling multiple exception types:
Delphi Exception handling problem with multiple Exception handling blocks

Fast Report fr3 File loading Error in Delphi

I have question about loading *.fr3 in DelphiXE5,
I designed a report and pointed some text to Memo inside of Fast Report everything was ok until I want to load fast Report file from out site App it works for my PC perfectly but when I install client side it gets Error like this Photo include in this message
And the code I used is:
begin
frxReport1.LoadFromFile(ExtractFilePath(Application.ExeName)+'R1.fr3');
frxReport1.PrepareReport();
frxReport1.ShowReport();
end;
Error message:
'18/89765' is not a valid floatin point value
'238/11039' is not a valid floatin point value
'275/90569' is not a valid floatin point value
'41984/5614698264' is not a valid floatin point value
'41984/5618072454' is not a valid floatin point value
'94/48825' is not a valid floatin point value
I found the problem, the problem was Microsoft windows 8.1
I'm using Microsoft Windows 8.1, Delphi Xe 5 and Fast-report 4.15.6
First I made a report in fast report without any change and then run my app in windows 7 save as Fast-report to file and then use in all version of Microsoft Windows, thanks a lot
The problem has been originated form Regional Settings.
Win 8.1 automatically changes decimal separator as '.' to '/' in Persian language, even in fast reports.
The Microsoft has to figure this problem out.
step 1: open frxutils.pas from fastreport lib
step 2: function frxStrToFloat(s: String): Extended;
step 3: relapse this code: [',', '.']) with [',', '.','/']

Resources