Delphi XE2 cannot find ComObj.dcu where did it go? - delphi

I'm trying to install the jvcl from source, but I'm getting an error in
line #1267 of unit JvInterpreter;
uses
TypInfo,
{$IFDEF JvInterpreter_OLEAUTO}
OleConst, ActiveX, ComObj,
So I removed ComObj from the uses and waited for the error further down the line:
There's an error concerning EOLEError, which is part of OleAuto I added that and hoped for the best, but....
I get an error on this line #1799:
DispatchInvoke(IDispatch(Dispatch), CallDesc, PDispIDList(#DispIDs[0]), ParamTypes, Result);
So the question is: what happened to ComObj and what unit do I need for DispatchInvoke in XE2?

The solution is to change the uses to use a fully qualified name:
uses
TypInfo,
{$IFDEF JvInterpreter_OLEAUTO}
OleConst, ActiveX,
{$IFDEF VER230} system.win.ComObj, {$ELSE} ComObj, {$ENDIF}
Now it compiles without error.
See: What is the compiler version for Delphi 2010?
For a list of compiler defines.

Simply add system.win i.e. instead of comobj use system.win.comobj

Related

How to avoid insert namespace in Delphi uses

I manage a huge project in Delphi 2007. The target is to upgrade it to Delphi 10.1 Berlin this year. So in the meantime the source is compiled in both versions.
If there is a problem with the new Delphi we want the old version as backup.
My problem in unit dmActions.pas that is a unit inherited from TDataModule.
uses
// VCL
ActnList,
ActnMan,
Classes,
Controls,
Forms,
Graphics,
ImgList,
Menus,
SysUtils,
XPStyleActnCtrls,
Variants,
{$IFDEF BOLD_DELPHI16_OR_LATER}
System.ImageList,
System.Actions,
{$ENDIF}
BusinessClasses;
Delphi IDE don't understand my IFDEF so it automatically insert missing units to this
uses
// VCL
ActnList,
ActnMan,
Classes,
Controls,
Forms,
Graphics,
ImgList,
Menus,
SysUtils,
XPStyleActnCtrls,
Variants,
{$IFDEF BOLD_DELPHI16_OR_LATER}
System.ImageList,
System.Actions,
{$ENDIF}
BusinessClasses, System.ImageList, System.Actions;
But this don't compile in Berlin with this message
[dcc32 Error] dmActions.pas(36): E2004 Identifier redeclared: 'System.ImageList'
[dcc32 Error] dmActions.pas(36): E2004 Identifier redeclared: 'System.Actions'
And of course "System.ImageList, System.Actions" don't compile in D2007.
So what is my best action to solve this ?
You can make use of the Unit Aliases feature of Delphi here - at least as your Delphi 2007 supports dotted unit names in the first place. This allows to use the new unit names like System.SysUtils from Delphi 10.1 Berlin and still compile that project with Delphi 2007.
For this you have to add mappings to the Unit Aliases of the Delphi 2007 project like this:
System.SysUtils=SysUtils
System.Classes=Classes
For units that don't exist in Delphi 2007, like the ones you mention in your post, simply map to an existing unit:
System.Actions=ActnList
System.ImageList=ImgList
As a benefit you end up with uses clauses free of IFDEFs.
As https://stackoverflow.com/users/2916756/nolaspeaker said it works by test compiler version directly. I used an inc-file and that don't work well in this case
But in my case I check Berlin so:
{$IFDEF VER310}
System.ImageList,
System.Actions,
{$ENDIF}

Compiler directive is not set in Delphi 10.2

I have the following unit implementation in my delphi probject.
uses
{$IFDEF Ver270} JSON, {$ELSE} DBXJSON, {$ENDIF}
In Delphi XE4 DBXJSON will be implemented - that's fine.
In Delphi XE6 JSON will be implemented - that's fine too.
But in Delphi 10.2, DBXJSON will be implemented - not JSON. Why? Is this a bug in Delphi 10.2?
This is not a bug, it is by design. Each version has exactly one VERXXX definition. VER270 is defined in XE6 and XE6 only. For version 10.2 VER320 is defined.
In your scenario it is much simpler to use code like this:
uses
{$IF RTLVersion >= 27} JSON, {$ELSE} DBXJSON, {$IFEND}
Another option is to use a standard include file like jedi.inc. This takes the pain out of such conditional statements. If you use jedi.inc then you can code it like this:
uses
{$IFDEF DELPHIXE6_UP} JSON, {$ELSE} DBXJSON, {$ENDIF}

What is the Delphi 10 equivalent to DesignIntf?

Just updated the SynEdit RunTime module for Delphi 10.1 Berlin, but now I need to update the DesignTime Module... The Designer units from Delphi XE versions do not appear to be available in 10.1.
What is the recommended Design Editor and Interface module to replace the old Delphi Designers?
I was thinking there would be built-in XAML designers, since the new Delphi supports .NETCore.
Is there an alternate designer to use for FMX and cross-platform projects?
example found... requires FMX.Types unit and a header over the class
https://delphihaven.wordpress.com/2013/02/03/writing-a-simple-firemonkey-tlistlayout-implementation/
uses
System.SysUtils, System.Classes, FMX.Types;
type
[ComponentPlatforms(pidWin32 or pidWin64 or pidOSX32)]
TListLayout = class(TControl)
Here's how I changed my headers for XE, Delphi 10 and Firemonkey
(*
Directive Description
------------------------------------------------------------------------------
LINUX Defined when target platform is Linux // FOR KYLIX
// FOR WINDOWS VERSIONS USE VCL
WIN32 Defined when target platform is 32 bit Windows
WIN64 Defined when target platform is 64 bit Windows
CLR Defined when target platform is .NET
WINVCL // ADDING TO REPRESENT ALL VCL platforms
// FOR OTHER USE ELSE
// *)
{$IFDEF WIN32}
{$DEFINE WINVCL}
{$ELSE}
{$IFDEF WIN64}
{$DEFINE WINVCL}
{$ELSE}
{$IFDEF CLR}
{$DEFINE WINVCL}
{$ENDIF}
{$ENDIF}
{$ENDIF}
uses
{$IFDEF LINUX} // Kylix is target platform
QControls,
{$ELSE}
{$IFDEF WINVCL}
VCL.Controls,
{$ELSE} // ALL OTHER PLATFORMS USE FIREMONKEY CONTROLS
FMX.Controls,
FMX.Types,
{$ENDIF}
{$ENDIF}
System.Classes;
And the new controls start out like this now...
[ComponentPlatforms(pidWin32 or pidWin64 or pidAndroid or pidOSX32)]
TMyCustomComponent = class(TControl)
Nothing has changed. Your design-time package should require designide.dcp and the necessary runtime package. Designide contains what you need.
Use the Getit Package Manager
But this can be a lot simpler. I just did the following:
In the IDE, selected Getit Package Manager from the Tools menu.
Searched for Synedit
Found Synedit Turbo Pack and clicked Install
A dialog popped up. I clicked agreement and it went on installing Synedit (although with the old 230 version suffix - this ought to be changed to 240 for Berlin)
After that, I could continue editing what I was editing before this, and the latest Synedit was installed.
SyneditPropertyReg.pas still uses the same units, like DesignIntf, DesignEditors, etc.
Note that now, there are (at least) two packages: SyneditDD.dpk and SyneditDR.dpk. The latter is the runtime package, the former is the designtime package and that should require the runtime package as well as designide. I think the installer compiled a little more, but it went so fast, I couldn't see properly.

Stop Delphi automatically adding units incorrectly [duplicate]

This question already has answers here:
Delphi conditional compilation in uses clause
(4 answers)
Closed 7 years ago.
I am updating our projects from XE7 to XE8. For the time being they will still need to work with XE7, so a few conditionals are required. For example, ImageList has changed units, so Vcl.ImgList is Syste.ImageList in XE8. To make it work on both Delphi versions the uses clause looks something like this:
uses
System.SysUtils, System.Classes, Vcl.Controls
{$IF CompilerVersion >= 29.0}
,System.ImageList
{$else}
,Vcl.ImgList
{$endif}
,cxGraphics;
Sometimes this works fine. However, quite often Delphi automatically re-adds the System.Imagelist unit even though it is already there, albeit in a conditional e.g.
uses
System.SysUtils, System.Classes, Vcl.Controls
{$IF CompilerVersion >= 29.0}
,System.ImageList
{$else}
,Vcl.ImgList
{$endif}
,cxGraphics, System.ImageList;
When this is compiled, XE8 complains.
[dcc32 Error] dmImagesU.pas(13): E2004 Identifier redeclared: 'System.ImageList'
a) Why does Delphi add the unit? b) Anybody know a workaround?
The "parser" that is responsible for adding units to the uses in this case is not considering compiler directives properly (that issue already occured with the introduction of System.Actions.pas).
I usually create a dummy unit for older Delphi versions so I don't have to put any directives into the uses.
So in your case just create an empty System.ImageList.pas and put that somewhere <= XE7 finds it.

Why doesn't code from "The Tomes of Delphi" compile?

I'm trying to use the TDRecLst and TDSplyCm units from the code included with The Tomes of Delphi, but I get a compiler error in TDBasics.pas:
I get a similar error in TDStrRes.inc:
What's wrong, and how do I fix it?
The code is available from the author.
You're evidently using a Delphi version that's newer than Delphi 6. Despite being updated in 2005, the code from that book only detects up to that version of Delphi. TDDefine.inc defines a number of compiler symbols based on the version it detects, but when the version you're using isn't anything it recognizes, it defines no symbols. That eventually leads to problems later when the compiler encounters code like this in TDBasics.pas;
implementation
uses
{$IFDEF Delphi1}
WinTypes, WinProcs;
{$ENDIF}
{$IFDEF Delphi2Plus}
Windows;
{$ENDIF}
{$IFDEF Kylix1Plus}
Types, Libc;
{$ENDIF}
{$IFDEF Delphi1}
{$R TDStrRes.r16}
{$ENDIF}
{$IFDEF Delphi2Plus}
{$R TDStrRes.r32}
{$ENDIF}
{$IFDEF Kylix1Plus}
{$R TDStrRes.r32}
{$ENDIF}
const
UnitName = 'TDBasics';
Since none of Delphi1, Delphi2Plus, or Kylix1Plus is defined, the uses clause is empty. When we ignore all the compiler directives and inactive code blocks, the compiler ultimately sees code like this:
implementation
uses
const
UnitName = 'TDBasics';
That's why the compiler complains about expecting an identifier instead of const.
To fix it, you need to teach TDDefine.inc to recognize your version of Delphi. Easier, though, might be to ignore all the version-detection code and hard-code all the symbols that apply to the version you're using. As long as you never use any version older than Delphi 6, all the symbols will apply to all your versions.
Find the following block of code in TDDefine.pas:
{$IFDEF VER140}
{$DEFINE Delphi6}
{$DEFINE Delphi1Plus}
{$DEFINE Delphi2Plus}
{$DEFINE Delphi3Plus}
{$DEFINE Delphi4Plus}
{$DEFINE Delphi5Plus}
{$DEFINE Delphi6Plus}
{$DEFINE HasAssert}
{$ENDIF}
Remove the first and last lines so that the remaining $DEFINE instructions are processed unconditionally.

Resources