In this post, I will be showing how to embed publicly hosted video into your Delphi source code. I’ll be using YouTube as an example hosting provider, but in practice, Viddler is probably a better choice because of its embedded comments feature and corporate support.
What to do
- Locate your CodeInsight directory. Eg. “C:Program FilesEmbarcaderoRAD Studio7.0ObjReposen” .
- Backup your original HelpInsight.xsl file.
- Open this file in an editor and locate the node <xsl:template match=”summary”>
- After the close of this node, insert the following node
<xsl:template match="youtube"> <iframe width="560" height="315" frameborder="0" controls="0"> <xsl:attribute name="src">http://www.youtube.com/embed/<xsl:value-of select="@id"/></xsl:attribute> </iframe> </xsl:template>
- Locate the <xsl:apply-templates select=”member/summary”/> node. Just after that one insert:
<xsl:apply-templates select="member/youtube">
- Save and close HelpInsight.xsl file.
- Open up Delphi. Just before the class or declarative element that you which to annotate, insert something like this …
{$REGION 'xmldoc'} type /// <summary>Play this video!</summary> /// <youtube id="PWNLPl7oIRc"/> {$ENDREGION}
Replace the id code with the YouTube id of your annotating video. The Summary node is completely optional. The “Type” inside the folded region is important – I’ll explain that in a moment.
- Close the folded region.
- Mouse over your target class or declarative element. Give it a second, and Alakhazam! Embedded Video!
So what’s with the extraneous “type” inside the folded region?
Delphi’s Help Insight feature has a surprising anomaly (read “bug”). If you have two or more type declarations in a unit, Help Insight only works on the first declarative element after the “type” keyword. Where normally, a developer would tend to write:
type TMyFirstType = banana banana banana; TMySecondType = banana banana banana;
To get Help Insight to work on both declarations, we have to write it like this:
type {$REGION 'xmldoc'} /// <summary>This is about TMyFirstType. It involves a lot of bananas.</summary> {$ENDREGION} TMyFirstType = banana banana banana; {$REGION 'xmldoc'} type /// <summary>This is about TSecondFirstType.</summary> {$ENDREGION} TMySecondType = banana banana banana;
The funny thing is, that if you choose Viddler over YouTube and you embed some comments in your video, what is presented to the client-developer is text comments embedded in video embedded in XML embedded in source code.
Awesome! I’m gonna try it now!
This is amazingly cool and incredibly useless 🙂
I can get it to work with XE but in XE2 due to the bundled Documentation Insight plugin the HelpInsight.xsl file has a completely different structure and doesn’t seem to have the corresponding sections.
Hello just wanted to give you a quick heads up.
The text in your article seem to be running off the screen in Internet explorer.
I’m not sure if this is a formatting issue or something to do with browser compatibility but I thought I’d post to let
you know. The design look great though! Hope you get the issue
resolved soon. Kudos