Категория: In English @en

Multiobject try..finally

Just a simple Delphi pattern. We all have encountered nested try..finally blocks like this:

CChar := TTextTableCursor.Create(TChar);
try
 CCharProp := TTextTableCursor.Create(TCharProp);
 try
   Builder := TCharPropBuilder.Create(Result);
   try
     //Do some work with all three objects
     //Since all three are needed, we can't destroy any before this point
   finally
     FreeAndNil(Builder);
   end;
 finally
   FreeAndNil(CCharProp);
 end;

finally

 FreeAndNil(CChar);

end;But there’s a nicer way of doing the same while still being exception safe (and avoiding the overhead of three try..finally exception frames):

CChar := nil;
CCharProp := nil;
Builder := nil;
try
 CChar := TTextTableCursor.Create(TChar);
 CCharProp := TTextTableCursor.Create(TCharProp);
 Builder := TCharPropBuilder.Create(Result);
//Do some work with all three objects

finally

 FreeAndNil(Builder);
 FreeAndNil(CCharProp);
 FreeAndNil(CChar);

end;

Installing Delphi VersionInsight Plus

Since Delphi XE, Delphi has SVN support integrated into file history display. SVN revisions are displayed in addition to local backups, all properly sorted by date. Very nice.

Mercurial and Git support wasn’t added into the default distribution, but there’s a newer version of VersionInsight plugin with fully functioning support for those, written by Delphi developers. Meet RAD Studio Version Insight Plus.

To use this you need to compile it. It’s simple, but mind these fine points:

  • There are several branches in the repo, you need the /plus one. Not the trunk.
  • Delphi less than XE will not compile those, no simple solution.
  • You need to compile five packages: svn, svnui, svnide (already grouped into DelphiSVN) + hgide and gitide.
  • Delphi already includes pre-compiled svn, svnui and svnide. You need to remove those from "Component> Install packages" list. (And restart)
  • The ones from SVN are marked ver_150, and the ones with Delphi ver_170, but the ones from SVN are newer (I think).
  • When compiling the packages, Delphi might try to trip you up and use existing packages it cached somewhere instead of the sources right in front of it.
    To be on a safe side, do dir c:\svn*.bpl /s, dir c:\svn*.dcp /s, dir c:\svn*.dcu /s, and remove everything related to VersionInsight plus. (Some matches are going to be in the cached Delphi install distributions, these are fine).
    Particularly, svn*.dcp in Program Files\Embarcadero\Delphi\DelphiVersion\lib\Win32\debug or \release are known to silently cause problems such as svnui.bpl complaining that TSvnBlameOptions is not defined even though it’s defined right there in SvnClient.pas.

Otherwise packages compile just fine, have no dependencies and produce almost no warnings.

After compiling the packages, install the last three (svnide, hgide and gitide). Restart the Delphi.

The SVN support will start working straight away (it should have been working before too). For Git and Mercurial you need to go to Tools> Options> Version Control, and set paths to git.exe and hg.exe executables in the respective sections.

Atlas Shrugged

Well, people say Rand’s book is about how to be an asshole. It certainly seems that some of her opponents just don’t need the training.

HOWTO: Add your own feed reader to Opera’s default list

By default, when you click on an RSS feed icon, Opera displays feed contents in some basic format and allows you to subscribe to it with either the built-in reader or some of the popular ones.

But with the recent end of life of Google Reader many will switch to other, less popular readers, or perhaps even install one on their own server.

To add a feed reader to Opera’s default reader list, edit feedreaders.ini in "Program Files\Opera\defaults" folder. The format is obvious. There doesn’t seem to be an option for a per-user feed reader list.

For instance, if you’re using Tiny Tiny RSS, the subscription URL is per faq:

http://your.domain.com/path-to-ttrss/public.php?op=subscribe&feed_url=%s

The code to add to feedreaders.ini will be:

[TinyRSS]
ID=20
URL=http://your.domain.com/path-to-ttrss/public.php?op=subscribe&feed_url=%s

Tell me what I’m going to use it for

For those who didn’t know, there’s a new pascal-based compiler on a market for a while, and a pretty cool one at that. Enter RemObjects Oxygene.

It’s Visual Studio-based, compiles to .NET, Android Java and iPhone Cocoa, resembles Pascal and implements the majority of its cool features like generics. Parts of language are redesigned, some for better, some for worse.

Cool feature. Even the main unit now has the interface/implementation sections.

namespace Application1;
interface
implementation
begin
  Console.WriteLine("The magic happens here.");
end.

Uncool feature. initialization/finalization sections are no more. I guess you can kinda replace them with class constructors, but they were so much better.

Anyway.

The language is indeed pretty fresh, with support even for WinRT while Delphi has yet to convince Microsoft to let everyone else have a part of the cake. Turns out, the only way to do native WinRT applications is through using Microsoft Visual C++ Runtime. Ha-ha, funny joke Microsoft, you.

So I thought about playing with it for a change.
No, I’m not betraying Delphi just yet. It’s still pretty cool, compiling to 64 bit and not being afraid of anything.

But sitting before the empty Oxygene project, I have found myself at loss at what to do.
Okay, it runs. It compiles Hello World, alright.
What next?

Turns out, when you encounter a new language, you have to have a few use cases for it. And since you usually don’t know what this langage can do, it’s better if someone suggests those for you.

One hyperlink multiple hrefs

The simple thing that HTML really lacks is the ability to set multiple HREF targets for a single link:

<a href="iichan.ru" href="iichan.hk">

Why would you need this?
1. To specify multiple hosts serving the same thing, ensuring that even if one host goes down, it’s still accessible (for instance, multiple sources for a pic you’re linking to)
2. To aid with domain name changes (linking to both old and new domains)
3. To keep information well-organized (for instance, there’s a well-known domain hosting this which is down now, but may be revived later, and you’re linking to a google cache copy or a mirror, and still want the main domain to be the logical “target”)

How to implement this:
Browsers shall try HREF links one after another, in the order of declaration. They MAY probe them all at once and choose the fastest server, or probe in batches. They MUST though choose one “default” HREF and display it in the interface, and navigate to other HREFs only after asking for permission from the user. They MAY let the user choose the HREF manually when clicking on link.

Correct: The browser randomly chooses second HREF as the default HREF. When the user clicks on link, the server is not accessible, so the browser asks for permission to use next randomly chosen (fifth) HREF. This one is not accessible too. The browser asks for permission to use next randomly chosen (first) HREF, which turns out to be available.
Correct: When the user clicks on link, the browser probes all the available HREFs. Since the default one is not accessible, the browser asks for permission to use the fastest available alternative.
Correct: When rendering the page, the browser probes all the available HREFs and uses the fastest available server as the default HREF.
Correct: When rendering the page, the browser uses it’s knowledge of which servers were available and which were down before, to guess the best default HREF without actually probing HREFs.

Rebuild of Evangelion 3.33: You shall (not) pass.
Rebuild of Evangelion 4.44: One does (not) simply walk into Mordor.

Did you know…

Foe = 10^44 joules.
Worthy foe = priceless.

Auto-updater

This is the automatic updater notice.

Current version of TortoiseSVN is: TortoiseSVN 1.4.8.0.
You’re using: TortoiseSVN 1.6.4.0.

Your version is forward-outdated, please downdate it immediately as the prolonged usage of the yet-to-be-developed product can lead to irrevocable temporal paradoxes and make you lose your data.

Features removed in TortoiseSVN 1.4.8.0:
– Option to specify temporal plane of the SVN server on the connection configuration page.
– Support for distributed-in-time version storage.
– Support for rolling edits back onto your computer, creating conflicts and untyping the conflicting changes (only for reverse quantum law architectures)

BMG13

(A: Araragi, H: Hachikuji)

H: So, Hanekawa’s that girl I met before, and Senjougahara’s your girlfriend?
A: Yup.
H: Hmm…
A: What?
H: Nothing, I’m just surprised since normally one would clearly choose Hanekawa over Senjougahara-san. Just why did you choose Senjougahara?
A: Why, you say… guess I just had no feelings for Hanekawa.

No, Araragi, let’s be frank, you chose her becase she proposed to you while Hanekawa did not, that’s all :)
分かり易い奴ですねぇ