1

In a legacy Delphi-7 application, a TExcelApplication is used to export data to Excel. Porting this to Rio, Delphi sends mixed signals as to the availability of this component.

When the component is put on a form, the IDE reports TExcelComponent “cannot be found” and the pascal code opens, but the form view (F12) is unavailable. The project DOES compile however, and accessing the component (to open Excel files etc) works runtime.

When I remove the component from the form and create it dynamically in FormCreate, the code DOES compile, but runtime the code generates an error: “TExcelApplication cannot be found”

“Uses Excel2000” is in the code.

Some googling pointed me in the direction of needing to install a Office package in Delphi (see screenshot). Indeed the “MS-Office2000…” checkmark was off so I turned it on and saved it; however this didn’t help. Clicking “Components” here does indeed display the TExcelApplication component. However checking this box (and including exiting Delphi, and building the project) doesn’t help (same problem).

https://gyazo.com/960eb8b53b891a5cc320e6866513c41a

The bpl file in the embarcadero subdir of program files doesn’t exist on my system (and no I didn’t remove it from there or anything; I never been there before and lots of other bpl’s ARE there).

So I’m a bit at my whit’s end here… how do I get something simple like exporting stuff to Excel working again?

Thanks in advance, Jur.

Dalija Prasnikar
  • 27,212
  • 44
  • 82
  • 159
Jur
  • 520
  • 2
  • 18
  • Fwiw, I can open a D7 TExcelApplication project in Delphi 10.2 without any problem, as long as I have the 'Microsoft Office 2000 Sample Automation Server Wrapper Components' package checked. So it seems likely your problem is related to the DFM or your Delphi set-up. Have you tried creating a new package, adding Word2000 to it and installing that? – MartynA Jul 15 '20 at 10:59

1 Answers1

1

work in progress

  1. ExcelXP, Excel2000, Excel97 - those units are just brushed-up polished in-house versions of standard ActiveX import. You can use them, or you can always do you own import using standard Components / Import Active X menu.

Dynamic linking like shown in MArtynA's answer can work too, but it will strip you from benefit of compile-time syntax checking.

var Excel: Variant; // or OleVariant
...
   Excel := CreateOleObject('Excel.Application');

If you mistyped some identifier, or used a property/method not yet or no more supported in your Excel version - you would only know it when your Application will try to use it, compilation would not alert you.

  1. The runtime the code generates an error: “TExcelApplication cannot be found” means you broken DFM streaming. In particular, ReadComponent function parsing DFM resource of your application finds it need to load a class named 'TExcelApplication' - but there is no such class in the dictionary. Use RegisterClass(TExcelApplication); in the unit initialization section. Or move the object declaration back to published section of your form's class - then Delphi RTL would transparently do this call for you.

  2. "the IDE reports TExcelComponent “cannot be found”" and " install a Office package in Delphi" - indeed, see Error opening a dfm file - Class xxxx not found

"The bpl file in the embarcadero subdir of program files doesn’t exist on my system" - would it be so, you would not be able to tick the checkbox, because that exactly tries to load the design-time BPL into your IDE. And that would give you a very different error, about inability of loafing your BPL.

Personally i never install Delphi into Program Files, both because some old code might fail with long and space-containing paths, and because i prefer to have options of tinkering with development tools without hassle of UAC (User Access Control of Windows Vista+), including its virtual shadowing filesystem (%LocalAppData%\VirtualStore).

In my XE2 installation the source .pas files lie in c:\RAD Studio\9.0\OCX and c:\RAD Studio\9.0\bin has THREE dcl*office*.bpl - for Office 2000, XP and 2010.

Are you sure you have neither? Search all you disk for files like that then. Still not found - run Delphi installation, "Modify" and make sure you made Office sample automation components actually installed. Try to use OfficeXP or Office2010 packages - they should be backward-compatible with Office 2000, due to Microsoft COM guidelines.

If still not found you might do Components / Import Component / Import ActiveX for Excel.

  1. Also, i wonder seeing RxLib in your list. Officially RxLib ended with Delphi 5 and never supported Delphi6+, instead donating to JediVCL project. The unofficial patches existed (by Polaris Software for example), but i wonder if they invested a lot of support into Unicode versions of Delphi. Even J.E.D.I. lacks manpower badly today.

  2. Also, thing again if you need a full-fledged Excel interoperation. It gives you VBA-level access to Excel's internal object tree. But it burdens your users with need to purchase and install Excel, and it also is rather slow. If you only use limited subset of the Excel Workbook features generating XLSX files in your program might be both faster and leaner. At least this is the way we switched to in our app. Now users you can export spreadsheets no matter if Excel or some other office or none at all is installed, and do it much faster.

Arioch 'The
  • 15,799
  • 35
  • 62
  • RegisterClass in initialization doesn't compile: [code][dcc32 Error] uMatchFactDM.pas(6210): E2010 Incompatible types: 'tagWNDCLASSW' and 'class of TExcelApplication'[/code] RxLib is extensively used in the code, TRxMemoryData in particular. I found a version that works now, not sure where, it was a few weeks ago; but those memory tables work fine now. I'm hesitant to convert them to FD memtables, they're constantly being sorted ("SortOnFields" method) and I'd have to replace all that code with indices. If it isn't broken, don't fix it? – Jur Jul 15 '20 at 09:45
  • @jur - change ordering of USES clause, or use qualified call `unitname.functionname`. You try to call `RegisterClass` from `Windows` and you need one from `SysUtils` or `classes` or something, check Delphi help which specific unit it's in - make it last. Also that still is bad route, don't go there. You make `TExcelApplication` options stored into DFM sources, but not seeing in GUI Form Designed, that means they can always be unexpectedly modified or deleted. Don't go there. OR clean-up the DFM file. Open DFM file in notepad, or in Delphi form Designer Alt+F12 or right-click and "view as text" – Arioch 'The Jul 15 '20 at 09:50
  • @Jur TJvMemoryDataset is particularly buggy and slow (as all the onion layers of `TDataSet` makes it) thing, i particularly had troubles with datasets having 0 or 1 rows, attempting reading from it was very inconsistent. If you do not have complex searches (sorting by different columns for different usecases) and all your app needs is key/value storage - consider getting rid of it. Personally i rewritten one class to use `TDictionary` instead and it became much faster and more reliable. If you do you may instead try in-memory SQL (NexusDB, SQLite, etc) – Arioch 'The Jul 15 '20 at 09:59
  • 5. Yes I do; in fact, users make edits in Excel, then return to my app and click buttons for further processing (and please don't ask me why exactly; I didn't write this stuff))) – Jur Jul 15 '20 at 10:00
  • @Jur Then re-install Delphi and make sure you install Office components too. We have legacy Clarion app working that way, but it uses DDE to send commands back from Excel, not COM :-) – Arioch 'The Jul 15 '20 at 10:01
  • when cleaning up the dfm, what exactly am I cleaning up, I mean, what components/properties I need to get rid of? – Jur Jul 15 '20 at 10:02
  • you removed TExcelApplication from the from sources - remove it from DFM. But you still better fix the IDE loading problem instead (the minimal changes principle you touted above). Actually, tools like GExperts and CnWizards have component-to-code button. You can load the form in Delphi 7, click it, and have non-visual code, creating the object and setting all the properties that were non-default in DFM. – Arioch 'The Jul 15 '20 at 10:04
  • lol, well the whole reason this project was started at all was because some old PC (2005?) where Delphi-7 was installed, finally passed to computer netherworld... wouldn't know where to find an old Delphi-7 now))) And yes, I already removed the ExcelApp component from the dfm (before coming here at all) – Jur Jul 15 '20 at 10:07
  • `I found a version that works now` basically you say you pulled some random garbage in that you can not verify and make sense of, and it does not even have some developers you can ask questions. Any open-source is YOUR OWN code by definition. So migrating to half-dead JediVCL would probably still be better than using some snapshot of unknown origin with unknown quality. You can not diagnose even Delphi failing to load components, how would you diagnose bugs with this unknown RxLib derivative? Especially some techie bugs with Unicode strings or Win64? Here be dragons, you pave a road to hell... – Arioch 'The Jul 15 '20 at 10:08
  • 1. Also you may try FPC/Lazarus, maybe PilotLogic's distro (CodeTyphoon or something). It might seem not not worse than Delphi 7 and it IS supported living project. Granted, there is nothing like BPL in FPC, but if you don't use them - who cares. // 2. After you purchase Delphi you should have a 6 months grace period you can demand license codes for ANY prior Delphi edition from Delphi 7 to the one you purchased. At least that was so with XE2 and XE4. Check it out before time window elapsed! Grab your D7 copy. // 3. Can u turn that "old PC" into virtual machine? we did, sysinternals disk2vhd – Arioch 'The Jul 15 '20 at 10:11
  • Point taken. yet this is an emergency conversion with limited resources, and it simply needs to be up and running again asap. So yes, it would be better to take the long route and do it properly (and I MIGHT be allowed to do that later on), but for now I'm only doing what is ABSOLUTELY necessary to get it back up... and those memtables DO seem to work now. – Jur Jul 15 '20 at 10:12
  • If emergency - and you purchased last Delphi version, try to get ALL activation codes and installation packages for ALL prior versions. 99% you would never need them, but there still is 1%. – Arioch 'The Jul 15 '20 at 10:14
  • "passed to computer netherworld" - what specifically would you mean here, is there totally no chance you can make old HDD run at least once for disk2vhd session? Also, VirtualBox can run VHD drives but not VHDX – Arioch 'The Jul 15 '20 at 10:15
  • "Any open-source is YOUR OWN code by definition." It most certainly is not! What about author's right of acknowlegement, etc. – MartynA Jul 15 '20 at 10:15
  • @MartynA i was talking about technical side and responsibilities programmer has before his company and his program users. As for author's rights, nominally they are there, but practically there are so many of them that mentioning them all is not practical. See 2/3-clause BSD and see XFree86 vs X.org :-) – Arioch 'The Jul 15 '20 at 10:17
  • With respect, the word you used is "own" and had no qualification as to origin. I suggest you get your facts right ... – MartynA Jul 15 '20 at 10:22
  • disk2vhd session - as you probably already understood, I'm not technical enough to understand you. Yes, the HDD is alive, but not bootable anymore. I took it so several hardware guys to find a way to virtualize it and make it bootable again so Deplhi-7 could run, but they told me either it was impossible, or that the process was so complicated that I failed to understand even the terminology they used... and given the time pressure (and general value of having it in a currrent Delphi version anyway), this road seemed easier. – Jur Jul 15 '20 at 10:23
  • @MartynA i can not edit old comment, and even formally Jur is now co-author of the RxLibrary derivative he installed in his Delphi (and changed few bytes here and there along the installation). So, yes, he has the same rights and responsibilities towards that derivative as all other unknown authors. But he is known and he has responsibilities before users and bosses, that other unknown co-authors do not. Basically, he just made a fork and he is as now its sole author/maintainer of that fork. He owns it. – Arioch 'The Jul 15 '20 at 10:25
  • see the last example http://www.dict.org/bin/Dict?Form=Dict2&Database=gcide&Query=own - *To grant; to acknowledge; to admit to be true; to confess; to recognize in a particular character; as, **we own** that we have forfeited your love.* - Jur definitely owns the fork of RxLib he just created and ALL the bugs, intentional or unintentional, it contains. – Arioch 'The Jul 15 '20 at 10:27
  • @Jur `not bootable` means more of software problem with Windows, etc. So it seems that was not "computer went to heaven but "Windows went to heaven" and you do not have the saved copy of that Windows. Anyway, if you have emergency and lack experience you better change as little as possible. That means, using Delphi 7 and exactly the same set of components and sources! So, install Delphi 7 - co-purchased with you Delphi Rio, or one salvaged from the old HDD, and work in D7there. The last route would probably require you to illegally activate D7 on new hardware. Best is fixing old Windows boot – Arioch 'The Jul 15 '20 at 10:32
  • Personally, is would 1) use Disk2VHD to make etalon never-changing copy of you old HDD as the last "known good" reference snapshot of data. Save MD5 / SHA256 hashes of it to detect any potential change. And make several copies of it into different media (new HDD, DVD-R of good producer, but not SSD/flash) and kept in different houses. I would prefer old "dumb" VHD format instead of VHDX, because more non-Microsoft software know it. 2) make copies of the VHD files and work with copies to make old Windows boot in Hyper-V or VirtualBox or any other virtual machine player. – Arioch 'The Jul 15 '20 at 10:40
  • What Windows was there actually ? if 2000/XP then chances are mere finding the same Windows distro and installing it over old disk in "i pretend i am upgrading Windows" mode can fix it. BUT you only do experiments on expendable copies, not on the FIXED etalon you make to keep not to work on. "The data you only have once is the data you do not really have". – Arioch 'The Jul 15 '20 at 10:42
  • Oh man, that's way over my head... I'm just a functional guy who got assigned to this because the devs are Visual Studio/MVC/C#/Javascript people who refused to do this and I'm the only one who once worked with Delphi... but THANKS A LOT to you both for trying to help me anyway!! – Jur Jul 15 '20 at 11:01
  • Native programmin is "close to bare metal" stuff, rejoice! you will grow into snapping hardware parts in and out of the box too :-) But, i gave you the paths to explore i feel are more efficient and safer. So, start them both now and learn along the way. I hope your new PC has place to clone old HDD into VHD format file (don't forget to make the file read-only and to keep md5/sha256 "signatures"), then your bosses should provide u with reliable and multi-place storages for that clone. And then install new Delphi 7 onto your new computer, while in parallel solving "Windows NNN don't boot" issue – Arioch 'The Jul 15 '20 at 11:08
  • heh yeah, I prolly will, unless I'm supposed to get back to my normal job of participating in discussions whether employee ID's are shown or not (3 hour meeting) or the color of an update button (green or blue, 2 hour meeting) – Jur Jul 15 '20 at 12:04