Archive for the ‘Delphi’ Category
Posted by jpluimers on 2014/07/24
Late binding sometimes is your friend:
Set objWord = CreateObject("Word.Application")
Wscript.Echo "Version: " & objWord.Version
Wscript.Echo "Build: " & objWord.Build
objWord.Quit
The accompanying Delphi code:
uses
System.Win.ComObj;
procedure TTestVersionAgnosticWordMainForm.GetWordApplicationInfoButtonClick(Sender: TObject);
var
WordApplication: OleVariant;
Version: OleVariant;
Build: OleVariant;
begin
WordApplication := CreateOleObject('Word.Application');
try
try
Version := WordApplication.Version;
Build := WordApplication.Build;
LogMemo.Lines.Add(Version);
LogMemo.Lines.Add(Build);
finally
WordApplication.Quit;
end;
finally
WordApplication := Unassigned; // release it
end;
end;
–jeroen
via: How Can I Determine Which Version of Word is Installed on a Computer? – Hey, Scripting Guy! Blog – Site Home – TechNet Blogs.
Posted in Delphi, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Development, Scripting, Software Development, VBScript | 10 Comments »
Posted by jpluimers on 2014/07/23
A while ago, some of the TODO comments in my source code disappeared from the TODO list.
I wondered why, so I found this question: How set up todo list categories in Delphi 2010?.
The Delphi TODO item syntax in source code comments is like this (thanks Nelson H C Nepomuceno):
{ TODO 1 -cImportant :Do this!}
// TODO 1 -cImportant: Do this!
My comment there, after I found out I had done a stupid global search replace involving colons:
The important thing is the colon somewhere after the TODO. If you do not have the colon, then the TODO list will not show the comment. Anything after the colon will be the action item in the TODO list.
–jeroen
via: How set up todo list categories in Delphi 2010 – Stack Overflow.
Posted in Delphi, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 7, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2014/07/22
Found out where the StackOverflow Pascal has its origins: What happened to comments in syntax highlighter? – Meta Stack Overflow.
Like any syntax highlighter, it is not perfect (only a Delphi compiler driven highlighter would have a chance to be perfect), but it does a pretty good job and gets better over time.
–jeroen
Posted in Borland Pascal, Delphi, Delphi 1, Delphi 2, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Development, FreePascal, Pascal, Software Development, Turbo Pascal | Leave a Comment »
Posted by jpluimers on 2014/07/19
Though fully justified text is most often in print, and not much in user interfaces any more, this might come in useful one day (it is based on the GDI functions TextOut and SetTextJustification):
David Millington Posted: Have you ever wanted to draw fully justified text ie, text that adheres to both the left and right sides of the destination rectangle? It’s more complicated than it seems, and there’s definitely no inbuilt support in the VCL. But here’s how to do it, including an open-source unit you can drop into your applications and use.
Drawing fully justified text to a canvas | Parnassus – Delphi Consulting & Plugins.
–jeroen
via:
Posted in Delphi, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 7, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Delphi XE5, Delphi XE6, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2014/07/17
I observe an increase of people not asking questions on Stack Overflow any more…
Today, two interesting questions caught my eye.
The first one was by Martijn Coppoolse about Is it possible to figure out whether a type’s property has a ‘stored’ flag or not, preferably without having to create an instance of that type? (note: emphasis is mine)
Then the most interesting one (note this is about old Turbo Pascal style object syntax that is still available in Delphi, yes polymorphism with the object keyword): Could you please remind me if Objects support polymorphism? by Roman Yankovsky.
–jeroen
PS: Martijn posted the solution he used:
So I tried looking at the StoredProc pointer, and I can differentiate between three states:
- nil, which means stored False;
- Pointer(1), which means that no stored flag was specified;
- an actual pointer, which means that a method was specified; and the pointer seems to point at the relevant method’s CodeAddress. However, we always use private methods for that, and those don’t seem to be enumerated by GetMethods.
Still, those three states are basically what I needed: don’t include an element when StoredProc = nil; when StoredProc = Pointer(1) make it compulsory, and make it optional otherwise when it’s a pointer.
Thanks a lot to all who helped! +Qing-Shan Xiao +Jeroen Wiert Pluimers +Asbjørn Heid
–jeroen
Posted in Delphi, Delphi 7, Development, Software Development | 3 Comments »
Posted by jpluimers on 2014/07/17
I’m not a real expert on LCID (the values like 1033 (aka 0x409 or $409) and 1043 (aka 0x413 or $413), but here are a few notes on stuff that I wrote a while ago to obtain shell32.dll resource strings for various LCIDs.
The most often used way to load resource strings is by calling the LoadString Windows API call which loads the string for the currently defined LCID.
To get them for a different LCID, there are two ways:
- Set the LCID for the current thread (don’t forget to notify the Delphi RTL you did this, and update FormatSettings)
- Write an alternative for LoadString that gets a string for a specific LCID (so you can keep the current thread in a different LCID)
The first method – altering the LCID of the current thread – is done using SetThreadLocale in Windows XP or earlier, and SetThreadUILanguage in Windows Vista/2008 and up (I’m not sure on the timeline of Windows Server versions, but I guess the split is between 2003 and 2008) as mentioned at SetThreadLocale and SetThreadUILanguage for Localization on Windows XP and Vista | words.
SetThreadLocale is deprecated, as Windows has started switching from LCID to Locale Names. This can cause odd behaviour in at least Delphi versions 2010, XE and XE2. See the answers at delphi – GetThreadLocale returns different value than GetUserDefaultLCID? for more information.
But even on XP it has the potential drawback of selecting language ID 0 (LANG_NEUTRAL) which selects the English language if it is available (as that is in the default search order). Both Writing Win32 Multilingual User Interface Applications and the answers to LoadString works only if I don’t have an English string table and Windows skipping language-specific resources and the Embarcadero Discussion Forums: How to load specific locale settingsd thread that describe this behaviour.
To work around that, you can do two things: store your resource strings in locale dependent DLLs, or (if you don’t write those DLLs yourself), write an alternative for LoadString.
I’ve done the latter for Delphi, so I could load strings for a specific LCID from the Shell32.dll.
For a full overview of all these strings, see http://www.angelfire.com/space/ceedee/shell32stringtables.txt
A few pieces of code.
You can get the full code at the BeSharp – Source Code Changeset 100520 (now at bitbucket too). Read the rest of this entry »
Posted in Delphi, Delphi XE2, Delphi XE3, Delphi XE4, Development, internatiolanization (i18n) and localization (l10), Software Development | 4 Comments »
Posted by jpluimers on 2014/07/16
I used to forget about the difference between Variant and OleVariant, and used them like this:
Use OleVariants for OLE, and Variants for non OLE.
There is no need to manually clear them.
Luckily I was right, as the differences are documented in the Delphi on-line help at OLE-compatible Variant type (the oldest I could find was the Delphi 2010 OleVariant documentation): Read the rest of this entry »
Posted in Delphi, 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, Development, Software Development | Leave a Comment »
Posted by jpluimers on 2014/07/03
Joseph G. Mitzen posted a very interesting (and elaborate <g>) comment on a post from me in 2009: Delphi – for … in on enumerated data types « The Wiert Corner – irregular stream of stuff.
The crux of his post is about consistency of your tools. And clearly, the Delphi team has some work to do in that regard especially when compared to the Python world where consistency is key (and takes a lot of time to introduce new features as a side effect).
He refers to the ADUG post For-in Enumeration | Australian Delphi User Group Members by DaddyHPriest that lists a number of areas where Delphi does not have enumerator support for.
Which reminds me I promised to publish some more enumeration demos showing what kind of code could be eliminated if things became more consistent.
Hopefully this summer gives me a bit more time for that (:
–jeroen
via: Delphi – for … in on enumerated data types « The Wiert Corner – irregular stream of stuff.
Posted in Delphi, Delphi 2007, Delphi 2009, Delphi 2010, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Development, Software Development | 4 Comments »
Posted by jpluimers on 2014/06/11
A bit more than a year ago, I wrote about Delphi: you should avoid the with statement as it makes your code less future proof. That caused some nice comments on the blog, and some more on LinkedIn where Paul Foster mentioned it in a thread ‘Jeroen Pluimers makes a case against “with” statements.‘ Both interesting reads, especially the reasons that people use or avoid with, or keep its use in balance. There is one set of comments I want to emphasize: refactoring multiple with statements into a one function and a call per former with. Read the rest of this entry »
Posted in Borland Pascal, Delphi, Delphi 1, Delphi 2, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi 8, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Development, Pascal, Software Development, Turbo Pascal, With statement | 19 Comments »
Posted by jpluimers on 2014/06/03
Talking about Danny Thorpe: he also posted a nice hint on threading methods for ancient Delphi versions that equally applies to DLL exports in any Delphi version, even any programming environment.
Recently, I had to do some surgery in such a Pre-Delphi 6 application, and I was really happy to remember this answer: it instantly solved some process crashes, and the added logging allowed for investigating the actual cause.
Note that this tip isn’t just a good advice for old Delphi versions.
Even in younger Delphi versions, you have to watch methods that can be called from outside a regular Delphi context, for instance exported methods.
Heck, it applies to virtually any development environment: exceptions usually are very specific to that environment and should never cross a process boundary.
Summary
Take the approach below
- for Execute methods in your own thread classes in Delphi 5 or earlier
- for any method that can be called externally (like DLL exports) Read the rest of this entry »
Posted in Delphi, Delphi 1, Delphi 2, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 3, Delphi 4, Delphi 5, Delphi 6, Delphi 7, Delphi 8, Delphi x64, Delphi XE, Delphi XE2, Delphi XE3, Delphi XE4, Development, Software Development | Leave a Comment »