The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,860 other subscribers

Archive for the ‘Delphi XE6’ Category

Get the path to the most recent msbuild.exe from the registry.

Posted by jpluimers on 2015/10/06

Get the path to the most recent msbuild.exe from the registry:


@echo off
:: http://stackoverflow.com/questions/328017/path-to-msbuild
:: http://www.csharp411.com/where-to-find-msbuild-exe/
:: http://timrayburn.net/blog/visual-studio-2013-and-msbuild/
:: http://blogs.msdn.com/b/visualstudio/archive/2013/07/24/msbuild-is-now-part-of-visual-studio.aspx
setlocal
:vswhereModernTry
:: https://github.com/Microsoft/vswhere/wiki/Find-MSBuild
:: Normal output example of `vswhere -legacy -latest -property installationPath` has no trailing back-slash:
:: `C:\Program Files (x86)\Microsoft Visual Studio 14.0\`
for /f "usebackq tokens=*" %%i in (`vswhere -latest -products * -requires Microsoft.Component.MSBuild -property installationPath`) do (
set InstallDir=%%i
)
:: without ENABLEEXTENSIONS, %InstallDir% is only available outside the above loop.
for %%v in (15.0, 14.0) do (
if exist "%InstallDir%\MSBuild\%%v\Bin\MSBuild.exe" (
set msBuildExe="%InstallDir%\MSBuild\%%v\Bin\MSBuild.exe"
goto :finish
)
)
:manualTry
:: order of the versions is important: get the most recent one
for %%v in (14.0, 12.0, 4.0, 3.5, 2.0) do (
for /f "usebackq tokens=2* delims= " %%c in (`reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSBuild\ToolsVersions\%%v" /v MSBuildToolsPath`) do (
set msBuildExe="%%dMSBuild.exe"
goto :finish
)
)
:vswhereLegacyTry
:: -legacy is not compatible with -products or -requires
:: note there is no Visual Studio 13.0 (just like there is no Office 13.0) likely because USA superstition.
:: https://en.wikipedia.org/wiki/Microsoft_Visual_Studio#History
:: msbuild was introduced in Visual Studio 8.0: https://en.wikipedia.org/wiki/MSBuild#History
:: Legacy output example of `vswhere -legacy -latest -property installationPath` has trailing back-slash:
:: `C:\Program Files (x86)\Microsoft Visual Studio 14.0\`
for /f "usebackq tokens=*" %%i in (`vswhere -legacy -latest -property installationPath`) do (
set InstallDir=%%i
)
:: without ENABLEEXTENSIONS, %InstallDir% is only available outside the above loop.
for %%v in (14.0, 12.0, 11.0, 10.0, 9.0, 8.0) do (
if exist "%InstallDir%MSBuild\%%v\Bin\MSBuild.exe" (
set msBuildExe="%InstallDir%MSBuild\%%v\Bin\MSBuild.exe"
goto :finish
)
)
:: nothing found
:finish
endlocal & if not [%msBuildExe%]==[] if exist %msBuildExe% ( echo %msBuildExe% )


for /f "usebackq tokens=*" %%c in (`"%~dp0get-msbuildExe-path.bat"`) do (
call %%c %*
)

view raw

run-msbuild.bat

hosted with ❤ by GitHub

With help from:

Note

This needs adoption for Visual Studio 2017 (15.0) and up; see the comments at the above gist:

lextm commented on Mar 9, 2017  

Note that 15.0 (in VS2017) no longer registers itself at this registry key location, so this trick won’t simply work. vswhere is now recommended to locate MSBuild 15,

https://github.com/Microsoft/vswhere

n9 commented on May 17, 2017

Be sure to call vswhere -products * to get standalone installation of BuildTools. (See Microsoft/vswhere#61.)

–jeroen

Posted in .NET, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, C#, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Delphi, Delphi 10 Seattle, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | Leave a Comment »

Unless you write an installer with the right manifest, don’t include Installer, Update, Upgrade, Setup, … in your EXE name

Posted by jpluimers on 2015/09/28

I’ve seen this question coming up a few times, and bumped into this at a client recently: the UAC dialog coming up when debugging a 32-bit executable.

This is caused (more details below) by Installer Detection Technology introduced in Windows Vista (with UAC) and tightened in more modern Windows versions.

The solution is to either:

  • not include Installer, Patch, Update, Upgrade, Setup, … in your EXE name
  • provide a correct manifest to your EXE (getting this right can be hard)
  • don’t use x86 as platform target

For software you don’t have source code for, you can alter the manifest with a requestedExecutionLevel elementFixing the way Vista Auto-detects Installers – Ben’s Writing.

A few links on Installer Detection Technology in Windows:

Read the rest of this entry »

Posted in .NET, .NET 1.x, .NET 2.0, .NET 3.0, .NET 3.5, .NET 4.0, .NET 4.5, .NET CF, C#, C# 1.0, C# 2.0, C# 3.0, C# 4.0, C# 5.0, C# 6 (Roslyn), Delphi, Delphi 10 Seattle, Delphi 2, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, RemObjects C#, Software Development | 1 Comment »

Do publish your .dproj/.groupproj in your version control systems (via: DelphiTools)

Posted by jpluimers on 2015/09/22

But I partially agree with the statement that Eric Grange made at DelphiTools as part of his post via Don’t publish your .dproj/.groupproj a few years ago:

Ad interim, .dproj are just a kludge by design

I completely disagree with hist blog post title: in my opinion “Do publish your .dproj/.groupproj in version control systems”

The discussion that followed in the comments was quite interesting: to bad I missed it back then.

Both .dproj and .groupproj are indeed a bit of a kludge. The main reason is that there is little documentation about them on the Embarcadero sites: most of it are threads on the forums.

msbuild

If you remember that basically they are just msbuild XML files, which is part of the .NET 2.0 framework and higher, and both extensively documented and extendable, then it gets much easier. Read the rest of this entry »

Posted in Delphi, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | 8 Comments »

Delphi 2010: Compiler understands $(platform) but not $(config), but debugger understands neither.

Posted by jpluimers on 2015/09/17

If, like Delphi XE and higher, your organise your projects to use output directories like ...Bin\Delphi####\$(Platform)\$(Config), and back-port to Delphi 2010, then

  • The Delphi 2010 compiler puts the files in almost the right directory ...\Bin\Delphi2010\Debug\Spring.Tests.exe
  • The Delphi 2010 debugger barfs with this message:
---------------------------
Error
---------------------------
Could not find program, '...\Bin\Delphi2010\%Platform%\%Config%\Spring.Tests.exe'.
---------------------------
OK   
---------------------------

So you might think that it is enough to hard code this in your base configuration:

  • Platform=Win32

Well no, the debugger still shows the above error message. Despite the compiler putting it in the correct directory: ...\Bin\Delphi2010\Win32\Debug\Spring.Tests.exe

So there are 3 configurations for the output directory:

  • Base (for documentation purposes only)
    • Bin\Delphi2010\$(platform)\$(config)
  • Debug
    • Bin\Delphi2010\Win32\Debug
  • Release
    • Bin\Delphi2010\Win32\Release

You might think: why is Spring4D still supporting Delphi 2010?

Two simple reasons:

  • many people still use it
  • it produces relatively small executables, which still is important in some situations like producing our own Build tool and keeping binary versions of that in our version control system

–jeroen

Posted in Delphi, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | 1 Comment »

Delphi installs: cleaning up space from %ProgramData%

Posted by jpluimers on 2015/09/16

A while ago I asked this on G+:

I’ve a VM with many Delphi versions and want to clean up space from %ProgramData% to install more. I think somewhere in the comments it was mentioned what to delete from %ProgramData% to lessen the disk space used by Delphi installations. […]

The VM is on an SSD, and the GUID directories there total to about 50 gigabytes.So any reminder what I can delete there would be much appreciated (:

Besides saving disk space, another advantage is that you get far less duplicates when indexing your filesystem with Everything: the directories contain copies of all files also present in the final installation (like %ProgramFiles%, etc).

Thanks to Ilya S, below are my notes for cleaning up a machine that has Delphi 2007 and Delphi 2010-XE6 installed.

In these folders, backup delete all subdirectories but the directory OFFLINE. Don’t delete files. Keep the backups in case you need them.

Read the rest of this entry »

Posted in Delphi, Delphi 2007, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Development, Software Development | 3 Comments »

Workaround for Delphi 2010 compiler error “E2076 This form of method call only allowed for class methods” when it infers a generic parameter type.

Posted by jpluimers on 2015/09/10

Generic support in Delphi took a very long time to get stabilised. Which means that compilers older than Delphi XE2 are hardly usable for code using generics. XE did get better, but Delphi 2010 and especially Delphi 2009 were hopeless.

A while ago, I bumped into another subtle error “E2076 This form of method call only allowed for class methods” when back-porting to Delphi 2010 the code like below calling the Spring4D unit Spring.SystemUtils which has a TEnum class that includes this TEnum.GetName<T> method:

    class function GetName<T>(const value: T): string; overload; static;

In Delphi XE and up, you do not have to specify the generic parameter T: the compiler automatically infers it.

In Delphi 2010, you have to, otherwise you will get the (totally unrelated!) error “E2076 This form of method call only allowed for class methods“.

Example code:


uses
Spring.SystemUtils;
procedure Test;
var
RuntimeError: TRuntimeError;
Name: string;
begin
RuntimeError := reNone;
// in the Spring.SystemUtils unit:
// class function TEnum.GetName<T>(const value: T): string;
// Workaround in Delphi 2010 (also works in Delphi XE+, but these do not require the Generic type to be specified).
Name := TEnum.GetName<TRuntimeError>(RuntimeError);
// Delphi 2010 does infer the type of the generic parameter, but then barfs with error E2076.
// Delphi XE+ infers the parameter type and do not generate an error: no need to explicitly specify the generic type:
Name := TEnum.GetName(RuntimeError); // Delphi 2010: [DCC Error] : E2076 This form of method call only allowed for class methods
end;

–jeroen

Posted in Delphi, Delphi 10 Seattle, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | Leave a Comment »

Delphi: rolling your own code or (dis)trusting the libraries that ship with Delphi?

Posted by jpluimers on 2015/09/09

Over the two decades I’ve come across a lot of Delphi projects.

All of them have one thing in common: even for functionality available in the Delphi libraries, much of that code was self-written.

You even see this in big libraries that have shipped with Delphi bit not originate from the Delphi team. Take Indy: lots of “roll your own” in it.

I’ve made some thoughts about that, and see these main causes with the points below.

What’s your thought on this?

Read the rest of this entry »

Posted in Conference Topics, Conferences, Delphi, Delphi 10 Seattle, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Event, QC, Software Development | 1 Comment »

Rudy’s Delphi Corner – Pitfalls of converting, on converting from C/C++ to Delphi

Posted by jpluimers on 2015/09/02

If ever in need to translate C/C++ headers or code to Delphi, this refernece by Rudy Velthuis – a dentist with a strong interest in programming – is the best I could find: Rudy’s Delphi Corner – Pitfalls of converting.

It is written in a pretty version agnostic way, and covers the vast majority of conversion topics.

And it has been updated over time numerous times.

–jeroen

Posted in Borland C++, C, C++, C++ Builder, Delphi, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 7, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | 10 Comments »

Android NDK Beginner’s Guide – Free Learning | PACKT Books

Posted by jpluimers on 2015/08/31

For Delphi and Android developers that want a deeper insight in the NDAK: only free today

https://www.packtpub.com/packt/offers/free-learning

Android NDK Beginner’s Guide

Get deep insight into the Android Native Development Kit for building complex apps. Using this practical step-by-step tutorial, highlighted with comments and tricks, discover how to run C/C++ code embedded in a Java application or in a standalone application. You will create a real native application starting from project creation through to full implementation of native API and the porting of existing third-party libraries. Grab this eBook whilst it’s free today!

–jeroen

Posted in Delphi, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Delphi XE8, Development, Software Development | 2 Comments »

GoF Patterns in Delphi | Implementations of the famous Gang of Four Design Patterns in Delphi language – via Nick Hodges

Posted by jpluimers on 2015/08/20

Thanks to Nick Hodges for having Delphi-losophy | Flotsam and Jetsam #88 point me to GoF Patterns in Delphi | Implementations of the famous Gang of Four Design Patterns in Delphi language.

–jeroen

Posted in Delphi, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Delphi XE7, Development, Software Development | 2 Comments »