Invalid Pointer and Access Violation with Native Excel 3 for Delphi - 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.

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.

How to get S.M.A.R.T. info from disks?

I tried code found in Google but nothing works and in most cases it doesn't even compile (missing units, undeclared data types etc).
I finally found something that looks complete but shows "The handle is invalid" error:
http://rsdn.org/article/delphi/SMART.xml
You can download the file from here:
http://rsdn.org/article/delphi/smart/smart.zip
The problem is with function function OpenSMART(DrvNum:Byte): THandle;
hSMARTIOCTL:=CreateFile(PChar('\\.\PhysicalDrive'+inttostr(DrvNum)),GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ or FILE_SHARE_WRITE,nil,OPEN_EXISTING,0,0);
result:= hSMARTIOCTL;
How can I fix it or where can I find working example?
I use Delphi 7 Pro and Delphi 10.3.
OK, it needs to be run as admin. Then it just works.

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.

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 [',', '.','/']

Validate user against aspnet_Membership from Delphi

I am trying to validate a user against table aspnet_Membership that is created by asp.net MVC 5 entity framework . As most of you know it has hash password.
I think I found a link for C#
ASP.NET Identity default Password Hasher, how does it work and is it secure?
Any idea how to validate from Delphi? Thanks.
Finally I was able to get this done with help from my colleague and this link courtesy Malcolm Swaine at
http://www.codeproject.com/Articles/32600/Manually-validating-an-ASP-NET-user-account-with-a
Here is the final code that should do the trick.
uses DECHash,Data.Cloud.CloudAPI;
...
..
function GetHash_ASPNetMemberShip(const Password, Salt:string):string;
var
bPassword ,bSalt ,bSaltPassword: TBytes;
begin
bPassword:= TEncoding.Unicode.GetBytes(Password) ;
bSalt:= DecodeBytes64(Salt);
SetLength(bSaltPassword, length(bPassword)+length(bSalt));
Move(bSalt[0],bSaltPassword[0],length(bSalt));
Move(bPassword[0],bSaltPassword[length(bSalt)],length(bPassword));
Result := THash_SHA1.CalcBuffer(bSaltPassword[0], Length(bSaltPassword), TFormat_MIME64);
end;
I use Delphi XE8. Trying this example got error:
[dcc32 Fatal Error] Unit1.pas(7): F2613 Unit 'DECHash' not found.
Where I can find this unit? Google has't know nothing about it.

Resources