<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>困了也不睡</title>
	<atom:link href="http://wenjinjin.com/feed" rel="self" type="application/rss+xml" />
	<link>http://wenjinjin.com</link>
	<description>又一个 WordPress 博客</description>
	<lastBuildDate>Mon, 04 Jul 2011 09:54:00 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>敏捷宣言遵循的原则</title>
		<link>http://wenjinjin.com/code_document/other/principles_behind_the_agile_manifesto.html</link>
		<comments>http://wenjinjin.com/code_document/other/principles_behind_the_agile_manifesto.html#comments</comments>
		<pubDate>Mon, 04 Jul 2011 09:54:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[其他]]></category>

		<guid isPermaLink="false">http://wenjinjin.com/?p=149</guid>
		<description><![CDATA[我们遵循以下原则：
我们最重要的目标，是通过持续不断地
及早交付有价值的软件使客户满意。
欣然面对需求变化，即使在开发后期也一样。
为了客户的竞争优势，敏捷过程掌控变化。
经常地交付可工作的软件，
相隔几星期或一两个月，倾向于采取较短的周期。
业务人员和开发人员必须相互合作，
项目中的每一天都不例外。
激发个体的斗志，以他们为核心搭建项目。
提供所需的环境和支援，辅以信任，从而达成目标。
不论团队内外，传递信息效果最好效率也最高的方式是
面对面的交谈。
可工作的软件是进度的首要度量标准。
敏捷过程倡导可持续开发。
责任人、开发人员和用户要能够共同维持其步调稳定延续。
坚持不懈地追求技术卓越和良好设计，敏捷能力由此增强。
以简洁为本，它是极力减少不必要工作量的艺术。
最好的架构、需求和设计出自自组织团队。
团队定期地反思如何能提高成效，
并依此调整自身的举止表现。
来源：http://agilemanifesto.org/iso/zhchs/principles.html
]]></description>
			<content:encoded><![CDATA[<p>我们遵循以下原则：</p>
<p>我们最重要的目标，是通过持续不断地<br />
及早交付有价值的软件使客户满意。</p>
<p>欣然面对需求变化，即使在开发后期也一样。<br />
为了客户的竞争优势，敏捷过程掌控变化。</p>
<p>经常地交付可工作的软件，<br />
相隔几星期或一两个月，倾向于采取较短的周期。</p>
<p>业务人员和开发人员必须相互合作，<br />
项目中的每一天都不例外。</p>
<p>激发个体的斗志，以他们为核心搭建项目。<br />
提供所需的环境和支援，辅以信任，从而达成目标。</p>
<p>不论团队内外，传递信息效果最好效率也最高的方式是<br />
面对面的交谈。</p>
<p>可工作的软件是进度的首要度量标准。</p>
<p>敏捷过程倡导可持续开发。<br />
责任人、开发人员和用户要能够共同维持其步调稳定延续。</p>
<p>坚持不懈地追求技术卓越和良好设计，敏捷能力由此增强。</p>
<p>以简洁为本，它是极力减少不必要工作量的艺术。</p>
<p>最好的架构、需求和设计出自自组织团队。</p>
<p>团队定期地反思如何能提高成效，<br />
并依此调整自身的举止表现。</p>
<p>来源：http://agilemanifesto.org/iso/zhchs/principles.html</p>
]]></content:encoded>
			<wfw:commentRss>http://wenjinjin.com/code_document/other/principles_behind_the_agile_manifesto.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>敏捷软件开发宣言</title>
		<link>http://wenjinjin.com/code_document/other/manifesto_for_agile_software_development.html</link>
		<comments>http://wenjinjin.com/code_document/other/manifesto_for_agile_software_development.html#comments</comments>
		<pubDate>Mon, 04 Jul 2011 09:52:15 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[其他]]></category>

		<guid isPermaLink="false">http://wenjinjin.com/?p=147</guid>
		<description><![CDATA[我们一直在实践中探寻更好的软件开发方法，
身体力行的同时也帮助他人。由此我们建立了如下价值观：
个体和互动 高于 流程和工具
工作的软件 高于 详尽的文档
客户合作 高于 合同谈判
响应变化 高于 遵循计划
也就是说，尽管右项有其价值，
我们更重视左项的价值。
来源：http://agilemanifesto.org/iso/zhchs/
]]></description>
			<content:encoded><![CDATA[<p>我们一直在实践中探寻更好的软件开发方法，<br />
身体力行的同时也帮助他人。由此我们建立了如下价值观：</p>
<p>个体和互动 高于 流程和工具<br />
工作的软件 高于 详尽的文档<br />
客户合作 高于 合同谈判<br />
响应变化 高于 遵循计划</p>
<p>也就是说，尽管右项有其价值，<br />
我们更重视左项的价值。</p>
<p>来源：http://agilemanifesto.org/iso/zhchs/</p>
]]></content:encoded>
			<wfw:commentRss>http://wenjinjin.com/code_document/other/manifesto_for_agile_software_development.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>不可见的 Flash</title>
		<link>http://wenjinjin.com/code_document/web/invisible-flash.html</link>
		<comments>http://wenjinjin.com/code_document/web/invisible-flash.html#comments</comments>
		<pubDate>Mon, 12 Jul 2010 06:54:00 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[web技术]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://wenjinjin.com/?p=142</guid>
		<description><![CDATA[Michael Galpin, 软件架构师, eBay
简介： 您是否想过让 Cookies 容量更大以便在客户端存储更多数据，或者能实现跨域的 Asynchronous JavaScript and XML (Ajax) 调用？如果是，那么您很幸运。这两项技术都可以通过使用不可见的 Flash 实现。那么，什么是不可见的 Flash？它不是真正的不可见，而是它只有 1 × 1 个像素大，因此肉眼很难辨别。而且，它可以利用 Flash Player 的功能。在本文中，您将学习如何创建不可见 Flash 文件，以便能在客户端存储多达 100 KB 的数据，以及实现跨域 Ajax 调用 — 并且您的用户甚至不知道使用了 Flash。
让我们开始吧
如前所述，您将在本文中学习如何使用 Flash 为 Web 应用程序增添额外的功能。熟悉 JavaScript 是必需的技能，有 ActionScript 使用经验将会很方便。有很多方法编译 ActionScript，其中一些依赖于 Adobe 的商业工具。然而，也可以使用 Adobe 的开源 Flex SDK。本文使用的是 Flex SDK 4.0.0.10485 (Beta 2)。为了运行示例程序，需要 Flash Player [...]]]></description>
			<content:encoded><![CDATA[<div><a rel="#authortip1" href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#author1">Michael Galpin</a>, 软件架构师, eBay</div>
<p><strong>简介：</strong> 您是否想过让 Cookies 容量更大以便在客户端存储更多数据，或者能实现跨域的 Asynchronous JavaScript and XML (Ajax) 调用？如果是，那么您很幸运。这两项技术都可以通过使用不可见的 Flash 实现。那么，什么是不可见的 Flash？它不是真正的不可见，而是它只有 1 × 1 个像素大，因此肉眼很难辨别。而且，它可以利用 Flash Player 的功能。在本文中，您将学习如何创建不可见 Flash 文件，以便能在客户端存储多达 100 KB 的数据，以及实现跨域 Ajax 调用 — 并且您的用户甚至不知道使用了 Flash。</p>
<p><a name="N1006A">让我们开始吧</a></p>
<p>如前所述，您将在本文中学习如何使用 Flash 为 Web 应用程序增添额外的功能。熟悉 JavaScript 是必需的技能，有 ActionScript 使用经验将会很方便。有很多方法编译 ActionScript，其中一些依赖于 Adobe 的商业工具。然而，也可以使用 Adobe 的开源 Flex SDK。本文使用的是 Flex SDK 4.0.0.10485 (Beta 2)。为了运行示例程序，需要 Flash Player 的第 10 版或更高版本。本文中使用的是 10.0.42.34 版本。<a href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#resources">参考资料</a> 中有下载链接。</p>
<p><a name="N10077">Flash 本地存储</a></p>
<p>许多 Web 应用程序需要在客户端存储状态。有时候这仅仅是某种类型的会话 ID，它可以用来从内存或数据库检索服务器端状态。然而，很多 Web 应用程序出于可伸缩性的考虑故意避免服务器端状态。因此，所有的状态都要存储在客户端。另外，通常希望状态在当前回话结束后仍然保持。</p>
<p>长期以来都使用 HTTP cookies 作为默认的处理方式。然而，HTTP cookies 存在缺陷。在开发人员看来，它难以运用，因为它实际是只是一个 HTTP 头部。更重要的是，存在安全隐患。对于每个请求，HTTP cookies 都会在客户端和服务器端来回传递，因此其中的所有数据都可能被截取。还有，跨站点脚本/伪造会利用这一特定 “窃取 cookie”。如果 cookies 被窃取了，您的相应账号很可能被破坏甚至被他人利用。</p>
<p>但是，HTTP cookies 最常见的缺陷就是大小限制。不同浏览器为每个域分配的 HTTP cookies 的最大容量是不同的。HTTP 规范将其限制为 4 KB，这就是您所能利用的所有空间。如果想在客户端存储大于 4 KB 的数据怎么办呢？如果您考虑过这些问题，您只好无奈地用 Java™Script 编写一个 gip 式的压缩算法，这是一种方法。或者，可以使用其他替代方法，例如，Flash。</p>
<p><a name="N10088">本地共享对象</a></p>
<p>Flash Player 为 Flash 应用程序提供了本地存储空间。默认情况下，每个域有 100 KB 的限制。这样很好：可获得是 HTTP cookies 的 25 倍的空间。还有其他一些重要的差异。其一，Flash 中存储的客户端数据不会发送给服务器，因为它与 HTTP 没有任何关系。当然，如果您愿意，也可以将这些数据发送给服务器。这样做不会有任何障碍。然而，您必须选择发送哪些数据以及以什么方式发送。如果您真的希望客户端和服务器都包含这些数据，这就有点复杂了。但是，这通常更加安全，因为您必须在网络中显式 “公开” 这些数据。</p>
<p>用于存储和检索本地数据的 Flash API 是 <code>SharedObject</code>。其实，Flash 的 <code>SharedObject</code> 概念也可以是远程的，因此，仅存在于客户端的变体也称为本地 <code>SharedObject</code>。该 API 非常简单，它允许使用键-值范式存储和检索任意复杂的对象。清单 1 是存储和检索<code>SharedObjects</code> 的简单代码。<br />
<a name="l1"><strong>清单 1. 存储和检索 <code>SharedObjects</code></strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>package{

    import flash.display.Sprite;
    import flash.net.SharedObject;

    public class JsHelper extends Sprite{
        private const SO_NAME:String = "helperSo";

        private function saveLocal(name:String, value:Object):void{
            var so:SharedObject = SharedObject.getLocal(SO_NAME);
            so.data[name] = value;
            so.flush();
        }

        private function readLocal(name:String):Object{
            var so:SharedObject = SharedObject.getLocal(SO_NAME);
            return so.data[name];
        }
    }
}
</pre>
</td>
</tr>
</tbody>
</table>
<p>如果您不熟悉 ActionScript，清单 1 的代码可能看上去有点奇怪。ActionScript 很像 JavaScript；实际上，它来自于 ECMAScript 标准。尽管如此，它具有很多 C++ 和 Java 中常见的特性。变量都是强类型的，还有基于类的继承。清单 1 中的代码是一个扩展了<code>Sprite</code> 类的类。该类将会编译进 Shockwave Flash (SWF) 文件，此文件会嵌入 Web 页面中。该类有两个方法。其中一个叫<code>saveLocal</code>。它需要一个名称（只是一个字符串）和一个值（任何类型的对象）。然后它使用 <code>getLocal</code> 工厂方法取得特定的<code>SharedObject</code>。</p>
<p>每个 <code>SharedObject</code> 实例都有一个数据属性，可以看作存储数据的哈希表。这就是 <code>saveLocal</code> 函数的第二行的作用。 最后一行 “清除”<code>SharedObject</code>，或将其保存到磁盘上。这些就是本地存储所要做的一切。如果大量使用 <code>SharedObjects</code> 并接近了 100 KB 的限制，那么您可能需要添加事件监听器。这将能够对 “清除完成” 或 “清除失败” 之类的事件做出响应。</p>
<p>从本地存储中回读同样也很简单，这是通过清单 1 的 <code>readLocal</code> 函数完成的。本例中，已搜索到 <code>SharedObject</code>，并且 <code>name</code> 参数已用于从数据哈希表中搜索已存储的对象。如果哈希表中没有与键值对应的名称，将返回 null。既然已学会如何访问 <code>SharedObjects</code>，现在只需要在 Web 页面上获取 Flash（不可见）— 以及使用 JavaScript 访问它。</p>
<p><a href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#ibm-pcon">回页首</a></p>
<p><a name="N100E9">使其不可见</a></p>
<p>默认情况下，清单 1 中的任何函数都无法在 <code>JsHelper</code> 类以外访问。然而，Flash 能够很容易地将函数公开给 JavaScript。需要做的就是使用 Flash 的 <code>ExternalInterface</code> API，如清单 2 所示。<br />
<a name="l2"><strong>清单 2. 将 <code>JsHelper</code> 函数公开给 JavaScript</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>package{

    import flash.external.ExternalInterface;
    import flash.net.SharedObject;

    public class JsHelper extends Sprite{
        private const SO_NAME:String = "helperSo";
        private const SAVE_LOCAL:String = "saveLocal";
        private const READ_LOCAL:String = "readLocal";

        public function JsHelper(){
            ExternalInterface.addCallback(SAVE_LOCAL, saveLocal);
            ExternalInterface.addCallback(READ_LOCAL, readLocal);
        }
        // functions omitted for brevity
    }
}
</pre>
</td>
</tr>
</tbody>
</table>
<p>清单 2 简单演示了向清单 1 中的 <code>JsHelper</code> 类添加的内容。主要的注意点是添加了一个显式构造函数。正如您所料，这个构造函数将在创建类的一个实例时得到调用。其中，使用 <code>ExternalInterface</code> API 将两个函数 <code>saveLocal</code> 和 <code>readLocal</code> 公开给 SWF 所嵌入的所有 Web 页面上的 JavaScript。<code>addCallback</code> 函数的第一个参数是字符串。JavaScript 客户端使用它作为名称识别函数。它与类中的函数名可能不同，但在该例中是相同的。第二个参数是一个函数闭包。与 JavaScript 一样，ActionScript 是函数语言，因此函数是一阶的，可以传递。这就是公开两个函数所需要做的。现在看看用于嵌入和访问 SWF 的 JavaScript。详见清单 3。<br />
<a name="l3"><strong>清单 3. 嵌入不可见 Flash</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
&lt;title&gt;Flash Helper for JavaScript&lt;/title&gt;
&lt;script type="text/javascript" src="swfobject.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
    function writeFlash(){
        var attrs = {id : "JsHelper"};
        swfobject.embedSWF("JsHelper.swf", "flashContainer", "1", "1", "10.0.0",
            "playerProductInstall.swf", null, null, attrs);
    }
    function save(name, value){
        var helper = document.getElementById("JsHelper");
        helper.saveLocal(name, value);
    }
    function load(name){
        var helper = document.getElementById("JsHelper");
        return helper.readLocal(name);
    }
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="writeFlash()"&gt;
    &lt;div id="flashContainer"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
</td>
</tr>
</tbody>
</table>
<p>这段代码中首先要注意的是使用了第三方 JavaScript 库 <code>swfobject</code>。这实际上是嵌入 SWF 的标准库。它是开源的，虽然最初不是由 Adobe 开发的，但是现在由他们维护。它的 <code>embedSWF</code> 函数用于嵌入由清单 2 编译的 SWF。第一个参数是指向 SWF 的 URL。本例中，SWF 来自和 HTML 文件相同的服务器和路径，因此可以使用一个相对 URL。第二个参数是在其中嵌入 SWF 的页面的 HTML 元素的 ID。本例中是 <code>"flashContainer"</code> — 同时您将注意到 HTML 文档的主体部分有一个 HTML <code>div</code> 使用该 ID。</p>
<p>接下来的两个 <code>embedSWF</code> 参数是 SWF 的高度和宽度。在本例中，两者的值都是 1。这意味着 SWF 的高度和宽度都为一个像素。这就是不可见的 SWF！下一个参数是 Flash 的最低版本，您的 JavaScript 将检查该参数。如果 Flash 已安装在浏览器上，但其版本号比传递给 <code>embedSWF</code> 的版本号更低，那么 <code>embedSWF</code> 将使用下一个参数 <code>"playerProductInstall.swf"</code>。这是指向另一个 SWF 的 URL，它提示用户安装最新版本的 Flash。对于不可见 Flash，这其实没什么影响 — “您需要安装最新版本 Flash” 的 SWF 其实也不可见（当然，也是 1&#215;1 像素）。传给 <code>embedSWF</code> 的最后一个参数很重要。这是一个包含各种可选参数的属性对象。其中一个可选参数是 SWF 的 ID。对于和本文类似的用例，该参数是不可选的 — 这至关重要！它将会提供给 SWF 一个 HTML ID，而这将会在使用 JavaScript 进行编程访问时用到。</p>
<p>现在看看 <a href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#l3">清单 3</a> 中的两个 JavaScript 函数。二者很相似。都使用熟悉的 <code>getElementById</code> 函数获取 SWF 的引用。请注意它们使用的是 <code>writeFlash</code> 函数中的 <code>attrs</code> 对象指定的 ID。取得 SWF 引用后，可以直接调用 <a href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#l2">清单 2</a> 中公开的 ActionScript 函数。此处的关键是，JavaScript 中使用的函数名必须匹配 <code>ExternalInterface.addCallback</code> 函数中公开的名称或者是传给 <code>addCallback</code> 的第一个参数。</p>
<p>对于 save 方法，传递了一个 JavaScript 对象作为 value 参数。这可以是任意对象，甚至可以具有一个深度嵌套的结构。然而，只会传递对象的数据。如果该对象包含函数，那么将不会被传递。请注意 load 方法将返回所有来自 SWF 的内容。是什么内容？答案很简单：您发送的任何内容。如果您存储的是数字或字符串等标量值，那么将返回这些内容。如果存储的是复杂的对象，那么将返回该 JavaScript 对象 — 不需要解析或其它操作。一个例外是假如对象包含函数，那么肯定不会被序列化并保存。因此只会返回对象中的数据，而不是其他内容。以上总结了使用 Flash 进行本地存储所需掌握的全部内容。在学习使用 Flash 操作跨域 Ajax 之前，了解一些可作为替代选择的本地存储方法。</p>
<p><a href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#ibm-pcon">回页首</a></p>
<p><a name="N1017B">其他的本地存储选择</a></p>
<p>我提到 Flash 是面向客户端存储的一个有吸引力的选择，可以代替 HTTP cookies。尽管如此，还有两项 Web 技术采用了与 Flash<code>SharedObjects</code> 一样的范式。事实上，长期以来各种浏览器都提供相似的 API。但各浏览器的 API 不尽相同。因此您可以先了解一下各个浏览器，然后使用特定的 API。Flash 提供了一致的替代方案。本文中开发的代码几乎可以运行于所有浏览器：Internet Explorer 6 和 Firefox 2，以及这些浏览器的最新版本。更新的版本提供一致的解决方案。HTML 5 规范包含一个 <code>localStorage</code> API。主流浏览器的最新版本都实现了这个 API，包括 IE 8 和 Firefox 3.5。因此如果只担心浏览器的话，<code>localStorage</code> 将是一个可用的选项。如果担心旧的浏览器（IE 6、IE 7 等等），那么使用 Flash 可能会更容易。现在，看看 Flash 能够实现的新功能，跨域 Ajax。</p>
<p><a href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#ibm-pcon">回页首</a></p>
<p><a name="N10190">跨域 Ajax</a></p>
<p>Ajax 目前在 Web 应用程序中无所不在；它是任何 Web 应用程序中都假设会有的部分。Ajax 的一个主要不足就是为人诟病的同源策略。如果 Web 页面由 a.com 提供，您只能向 a.com 调用 Ajax（更精确地说是 <code>XMLHttpRequest</code>）。例如，您无法调用 b.com。如果您的公司拥有 a.com 和 b.com，那就没有影响；浏览器不会关心这些。但是对 Flash 应用程序却不是这样。</p>
<p>Flash 应用程序可以获得许可，并对提供服务的域以外的域进行调用。这可以用跨域策略文件完成。默认情况下，Flash 运行时将在服务器的文档根目录搜索策略文件：http://&lt;your domain&gt;/crossdomain.xml。例如，清单 4 是 Twitter 搜索域的策略文件，http://search.twitter.com/crossdomain.xml。<br />
<a name="l4"><strong>清单 4. Twitter 搜索域的策略文件</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>&lt;!DOCTYPE cross-domain-policy
SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"&gt;

&lt;cross-domain-policy&gt;
    &lt;allow-access-from domain="*" /&gt;
&lt;/cross-domain-policy&gt;
</pre>
</td>
</tr>
</tbody>
</table>
<p>这是个相当好的策略文件。它允许所有（如 “*” 通配符所示）域对 SWF 进行访问。因此所有 Flash 应用程序都可以调用 Twitter 的搜索 API。在大多数具有公共 API 的 Web 网站上像这样的策略文件很常见。尽管如此，有些网站使用更加严格的策略，只允许自己所有的其他域或合作伙伴的域进行访问。有了策略文件，就可以细粒度地精确控制谁能够调用服务器，谁不能。看看如何将同样的功能扩展到 Ajax 应用程序中。</p>
<p><a href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#ibm-pcon">回页首</a></p>
<p><a name="N101AC">跨域</a></p>
<p>如果您的应用程序只需要调用特定的域，可以编写 ActionScript 代码调用该域，然后在应用程序中使用 <code>ExternalInterface</code> 将其公开给 JavaScript。然而，我将采取一种更好的方法，并试图用更一般化的方式进行公开。因此，清单 5 中，将使用一个实用类从 ActionScript 中调用任意域。<br />
<a name="l5"><strong>清单 5. 跨域工具 SWF</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>package{

    import flash.display.Sprite;
    import flash.events.Event;
    import flash.external.ExternalInterface;
    import flash.net.URLLoader;
    import flash.net.URLRequest;

    public class JsHelper extends Sprite{
        private const SEND_REQUEST:String = "sendRequest";

        public function JsHelper(){
            ExternalInterface.addCallback(SEND_REQUEST, sendRequest);
        }

        public function sendRequest(url:String, handlerName:String,
                method:String="GET", content:Object=null,
                headers:Object=null):void{
            var loader:URLLoader = new URLLoader();
            var request:URLRequest = new URLRequest(url);
            if (method){
                request.method = method;
            }
            if (headers){
                for each (var name:String in headers){
                    request.requestHeaders[name] = headers[name];
                }
            }
            if (content){
                request.data = content;
            }
            loader.addEventListener(Event.COMPLETE,
                function(e:Event):void{
                    ExternalInterface.call(handlerName, loader.data);
            });
            loader.load(request);
        }
    }
}
</pre>
</td>
</tr>
</tbody>
</table>
<p>该类使用 <code>ExternalInterface</code> 将 <code>sendRequest</code> 函数公开给 JavaScript。这在对象的构造函数中完成，和之前 <a href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#l2">清单 2</a> 中的例子一样。<code>sendRequest</code> 函数有点复杂：它有两个必需的参数。第一个参数是需要调用的 URL。这是一个完整的 URL 字符串，包含所有请求参数。下一个是 JavaScript 函数名，此函数在获得服务器响应后由 Flash 调用。和典型的 Ajax 一样，Flash 对远程服务器进行异步调用，主 UI 线程在等待远程服务器响应时不会停止。因此，与 Ajax 一样，需要编写 <code>callback</code> 函数，它将在接收到服务器响应后被调用。将其作为字符串传递给 Flash，但它必须与函数名完全相同。</p>
<p><code>sendRequest</code> 函数也有三个可选参数。ActionScript 允许有可选参数，但必须有可用的缺省值。第一个是使用 HTTP 方法，通常是 <code>GET</code>或 <code>POST</code>。本文中，我将它默认为 <code>GET</code>，但是可以很容易地用 <code>POST</code> 将其替换，这取决于远程服务器的需要。下一个可选参数叫做<code>content</code>。这是一个一般数据对象，包含有需要发送给远程服务器的任意名称-值对。向远程服务器发送数据时需要用到。最后一个可选参数是另一个用于头部的一般数据对象。它用于将定制 HTTP 头部设置为作为远程服务器调用的一部分发送。</p>
<p>然后代码获取所有这些参数，使用 Flash <code>URLRequest</code> 对象构造 HTTP 请求，然后使用 Flash <code>URLLoader</code> 类发送请求。事件监听器会绑定到 <code>URLLoader</code> 以便能处理返回的响应。这里创建一个闭包，如同在 JavaScript 中一样，创建一个匿名内联函数，将在 <code>COMPLETE</code> 事件被加载程序触发后调用。该闭包将只使用 <code>ExternalInterface</code> 来调用名称被传递给 <code>sendRequest</code> 的函数。它将来自远程服务器的所有数据传递给该函数。这显然比使用本地存储复杂一点。看看清单 6 中调用 Twitter 搜索的例子。<br />
<a name="l6"><strong>清单 6. 调用 Twitter 搜索</strong></a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<td>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
&lt;title&gt;Calling Twitter from the client&lt;/title&gt;
&lt;script type="text/javascript" src="swfobject.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
    function writeFlash(){
        var attrs = {id : "JsHelper"};
        swfobject.embedSWF("JsHelper.swf", "flashContainer", "1", "1", "10.0.0",
            "playerProductInstall.swf", null, null, attrs);
    }
    function search(){
        var keyword = document.getElementById("keyword").value;
        var helper = document.getElementById("JsHelper");
        helper.sendRequest("http://search.twitter.com/search.json?q=" + keyword,
"showResults");
    }
    function showResults(responseStr){
        var response = eval("(" + responseStr +")");
        var results = response.results;
        alert("#Results = " + results.length);
    }
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="writeFlash()"&gt;
    &lt;div id="flashContainer"&gt;&lt;/div&gt;
    &lt;div id="inputDiv"&gt;
        &lt;label for="id"&gt;Search Twitter&lt;/label&gt;
        &lt;input type="text" id="keyword" name="keyword"/&gt;
        &lt;input type="button" value="Search Twitter" onclick="search()"/&gt;
    &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
</td>
</tr>
</tbody>
</table>
<p>此处的代码与 <a href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#l3">清单 3</a> 中的 HTML/JS 类似。再次使用了 <code>swfobject</code> 库将 SWF 嵌入页面中。代码中有个简单的表单，提示用户输入在 Twitter 中搜索的关键词。单击 Search 按钮后调用搜索函数。它从输入字段取得关键词并用于创建需要调用的 URL。然后传递给 JsHelper SWF，就像在 <a href="http://www.ibm.com/developerworks/cn/web/wa-aj-flash/index.html#l3">清单 3</a> 中那样，通过使用 ID 取得 SWF 的引用，然后使用 <code>ExternalInterface</code> 直接调用公开的函数。传递一个 URL 和命名回调函数的字符串。数据从 Twitter 返回后，传递到 <code>showResults</code> 函数。这是一个 JSON 字符串，因为它是从 Twitter 返回的，因此可以简单地用 JavaScript 的 <code>eval</code> 函数将其转换为一个对象。本例中，只是简单显示了从 Twitter 中返回的结果数。尽管如此，可以方便地在页面中创建 HTML 来列举每个结果；只是些样板 DOM 代码。就是这样，您学习了借助 Flash 的跨域 Ajax 调用的方法。与使用 Flash 进行本地储存一样，还有其他一些替代方法。</p>
<p><a name="N10232">跨域替代方案</a></p>
<p>Flash 长期以来被用于实现跨域调用，就像它可以实现本地存储一样。与本地存储的用例一样，一些 Web 浏览器实现了自己的方式，后来也出现了一些标准化工作。与本地存储相比，进展并不顺利。尽管目前已有跨域 Ajax 标准，却未被 IE 8 采用。相反，IE 8 以一种特有的方式处理跨域 Ajax。这种特有方式的实现在 IE 8 中是全新的，在旧版本 IE 中没有。Flash 再一次展示了一个可以跨所有浏览器工作的模型。</p>
<div><a name="clgrp"></a></p>
<h2>加入 My developerWorks 中的 Web 开发组</h2>
<div>
<p>在 <a href="http://www.ibm.com/developerworks/mydeveloperworks/groups/service/html/communityview?communityUuid=4a88af42-962d-4f4d-9b6a-245ea1e61f11">My developerWorks Web 开发组</a> 中与其他开发人员讨论话题、分享资源。</p>
<p>还不是 My developerWorks 的成员？<a href="http://www.ibm.com/developerworks/mydeveloperworks/cn/">现在就加入！</a></p>
</div>
</div>
<p>最后，如果您研究过跨域 Ajax，您肯定会发现其他方法，而不需要 Flash 或任何其他浏览器特性。这项技术，通常称为 JSONP（含有 Padding 的 JSON ）或者是 “动态脚本标记”，它利用了浏览器不对 JavaScript 源文件强制执行同源策略的特性。因此创建了一个脚本标记，它的源指向要调用的 URL，并插入到 DOM 中。该 URL 通常包含一个 “回调” 参数，它是您想要调用的回调函数的名称。服务器然后将数据与函数名封装，以便函数得到调用，且来自服务器的数据被传递给它。这项技术在 Internet 上广泛运用（例如，前面展示的 Twitter 搜索 API 就支持该技术），但有相应的安全风险 — 因此，标准的、安全的做法，就应该像 Flash 那样。</p>
<p><a name="N10255">结束语</a></p>
<p>本文介绍了如何使用 Flash 扩展 Web 应用程序的功能。您可以极大地增加应用程序所能访问的本地存储容量。这使您能够在客户端缓存大量数据。您还可以使用 Flash 从 Web 应用程序进行跨域 Ajax 调用。这里只是粗略体验一下 Flash 的功能。如果您觉得其他功能对您也有所帮助，可以使用同样的技术：使 Flash 不可见并用 <code>ExternalInterface</code> 公开其函数。</p>
<p><a name="download">下载</a></p>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tbody>
<tr>
<th scope="col">描述</th>
<th scope="col">名字</th>
<th scope="col">大小</th>
<th scope="col">下载方法</th>
</tr>
<tr>
<td scope="row">文章源代码</td>
<td>JsHelper.zip</td>
<td>12KB</td>
<td><a href="http://www.ibm.com/developerworks/apps/download/index.jsp?contentid=499574&amp;filename=JsHelper.zip&amp;method=http&amp;locale=zh_CN">HTTP</a></td>
</tr>
</tbody>
</table>
<p><a name="resources">参考资料</a></p>
<p><strong>学习</strong></p>
<ul>
<li>“<a href="http://www.ibm.com/developerworks/cn/web/wa-actionscript/">ActionScript 3.0 闪亮登场！</a>”：很好的 ActionScript 介绍。</li>
<li>“<a href="http://www.ibm.com/developerworks/cn/opensource/os-php-flexsdk/">使用 Flex SDK、Mate 和 PHP</a>”：学习使用 Flex SDK。</li>
<li>Flex SDK 是 Flex 框架的一部分，该框架是流行的、基于 Flash 的框架，可用于创建富互联网应用程序。在 developerWorks 文章 “<a href="http://www.ibm.com/developerworks/cn/web/wa-riagrails1/">使用 Grails 构建富 Internet 应用程序，第 1 部分: 使用 Grails 和 Flex 构建 Web 应用程序</a>”中探索其功能。</li>
<li>“<a href="http://www.ibm.com/developerworks/cn/web/wa-aj-jsonp1/">使用 JSONP 实现跨域通信，第 1 部分: 结合 JSONP 和 jQuery 快速构建强大的 mashup</a>”：学习将 JSONP 用于跨域 Ajax。</li>
<li><a href="http://opensource.adobe.com/wiki/display/flexsdk/Flex+SDK">Flex Wiki</a>：获取 Flex SDK 的最新消息和最新版本的 SDK。</li>
<li><a href="https://developer.mozilla.org/en/DOM/Storage">DOM Storage</a>：通过阅读 Mozilla 文章了解 Firefox 对 HTML 5 本地存储的支持。</li>
<li><a href="http://msdn.microsoft.com/en-us/library/cc288060%28VS.85%29.aspx">XDomainRequest</a>：阅读关于 IE 8 跨域实现的文档。</li>
<li><a href="https://developer.mozilla.org/En/HTTP_Access_Control">HTTP 访问控制</a>：通过阅读 Mozilla 文章了解 Firefox 如何实现跨域 Ajax。</li>
<li>developerWorks <a href="http://www.ibm.com/developerworks/cn/web/">Web 开发专区</a> 专门提供大量文章，介绍了各种基于 Web 的解决方案。</li>
<li><a href="http://www.ibm.com/developerworks/mydeveloperworks/cn/">My developerWorks</a>：个性化您的 developerWorks 体验。</li>
<li>要收听有关软件开发人员的有趣访谈和讨论，请访问 <a onmouseover="linkQueryAppend(this)" href="http://www.ibm.com/developerworks/podcast/">developerWorks podcasts</a>。</li>
<li>developerWorks <a href="http://www.ibm.com/developerworks/cn/offers/techbriefings/">技术活动</a>和<a href="http://www.ibm.com/developerworks/cn/swi/">网络广播</a>：随时关注 developerWorks 技术活动和网络广播。</li>
</ul>
<p><strong>获得产品和技术</strong></p>
<ul>
<li>下载 <a href="http://opensource.adobe.com/wiki/display/flexsdk/Download+Flex+3">Flex SDK</a>。</li>
<li>使用 <a href="http://www.ibm.com/developerworks/cn/downloads/">IBM 试用软件</a> 改进您的下一个开源开发项目，可通过下载或 DVD 获得。</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://wenjinjin.com/code_document/web/invisible-flash.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>DELPHI字符串分割函数</title>
		<link>http://wenjinjin.com/code_document/delphi_doc/delphi_string_split.html</link>
		<comments>http://wenjinjin.com/code_document/delphi_doc/delphi_string_split.html#comments</comments>
		<pubDate>Thu, 08 Jul 2010 14:44:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DELPHI文档]]></category>
		<category><![CDATA[字符串]]></category>

		<guid isPermaLink="false">http://wenjinjin.com/?p=137</guid>
		<description><![CDATA[

dephi中没有象PHP中的explode函数 ,但是使用TStringList类的 Delimter 和 DelimtedText 两个属性可以很容易的把字符串分割,然后放入 TStrings里面.
例:
s:=&#8217;aa,bb,cc,dd&#8217;
ts := TStringList.Create
ts.Delimter := &#8216;,&#8217;
ts.DelimtedText := s
//这时 ts里面就存放了 aa bb cc dd 这四个strings了. 你只要通过 ts[0]就可以取第一个数据
function SplitString(Source, Deli: string ): TStringList;stdcall;
var
EndOfCurrentString: byte;
StringList:TStringList;
begin
StringList:=TStringList.Create;
while Pos(Deli, Source)&#62;0 do
begin
EndOfCurrentString := Pos(Deli, Source);
StringList.add(Copy(Source, 1, EndOfCurrentString &#8211; 1));
Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) &#8211; EndOfCurrentString);
end;
Result := StringList;
StringList.Add(source);
end;
procedure StrToStrs(str:string;strs:tstrings);
var temp:string;
i:integer;
label B,E;
begin
B:
i:= ansipos(&#8216;&#124;&#8217;,str);
if i=0 THEN GOTO E;
strs.Add(ansileftstr(str,i-1));
str:=ansirightstr(str,length(str)-i);
GOTO [...]]]></description>
			<content:encoded><![CDATA[<div><span style="font-size: medium;"></p>
<div id="_mcePaste">
<div id="_mcePaste">dephi中没有象PHP中的explode函数 ,但是使用TStringList类的 Delimter 和 DelimtedText 两个属性可以很容易的把字符串分割,然后放入 TStrings里面.</div>
<div id="_mcePaste">例:</div>
<div id="_mcePaste">s:=&#8217;aa,bb,cc,dd&#8217;</div>
<div id="_mcePaste">ts := TStringList.Create</div>
<div id="_mcePaste">ts.Delimter := &#8216;,&#8217;</div>
<div id="_mcePaste">ts.DelimtedText := s</div>
<div id="_mcePaste">//这时 ts里面就存放了 aa bb cc dd 这四个strings了. 你只要通过 ts[0]就可以取第一个数据</div>
<div id="_mcePaste">function SplitString(Source, Deli: string ): TStringList;stdcall;</div>
<div id="_mcePaste">var</div>
<div id="_mcePaste">EndOfCurrentString: byte;</div>
<div id="_mcePaste">StringList:TStringList;</div>
<div id="_mcePaste">begin</div>
<div id="_mcePaste">StringList:=TStringList.Create;</div>
<div id="_mcePaste">while Pos(Deli, Source)&gt;0 do</div>
<div id="_mcePaste">begin</div>
<div id="_mcePaste">EndOfCurrentString := Pos(Deli, Source);</div>
<div id="_mcePaste">StringList.add(Copy(Source, 1, EndOfCurrentString &#8211; 1));</div>
<div id="_mcePaste">Source := Copy(Source, EndOfCurrentString + length(Deli), length(Source) &#8211; EndOfCurrentString);</div>
<div id="_mcePaste">end;</div>
<div id="_mcePaste">Result := StringList;</div>
<div id="_mcePaste">StringList.Add(source);</div>
<div id="_mcePaste">end;</div>
<div id="_mcePaste">procedure StrToStrs(str:string;strs:tstrings);</div>
<div id="_mcePaste">var temp:string;</div>
<div id="_mcePaste">i:integer;</div>
<div id="_mcePaste">label B,E;</div>
<div id="_mcePaste">begin</div>
<div id="_mcePaste">B:</div>
<div id="_mcePaste">i:= ansipos(&#8216;|&#8217;,str);</div>
<div id="_mcePaste">if i=0 THEN GOTO E;</div>
<div id="_mcePaste">strs.Add(ansileftstr(str,i-1));</div>
<div id="_mcePaste">str:=ansirightstr(str,length(str)-i);</div>
<div id="_mcePaste">GOTO B;</div>
<div id="_mcePaste">E:</div>
<div id="_mcePaste">end;</div>
<div id="_mcePaste">Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=590744</div>
<div id="_mcePaste">TStringList的用法</div>
<div id="_mcePaste">TStrings是一个抽象类，在实际开发中，是除了基本类型外，应用得最多的。</div>
<div id="_mcePaste">常规的用法大家都知道，现在来讨论它的一些高级的用法。</div>
<div id="_mcePaste">先把要讨论的几个属性列出来：</div>
<div id="_mcePaste">1、CommaText</div>
<div id="_mcePaste">2、Delimiter &amp; DelimitedText</div>
<div id="_mcePaste">3、Names &amp; Values &amp; ValueFromIndex</div>
<div id="_mcePaste">先看第一个：CommaText。怎么用呢？用代码说话：</div>
<div id="_mcePaste">const</div>
<div id="_mcePaste">constr :String = &#8216;aaa,bbb,ccc,ddd&#8217;;</div>
<div id="_mcePaste">var</div>
<div id="_mcePaste">strs :TStrings;</div>
<div id="_mcePaste">i :Integer;</div>
<div id="_mcePaste">begin</div>
<div id="_mcePaste">strs := TStringList.Create;</div>
<div id="_mcePaste">strs.CommaText := constr;</div>
<div id="_mcePaste">for i := 0 to Strs.Count-1 do</div>
<div id="_mcePaste">ShowMessage(Strs[i]);</div>
<div id="_mcePaste">end;</div>
<div id="_mcePaste">执行了这段代码后，可以看到ShowMessage显示出来的分别是：aaa bbb ccc ddd。</div>
<div id="_mcePaste">也就是说，strs.CommaText := constr这一句的作用，就是把一个字符串以&#8217;,'为分割符，分段添加到TStrings中。</div>
<div id="_mcePaste">那么如果不是以&#8217;,'来分割，又该怎么做呢？现在看第二个例子。使用Delimiter和DelimitedText。</div>
<div id="_mcePaste">const</div>
<div id="_mcePaste">constr :String = &#8216;aaa\bbb\ccc\ddd&#8217;;</div>
<div id="_mcePaste">var</div>
<div id="_mcePaste">strs :TStrings;</div>
<div id="_mcePaste">i :Integer;</div>
<div id="_mcePaste">begin</div>
<div id="_mcePaste">strs := TStringList.Create;</div>
<div id="_mcePaste">strs.Delimiter := &#8216;\&#8217;;</div>
<div id="_mcePaste">strs.DelimitedText := constr;</div>
<div id="_mcePaste">for i := 0 to Strs.Count-1 do</div>
<div id="_mcePaste">ShowMessage(Strs[i]);</div>
<div id="_mcePaste">end;</div>
<div id="_mcePaste">可以看到， 显示的效果和第一个例子是一模一样的。解释一下：</div>
<div id="_mcePaste">Delimiter为分隔符，默认为：&#8217;,'。DelimitedText就是按Delimiter为分隔符的一个串，得到赋值后回把这个字符串按Delimiter的字符添加到TStrings中。</div>
<div id="_mcePaste">说到这里，有想起一个属性，QuoteChar。其默认值为：&#8217;&#8221;&#8216;（不包括单引号）</div>
<div id="_mcePaste">有何用呢？看例子：</div>
<div id="_mcePaste">const</div>
<div id="_mcePaste">constr :String = &#8216;&#8221;aaa&#8221;\&#8221;bbb&#8221;\&#8221;ccc&#8221;\&#8221;ddd&#8221;&#8216;;</div>
<div id="_mcePaste">var</div>
<div id="_mcePaste">strs :TStrings;</div>
<div id="_mcePaste">i :Integer;</div>
<div id="_mcePaste">begin</div>
<div id="_mcePaste">strs := TStringList.Create;</div>
<div id="_mcePaste">strs.Delimiter := &#8216;\&#8217;;</div>
<div id="_mcePaste">strs.DelimitedText := constr;</div>
<div id="_mcePaste">for i := 0 to Strs.Count-1 do</div>
<div id="_mcePaste">ShowMessage(Strs[i]);</div>
<div id="_mcePaste">end;</div>
<div id="_mcePaste">显示出来的仍然是aaa bbb ccc ddd。为什么不是：&#8221;aaa&#8221; &#8220;bbb&#8221; &#8220;ccc&#8221; &#8220;ddd&#8221;呢？</div>
<div id="_mcePaste">再来看一个例子：</div>
<div id="_mcePaste">const</div>
<div id="_mcePaste">constr :String = &#8216;|aaa|\|bbb|\|ccc|\|ddd|&#8217;;</div>
<div id="_mcePaste">var</div>
<div id="_mcePaste">strs :TStrings;</div>
<div id="_mcePaste">i :Integer;</div>
<div id="_mcePaste">begin</div>
<div id="_mcePaste">strs := TStringList.Create;</div>
<div id="_mcePaste">strs.Delimiter := &#8216;\&#8217;;</div>
<div id="_mcePaste">strs.QuoteChar := &#8216;|&#8217;;</div>
<div id="_mcePaste">strs.DelimitedText := constr;</div>
<div id="_mcePaste">for i := 0 to Strs.Count-1 do</div>
<div id="_mcePaste">ShowMessage(Strs[i]);</div>
<div id="_mcePaste">end;</div>
<div id="_mcePaste">显示出来的又是aaa bbb ccc ddd。对比一下，应该不难明白吧？这个就不多说了，用得也不多。</div>
<div id="_mcePaste">但是还要多说一句，当Delimiter为：&#8217;,'而QuoteChar为：&#8217;&#8221;&#8216;时，DelimitedText和CommaText是同等的。</div>
<div id="_mcePaste">最后要说的三个是：Names &amp; Values &amp; ValueFromIndex。</div>
<div id="_mcePaste">看看下面的代码：</div>
<div id="_mcePaste">const</div>
<div id="_mcePaste">constr :String = &#8216;0=aaa,1=bbb,2=ccc,3=ddd&#8217;;</div>
<div id="_mcePaste">var</div>
<div id="_mcePaste">strs :TStrings;</div>
<div id="_mcePaste">i :Integer;</div>
<div id="_mcePaste">begin</div>
<div id="_mcePaste">strs := TStringList.Create;</div>
<div id="_mcePaste">strs.CommaText := constr;</div>
<div id="_mcePaste">for i := 0 to strs.Count-1 do</div>
<div id="_mcePaste">begin</div>
<div id="_mcePaste">ShowMessage(strs.Names[i]);</div>
<div id="_mcePaste">ShowMessage(strs.Values[strs.Names[i]]);</div>
<div id="_mcePaste">ShowMessage(strs.ValueFromIndex[i]);</div>
<div id="_mcePaste">end;</div>
<div id="_mcePaste">end;</div>
<div id="_mcePaste">通过这个例子不难看出：</div>
<div id="_mcePaste">这个时候strs中的内容是：</div>
<div id="_mcePaste">0=aaa</div>
<div id="_mcePaste">1=bbb</div>
<div id="_mcePaste">2=ccc</div>
<div id="_mcePaste">3=ddd</div>
<div id="_mcePaste">而Names中则是：</div>
<div id="_mcePaste">0</div>
<div id="_mcePaste">1</div>
<div id="_mcePaste">2</div>
<div id="_mcePaste">3</div>
<div id="_mcePaste">在Values中则是：</div>
<div id="_mcePaste">aaa</div>
<div id="_mcePaste">bbb</div>
<div id="_mcePaste">ccc</div>
<div id="_mcePaste">ddd</div>
</div>
<p></span></div>
]]></content:encoded>
			<wfw:commentRss>http://wenjinjin.com/code_document/delphi_doc/delphi_string_split.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>delphi运算符列表</title>
		<link>http://wenjinjin.com/code_document/delphi_doc/delphi_operator.html</link>
		<comments>http://wenjinjin.com/code_document/delphi_doc/delphi_operator.html#comments</comments>
		<pubDate>Thu, 08 Jul 2010 14:42:01 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DELPHI文档]]></category>
		<category><![CDATA[operator]]></category>
		<category><![CDATA[运算符]]></category>

		<guid isPermaLink="false">http://wenjinjin.com/?p=135</guid>
		<description><![CDATA[







分类
运算符
操作
操作数
结果类型
范例


算术运算符
+
加
整数，实数
整数，实数
X + Y


-
减
整数，实数
整数，实数
Result &#8211; 1


*
乘
整数，实数
整数，实数
P * InterestRate


/
实数除
整数，实数
实数
X / 2


div
整数除
整数
整数
Total div UnitSize


mod
取模
整数
整数
Y mod 6


+(一元)
符号等同
整数，实数
整数，实数
+7


-(一元)
符号相反
整数，实数
整数，实数
-X


布尔运算符
not
否定
布尔型
Boolean
not (C in MySet)


and
与
布尔型
Boolean
Done and (Total &#62; 0)


or
或
布尔型
Boolean
A or B


xor
异或
布尔型
Boolean
A xor B


逻辑(按位)运算符
not
按位否定
整数
整数
not X


and
按位与
整数
整数
X and Y


or
按位或
整数
整数
X or Y


xor
按位异或
整数
整数
X xor Y


shl
按位左移
整数
整数
X shl 2


shr
按位右移
整数
整数
Y shr I


字符串运算符
+
连接
字符串、压缩串、字符
字符串
S + &#8216;.&#8217;


指针运算符
+
指针加
字符指针，整数
字符指针
P + I


-
指针减
字符指针，整数
字符指针，整数
P &#8211; Q


^
指针解除参照
指针
指针的基类型
P^


=
相等
指针
Boolean
P = Q


&#60;&#62;
不等
指针
Boolean
P &#60;&#62; Q


集合运算符
+
并集
集合
集合
Set1 + Set2


-
差集
集合
集合
S – T


*
交集
集合
集合
S * T


&#60;=
子集
集合
Boolean
Q &#60;= MySet


&#62;=
超集
集合
Boolean
S1 &#62;= S2


=
相等
集合
Boolean
S2 [...]]]></description>
			<content:encoded><![CDATA[<table>
<tbody>
<tr>
<td>
<div>
<table border="1" cellspacing="1">
<tbody>
<tr>
<th>分类</th>
<th>运算符</th>
<th>操作</th>
<th>操作数</th>
<th>结果类型</th>
<th>范例</th>
</tr>
<tr>
<td rowspan="8">算术运算符</td>
<td>+</td>
<td>加</td>
<td>整数，实数</td>
<td>整数，实数</td>
<td>X + Y</td>
</tr>
<tr>
<td>-</td>
<td>减</td>
<td>整数，实数</td>
<td>整数，实数</td>
<td>Result &#8211; 1</td>
</tr>
<tr>
<td>*</td>
<td>乘</td>
<td>整数，实数</td>
<td>整数，实数</td>
<td>P * InterestRate</td>
</tr>
<tr>
<td>/</td>
<td>实数除</td>
<td>整数，实数</td>
<td>实数</td>
<td>X / 2</td>
</tr>
<tr>
<td>div</td>
<td>整数除</td>
<td>整数</td>
<td>整数</td>
<td>Total div UnitSize</td>
</tr>
<tr>
<td>mod</td>
<td>取模</td>
<td>整数</td>
<td>整数</td>
<td>Y mod 6</td>
</tr>
<tr>
<td>+(一元)</td>
<td>符号等同</td>
<td>整数，实数</td>
<td>整数，实数</td>
<td>+7</td>
</tr>
<tr>
<td>-(一元)</td>
<td>符号相反</td>
<td>整数，实数</td>
<td>整数，实数</td>
<td>-X</td>
</tr>
<tr>
<td rowspan="4">布尔运算符</td>
<td>not</td>
<td>否定</td>
<td>布尔型</td>
<td>Boolean</td>
<td>not (C in MySet)</td>
</tr>
<tr>
<td>and</td>
<td>与</td>
<td>布尔型</td>
<td>Boolean</td>
<td>Done and (Total &gt; 0)</td>
</tr>
<tr>
<td>or</td>
<td>或</td>
<td>布尔型</td>
<td>Boolean</td>
<td>A or B</td>
</tr>
<tr>
<td>xor</td>
<td>异或</td>
<td>布尔型</td>
<td>Boolean</td>
<td>A xor B</td>
</tr>
<tr>
<td rowspan="6">逻辑(按位)运算符</td>
<td>not</td>
<td>按位否定</td>
<td>整数</td>
<td>整数</td>
<td>not X</td>
</tr>
<tr>
<td>and</td>
<td>按位与</td>
<td>整数</td>
<td>整数</td>
<td>X and Y</td>
</tr>
<tr>
<td>or</td>
<td>按位或</td>
<td>整数</td>
<td>整数</td>
<td>X or Y</td>
</tr>
<tr>
<td>xor</td>
<td>按位异或</td>
<td>整数</td>
<td>整数</td>
<td>X xor Y</td>
</tr>
<tr>
<td>shl</td>
<td>按位左移</td>
<td>整数</td>
<td>整数</td>
<td>X shl 2</td>
</tr>
<tr>
<td>shr</td>
<td>按位右移</td>
<td>整数</td>
<td>整数</td>
<td>Y shr I</td>
</tr>
<tr>
<td>字符串运算符</td>
<td>+</td>
<td>连接</td>
<td>字符串、压缩串、字符</td>
<td>字符串</td>
<td>S + &#8216;.&#8217;</td>
</tr>
<tr>
<td rowspan="5">指针运算符</td>
<td>+</td>
<td>指针加</td>
<td>字符指针，整数</td>
<td>字符指针</td>
<td>P + I</td>
</tr>
<tr>
<td>-</td>
<td>指针减</td>
<td>字符指针，整数</td>
<td>字符指针，整数</td>
<td>P &#8211; Q</td>
</tr>
<tr>
<td>^</td>
<td>指针解除参照</td>
<td>指针</td>
<td>指针的基类型</td>
<td>P^</td>
</tr>
<tr>
<td>=</td>
<td>相等</td>
<td>指针</td>
<td>Boolean</td>
<td>P = Q</td>
</tr>
<tr>
<td>&lt;&gt;</td>
<td>不等</td>
<td>指针</td>
<td>Boolean</td>
<td>P &lt;&gt; Q</td>
</tr>
<tr>
<td rowspan="8">集合运算符</td>
<td>+</td>
<td>并集</td>
<td>集合</td>
<td>集合</td>
<td>Set1 + Set2</td>
</tr>
<tr>
<td>-</td>
<td>差集</td>
<td>集合</td>
<td>集合</td>
<td>S – T</td>
</tr>
<tr>
<td>*</td>
<td>交集</td>
<td>集合</td>
<td>集合</td>
<td>S * T</td>
</tr>
<tr>
<td>&lt;=</td>
<td>子集</td>
<td>集合</td>
<td>Boolean</td>
<td>Q &lt;= MySet</td>
</tr>
<tr>
<td>&gt;=</td>
<td>超集</td>
<td>集合</td>
<td>Boolean</td>
<td>S1 &gt;= S2</td>
</tr>
<tr>
<td>=</td>
<td>相等</td>
<td>集合</td>
<td>Boolean</td>
<td>S2 = MySet</td>
</tr>
<tr>
<td>&lt;&gt;</td>
<td>不等</td>
<td>集合</td>
<td>Boolean</td>
<td>MySet &lt;&gt; S1</td>
</tr>
<tr>
<td>in</td>
<td>成员</td>
<td>序数，集合</td>
<td>Boolean</td>
<td>A in Set1</td>
</tr>
<tr>
<td rowspan="6">关系运算符</td>
<td>=</td>
<td>相等</td>
<td>简单类型、类、类引用、接口、串、压缩串</td>
<td>Boolean</td>
<td>I = Max</td>
</tr>
<tr>
<td>&lt;&gt;</td>
<td>不等</td>
<td>简单类型、类、类引用、接口、串、压缩串</td>
<td>Boolean</td>
<td>X &lt;&gt; Y</td>
</tr>
<tr>
<td>&lt;</td>
<td>小于</td>
<td>简单类型、串、压缩串、PChar</td>
<td>Boolean</td>
<td>X &lt; Y</td>
</tr>
<tr>
<td>&gt;</td>
<td>大于</td>
<td>简单类型、串、压缩串、PChar</td>
<td>Boolean</td>
<td>Len &gt; 0</td>
</tr>
<tr>
<td>&lt;=</td>
<td>小于或等于</td>
<td>简单类型、串、压缩串、PChar</td>
<td>Boolean</td>
<td>Cnt &lt;= 1</td>
</tr>
<tr>
<td>&gt;=</td>
<td>大于或等于</td>
<td>简单类型、串、压缩串、PChar</td>
<td>Boolean</td>
<td>I &gt;= 1</td>
</tr>
<tr>
<td rowspan="4">类运算符</td>
<td>as</td>
<td>转换</td>
<td rowspan="2">类和类的实例</td>
<td></td>
<td></td>
</tr>
<tr>
<td>is</td>
<td>判断</td>
<td></td>
<td></td>
</tr>
<tr>
<td>=</td>
<td></td>
<td rowspan="2">关系运算符 = 和 &lt;&gt; 也作用于类</td>
<td></td>
<td></td>
</tr>
<tr>
<td>&lt;&gt;</td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td rowspan="3">地址(@)运算符</td>
<td>@X</td>
<td colspan="4">如果X是一个变量，那么@X返回X的地址。当编译指示 {$T-} 有效时，@X是Pointer类型; 而在编译指示 {$T+} 状态下时，@X是 ^T 类型，这里的T是X的类型。</td>
</tr>
<tr>
<td>@F</td>
<td colspan="4">如果 F 是一个例程(函数或过程)，那么@F返回 F 的入口点，@F的类型总是Pointer。</td>
</tr>
<tr>
<td>@类中方法</td>
<td colspan="4">当 @ 适用于定义在类中的方法时，方法标识符必需被类的名称限定。例如: @TMyClass.DoSomething</td>
</tr>
</tbody>
</table>
</div>
</td>
</tr>
</tbody>
</table>
]]></content:encoded>
			<wfw:commentRss>http://wenjinjin.com/code_document/delphi_doc/delphi_operator.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Delphi2010组件/控件安装方法</title>
		<link>http://wenjinjin.com/code_document/delphi_doc/delphi2010_add_module.html</link>
		<comments>http://wenjinjin.com/code_document/delphi_doc/delphi2010_add_module.html#comments</comments>
		<pubDate>Thu, 08 Jul 2010 14:37:20 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DELPHI文档]]></category>
		<category><![CDATA[delphi2010]]></category>
		<category><![CDATA[控件]]></category>
		<category><![CDATA[组件]]></category>

		<guid isPermaLink="false">http://wenjinjin.com/?p=131</guid>
		<description><![CDATA[delphi 有很多组件可以用，下面介绍一下 在delphi2010中 添加组件的方法。
 
 
 

在D2010IDE，初学者大都能够安装.Net控件，但VCL控件如何安装？大都茫然！下面就来力求详尽地回答这一问题。
首先注意到Delphi2010的组件/控件安装，只支持BPL文件。所以，不管是pas文件、dpk文件或ocx文件类的组件或控件，都需要将其;变成bpl包文件。
1. BPL类，直接安装：确认你的BPL所丰文件夹后，点击“Cpmponent-Install Packages-Add&#8230;&#8230;”即可完成安装；
2. 源码类：即Pas文件：需要新建BPL文件，再按步骤1进行安装。方法如下：点击“File-New-Package-Delphi”新建一个Package文件，并起名保存(别忘记保存在哪里哈！)，点击“Project-Add to Project&#8230;”，将组件源码添加进来，然后在“project manager”里选择包文件，并点击右键选择“install”就行了。别忘记“Close All”退出时一定要保存包文件，否则下次启动时会找不到包了。
3. ActiveX类控件：通常为OCX文件，如“并行口访问控件”(http://bbs.2ccc.com/topic.asp?topicid=344133&#8243;&#62; )，安装原则是，先将其编译成pas文件，再按照方法2安装。方法：点击“Cpmponent-Import Component&#8230;”，在对话框中选择“Import ActiveX Control”，点击Next，弹出对话框，此时有两种可能，若控件未注册，请选择Add；若控件已注册(通常在“运行&#8230;”处用“RegSvr32”命令来注册控件)，则直接从列表中选择你要安装的控件(如上述的hwiInterface ActiveX Control module)，然后点击Next；在弹出对话框中，要记住其中“Unit Dir Name”里面的路径名，它表示你在此保存的了pas文件；再点击Next，选中“Create Unit”即可生成pas文件，然后按照步骤2完成控件安装。
4. dpk类： 在IDE的file-open打开DPK文件；在project manager窗口点击右键，并选择“Build”,可生成BPL；然后按照步骤1完成控件安装；或者选择“Install”直接安装控件。

在D2010IDE，初学者大都能够安装.Net控件，但VCL控件如何安装？大都茫然！下面就来力求详尽地回答这一问题。
首先注意到Delphi2010的组件/控件安装，只支持BPL文件。所以，不管是pas文件、dpk文件或ocx文件类的组件或控件，都需要将其;变成bpl包文件。
1. BPL类，直接安装：确认你的BPL所丰文件夹后，点击“Cpmponent-Install Packages-Add&#8230;&#8230;”即可完成安装；
2. 源码类：即Pas文件：需要新建BPL文件，再按步骤1进行安装。方法如下：点击“File-New-Package-Delphi”新建一个Package文件，并起名保存(别忘记保存在哪里哈！)，点击“Project-Add to Project&#8230;”，将组件源码添加进来，然后在“project manager”里选择包文件，并点击右键选择“install”就行了。别忘记“Close All”退出时一定要保存包文件，否则下次启动时会找不到包了。
3. ActiveX类控件：通常为OCX文件，如“并行口访问控件”(http://bbs.2ccc.com/topic.asp?topicid=344133&#8243;&#62;&#60;span )，安装原则是，先将其编译成pas文件，再按照方法2安装。方法：点击“Cpmponent-Import Component&#8230;”，在对话框中选择“Import ActiveX Control”，点击Next，弹出对话框，此时有两种可能，若控件未注册，请选择Add；若控件已注册(通常在“运行&#8230;”处用“RegSvr32”命令来注册控件)，则直接从列表中选择你要安装的控件(如上述的hwiInterface ActiveX Control module)，然后点击Next；在弹出对话框中，要记住其中“Unit Dir Name”里面的路径名，它表示你在此保存的了pas文件；再点击Next，选中“Create Unit”即可生成pas文件，然后按照步骤2完成控件安装。
4. dpk类： 在IDE的file-open打开DPK文件；在project manager窗口点击右键，并选择“Build”,可生成BPL；然后按照步骤1完成控件安装；或者选择“Install”直接安装控件。
文章来源：http://www.51xuewen.com/group/2035/topic_17525.htm
]]></description>
			<content:encoded><![CDATA[<p><strong>delphi 有很多组件可以用，下面介绍一下 在delphi2010中 添加组件的方法。</strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong></p>
<div id="_mcePaste"><span style="font-weight: normal;">在D2010IDE，初学者大都能够安装.Net控件，但VCL控件如何安装？大都茫然！下面就来力求详尽地回答这一问题。</span></div>
<div id="_mcePaste"><span style="font-weight: normal;">首先注意到Delphi2010的组件/控件安装，只支持BPL文件。所以，不管是pas文件、dpk文件或ocx文件类的组件或控件，都需要将其;变成bpl包文件。</span></div>
<div id="_mcePaste"><span style="font-weight: normal;">1. BPL类，直接安装：确认你的BPL所丰文件夹后，点击“Cpmponent-Install Packages-Add&#8230;&#8230;”即可完成安装；</span></div>
<div id="_mcePaste"><span style="font-weight: normal;">2. 源码类：即Pas文件：需要新建BPL文件，再按步骤1进行安装。方法如下：点击“File-New-Package-Delphi”新建一个Package文件，并起名保存(别忘记保存在哪里哈！)，点击“Project-Add to Project&#8230;”，将组件源码添加进来，然后在“project manager”里选择包文件，并点击右键选择“install”就行了。别忘记“Close All”退出时一定要保存包文件，否则下次启动时会找不到包了。</span></div>
<div id="_mcePaste"><span style="font-weight: normal;">3. ActiveX类控件：通常为OCX文件，如“并行口访问控件”(http://bbs.2ccc.com/topic.asp?topicid=344133&#8243;&gt; )，安装原则是，先将其编译成pas文件，再按照方法2安装。方法：点击“Cpmponent-Import Component&#8230;”，在对话框中选择“Import ActiveX Control”，点击Next，弹出对话框，此时有两种可能，若控件未注册，请选择Add；若控件已注册(通常在“运行&#8230;”处用“RegSvr32”命令来注册控件)，则直接从列表中选择你要安装的控件(如上述的hwiInterface ActiveX Control module)，然后点击Next；在弹出对话框中，要记住其中“Unit Dir Name”里面的路径名，它表示你在此保存的了pas文件；再点击Next，选中“Create Unit”即可生成pas文件，然后按照步骤2完成控件安装。</span></div>
<div id="_mcePaste"><span style="font-weight: normal;">4. dpk类： 在IDE的file-open打开DPK文件；在project manager窗口点击右键，并选择“Build”,可生成BPL；然后按照步骤1完成控件安装；或者选择“Install”直接安装控件。</span></div>
<p></strong></p>
<p><span style="font-weight: normal;">在D2010IDE，初学者大都能够安装.Net控件，但VCL控件如何安装？大都茫然！下面就来力求详尽地回答这一问题。<br />
首先注意到Delphi2010的组件/控件安装，只支持BPL文件。所以，不管是pas文件、dpk文件或ocx文件类的组件或控件，都需要将其;变成bpl包文件。<br />
1. BPL类，直接安装：确认你的BPL所丰文件夹后，点击“Cpmponent-Install Packages-Add&#8230;&#8230;”即可完成安装；<br />
2. 源码类：即Pas文件：需要新建BPL文件，再按步骤1进行安装。方法如下：点击“File-New-Package-Delphi”新建一个Package文件，并起名保存(别忘记保存在哪里哈！)，点击“Project-Add to Project&#8230;”，将组件源码添加进来，然后在“project manager”里选择包文件，并点击右键选择“install”就行了。别忘记“Close All”退出时一定要保存包文件，否则下次启动时会找不到包了。<br />
3. ActiveX类控件：通常为OCX文件，如“并行口访问控件”(http://bbs.2ccc.com/topic.asp?topicid=344133&#8243;&gt;&lt;span )，安装原则是，先将其编译成pas文件，再按照方法2安装。方法：点击“Cpmponent-Import Component&#8230;”，在对话框中选择“Import ActiveX Control”，点击Next，弹出对话框，此时有两种可能，若控件未注册，请选择Add；若控件已注册(通常在“运行&#8230;”处用“RegSvr32”命令来注册控件)，则直接从列表中选择你要安装的控件(如上述的hwiInterface ActiveX Control module)，然后点击Next；在弹出对话框中，要记住其中“Unit Dir Name”里面的路径名，它表示你在此保存的了pas文件；再点击Next，选中“Create Unit”即可生成pas文件，然后按照步骤2完成控件安装。<br />
4. dpk类： 在IDE的file-open打开DPK文件；在project manager窗口点击右键，并选择“Build”,可生成BPL；然后按照步骤1完成控件安装；或者选择“Install”直接安装控件。</span></p>
<p>文章来源：http://www.51xuewen.com/group/2035/topic_17525.htm</p>
]]></content:encoded>
			<wfw:commentRss>http://wenjinjin.com/code_document/delphi_doc/delphi2010_add_module.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>系统托盘的实现</title>
		<link>http://wenjinjin.com/code_document/delphi_doc/delphi_notifyicon.html</link>
		<comments>http://wenjinjin.com/code_document/delphi_doc/delphi_notifyicon.html#comments</comments>
		<pubDate>Wed, 07 Jul 2010 16:04:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DELPHI文档]]></category>
		<category><![CDATA[系统托盘]]></category>

		<guid isPermaLink="false">http://wenjinjin.com/?p=122</guid>
		<description><![CDATA[主要代码
const
IconMessage = WM_USER+1;
ICON_ID=0;
type
PNewNotifyIconData = ^TNewNotifyIconData;
TDUMMYUNIONNAME = Record
case Integer of
0: (uTimeout: UINT);
1: (uVersion: UINT);
end;
TNewNotifyIconData = Record
cbSize: DWORD;
Wnd: HWND;
uID: UINT;
uFlags: UINT;
uCallbackMessage: UINT;
hIcon: HICON;
szTip: array [0..127] of Char;    //Version 5.0为128个，以前为64个
dwState: DWORD;    //Version 5.0
dwStateMask: DWORD;    //Version 5.0
szInfo: array [0..255] of Char;   //Version 5.0
DUMMYUNIONNAME: TDUMMYUNIONNAME;
szInfoTitle: array [0..63] of Char;   //Version 5.0
dwInfoFlags: DWORD;   //Version 5.0
end;
Var
IconData: [...]]]></description>
			<content:encoded><![CDATA[<p>主要代码</p>
<p>const</p>
<p>IconMessage = WM_USER+1;</p>
<p>ICON_ID=0;</p>
<p>type</p>
<p>PNewNotifyIconData = ^TNewNotifyIconData;</p>
<p>TDUMMYUNIONNAME = Record</p>
<p>case Integer of</p>
<p>0: (uTimeout: UINT);</p>
<p>1: (uVersion: UINT);</p>
<p>end;</p>
<p>TNewNotifyIconData = Record</p>
<p>cbSize: DWORD;</p>
<p>Wnd: HWND;</p>
<p>uID: UINT;</p>
<p>uFlags: UINT;</p>
<p>uCallbackMessage: UINT;</p>
<p>hIcon: HICON;</p>
<p>szTip: array [0..127] of Char;    //Version 5.0为128个，以前为64个</p>
<p>dwState: DWORD;    //Version 5.0</p>
<p>dwStateMask: DWORD;    //Version 5.0</p>
<p>szInfo: array [0..255] of Char;   //Version 5.0</p>
<p>DUMMYUNIONNAME: TDUMMYUNIONNAME;</p>
<p>szInfoTitle: array [0..63] of Char;   //Version 5.0</p>
<p>dwInfoFlags: DWORD;   //Version 5.0</p>
<p>end;</p>
<p>Var<br />
IconData: TNewNotifyIconData;</p>
<p>// 添加图标</p>
<div id="_mcePaste">begin<br />
IconData.cbSize:=sizeof(IconData);</div>
<div id="_mcePaste">IconData.Wnd:=self.Handle;</div>
<div id="_mcePaste">IconData.uID:= ICON_ID;</div>
<div id="_mcePaste">IconData.hIcon:=Application.Icon.Handle;</div>
<div id="_mcePaste">IconData.uCallbackMessage:=IconMessage;</div>
<div id="_mcePaste">IconData.uFlags:= NIF_MESSAGE   or   NIF_ICON   or   NIF_TIP or NIF_INFO;</div>
<div id="_mcePaste">IconData.szTip:=&#8217;托盘图标&#8217;;<br />
IconData.cbSize:=sizeof(IconData);    IconData.Wnd:=self.Handle;    IconData.uID:= ICON_ID;    IconData.hIcon:=Application.Icon.Handle;    IconData.uCallbackMessage:=IconMessage;<br />
IconData.uFlags:= NIF_MESSAGE   or   NIF_ICON   or   NIF_TIP or NIF_INFO;    IconData.szTip:=&#8217;托盘图标&#8217;;</div>
<div>//显示气球提示</div>
<div>
<div>strPLCopy(IconData.szInfo,&#8217;托盘图标已经启动&#8217;, sizeof(IconData.szInfo) &#8211; 1);</div>
<div>IconData.DUMMYUNIONNAME.uTimeout := 3000;</div>
<div>strPLCopy(IconData.szInfoTitle, 托盘图标, sizeof(IconData.szInfoTitle) &#8211; 1);</div>
<div>IconData.dwInfoFlags := NIIF_INFO;</div>
<div>Shell_NotifyIcon(NIM_MODIFY, @IconData);</div>
</div>
<div>Shell_notifyIcon(NIM_ADD,@IconData);//添加托盘图标</div>
<div>end</div>
<div>//删除图标</div>
<div>
<div>IconData.cbSize:=SizeOf(IconData);</div>
<div>IconData.Wnd:=winHandle;</div>
<div>IconData.uID:=ICON_ID;</div>
<div>Shell_NotifyIcon(NIM_DELETE,@IconData);</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://wenjinjin.com/code_document/delphi_doc/delphi_notifyicon.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>delphi之如何快速开发原生ActiveX控件</title>
		<link>http://wenjinjin.com/code_document/delphi_doc/delphi_activex.html</link>
		<comments>http://wenjinjin.com/code_document/delphi_doc/delphi_activex.html#comments</comments>
		<pubDate>Wed, 07 Jul 2010 15:49:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DELPHI文档]]></category>
		<category><![CDATA[ActiveX]]></category>

		<guid isPermaLink="false">http://wenjinjin.com/?p=105</guid>
		<description><![CDATA[
ActiveX技术虽然是一项古老的技术，但是却有着广泛的应用，支付宝
的密码输入控件，各大银行的密码输入控件，网页聊天室中的截屏功能，网页播放器中的p2p播放&#8230;甚至Flash ,Silverlight等等，在IE中都表现为ActiveX。虽然c#也能开发&#8221;用于网页的com应用&#8221;，能达到类似ActiveX的效果，但是有一个要命的问题是必须得安装几百M的.net framework框架，如果仅仅为了安全的输入一个密码，而要用户下载几百M的安装程序，这是很多人不能接受的，delphi做为win32下的原生开发工具，能很好的支持微软各种&#8221;古老&#8221;的经典技术。(再做点小广告:delphi的kyrix版本还能编译跨平台的应用哦！)


ok，开工吧:
开发工具:推荐用delphi 2010(d7也可以，不过添加属性，方法等过程要手动，稍微麻烦点)
1.启用delphi2010&#8211;&#62;File-&#62;New-&#62;Other&#8211;&#62;Active Library


2.项目命名为MyActiveX



 3.File&#8211;&#62;Save All 全部保存




实际上这样就能编译了，不过只是空的dll
 4.File&#8211;&#62;New&#8211;&#62;Other&#8211;&#62;Active Form

 
 改名为MyForm



 将对应的单元文件，保存为UMyForm.pas
 5.打开MyAcitveX.ridl文件，切换到design视图，选中IMyForm接口，右击New&#8211;&#62;Property 添加一个属性Msg

 

 将Msg属性的Type改为BSTR 即WideString类型





 完了之后，点击工具栏中的Refresh Implementation(即上图中工具栏中圈起来的部分)&#8211;这一步很重要，点击之后，它将自动生成属性Msg对应的声明和实现代码模板
 6.打开UMyForm.pas&#8211;即ActiveForm对应的单元，找到Set_Msg以及Get_Msg的实现部分，补充代码如下:
function　TMyForm.Get_Msg:　WideString;
begin
result:=_msg;
end;
procedure　TMyForm.Set_Msg(const　Value:　WideString);
begin
_msg　:=　value;
end;
 当然TMyForm的private部分，得先加一个私有成员 
type
TMyForm　=　class(TActiveForm,　IMyForm)
private
{　Private　declarations　}
_msg:WideString;
...
 这样我们就为即将生成的ActiveX控件，添加了一个字符串类型的属性Msg，下面来测试一下:
 7.编译项目，会生成一个MyActiveX.ocx，在运行栏里输入
 regsvr32 C:\Users\jimmy.yang\Desktop\delphi_activex\MyActiveX\MyActiveX.ocx
 注:这里ocx的路径，请各位根据自己的实际路径修改
 这样就完成了ocx的注册。
 8.放到html里测试一下：
&#60;OBJECT　ID='x'　name='x'　CLASSID='CLSID:52D17094-0687-4A2F-B2DB-30F3189AC659'　align=center　hspace=0　vspace=0　&#62;&#60;/OBJECT&#62;
&#60;script　type='text/javascript'&#62;
var　x　=　document.getElementById("x");
alert(x.Msg);
&#60;/script&#62;
 关于CLSID在哪里查看，打开:MyActiveX_TLB.pas文件，定位到下面这里:
const
//　TypeLibrary　Major　and　minor　versions
MyActiveXMajorVersion　=　1;
MyActiveXMinorVersion　=　0;
LIBID_MyActiveX:　TGUID　=　'{49138437-8265-4B1A-9EAE-D0F615D68464}';
IID_IMyForm:　TGUID　=　'{54A20855-29A3-4C92-85DE-A419DA457C7A}';
DIID_IMyFormEvents:　TGUID　=　'{60BBC967-E1E6-4E98-BAE5-776BFD06E9CC}';
CLASS_MyForm:　TGUID　=　'{52D17094-0687-4A2F-B2DB-30F3189AC659}';


 其中 CLASS_MyForm: TGUID对应的就是ClassID
 运行后，除了弹出一个空白的警告框，暂时看不到其它:)（可不就是这样么？Msg属性没给任何初始值，当然是空字符串，所以弹出一个空的警告框是正常的)
 9.我们再来添加一些控件和方法，以验证刚才设置的属性确实有效
 在MyForm上添加一个文件框，一个按钮
 

 按钮的事件如下:
procedure　TMyForm.Button1Click(Sender:　TObject);
begin
_msg:=　self.Edit1.Text;
end;
 即把文本框的值赋给属性Msg
 再继续定位到Set_Msg,略做修改
procedure　TMyForm.Set_Msg(const　Value:　WideString);
begin
_msg　:=　value;
self.Edit1.Text　:=　_msg;
end;
 即设置Msg属性时，同时也把值显示在文本框里，以便等会儿我们好测试在js中给activeX属性赋值的效果
 ok了，再来测试一下，编译一下，如果通不过，请先运行
 regsvr32 C:\Users\jimmy.yang\Desktop\delphi_activex\MyActiveX\MyActiveX.ocx /u
 将刚才注册的ocx反注册，同时关掉浏览器，不然该ocx文件一直被占用，无法更新.
 修改一下html的代码:
&#60;OBJECT　ID='x'　name='x'　CLASSID='CLSID:52D17094-0687-4A2F-B2DB-30F3189AC659'　align=center　hspace=0　vspace=0　&#62;&#60;/OBJECT&#62;
&#60;hr　/&#62;
&#60;input　type='button'　value='显示Msg属性的值'　onclick='ShowMsg()'/&#62;
&#60;input　type='button'　value='设置Msg属性的值'　onclick='SetMsg()'/&#62;
&#60;script　type='text/javascript'&#62;
var　x　=　document.getElementById("x");
var　ShowMsg　=　function(){
alert(x.Msg);
}
var　SetMsg　=　function(){
x.Msg　=　'js传过来的值';
}
&#60;/script&#62;

运行效果:



 10.添加Method
 我们已经知道了如何给ActiveX添加对外公开的属性，但是光有属性显然不够，我们再添加一个Method，参考第5步中的截图，选择new&#8211;&#62;Method,添加
 一个方法,命名为ShowMsg，Return参数项用默认值HRESULT，然后Parameters添加一个参数，如下图:



 同样不要忘记了点击工具栏中的更新按钮,再打开UMyForm.pas，会发现自动添加了一个过程的定义:
 procedure　ShowMsg(const　p:　WideString);　safecall;
 转到它的实现部分，写几行测试代码:
procedure　TMyForm.ShowMsg(const　p:　WideString);
begin
showmessage('Msg属性的值为：'　+　_msg　+　#13　+　'传入的参数为：'　+　p);
end;
 再编译，html代码中添加一些代码:
&#60;OBJECT　ID='x'　name='x'　CLASSID='CLSID:52D17094-0687-4A2F-B2DB-30F3189AC659'　align=center　hspace=0　vspace=0　&#62;&#60;/OBJECT&#62;
&#60;hr　/&#62;
&#60;input　type='button'　value='显示Msg属性的值'　onclick='ShowMsg()'/&#62;
&#60;input　type='button'　value='设置Msg属性的值'　onclick='SetMsg()'/&#62;
&#60;input　type='button'　value='调用ShowMsg方法'　onclick='CallShowMsg()'/&#62;
&#60;script　type='text/javascript'&#62;
var　x　=　document.getElementById("x");
var　ShowMsg　=　function(){
alert(x.Msg);
}
var　SetMsg　=　function(){
x.Msg　=　'js传过来的值';
}
var　CallShowMsg　=　function(){
x.ShowMsg('这是js传过来的参数');
}
&#60;/script&#62;



 [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">
<div id="_mcePaste">ActiveX技术虽然是一项古老的技术，但是却有着广泛的应用，支付宝</div>
<div id="_mcePaste">的密码输入控件，各大银行的密码输入控件，网页聊天室中的截屏功能，网页播放器中的p2p播放&#8230;甚至Flash ,Silverlight等等，在IE中都表现为ActiveX。虽然c#也能开发&#8221;用于网页的com应用&#8221;，能达到类似ActiveX的效果，但是有一个要命的问题是必须得安装几百M的.net framework框架，如果仅仅为了安全的输入一个密码，而要用户下载几百M的安装程序，这是很多人不能接受的，delphi做为win32下的原生开发工具，能很好的支持微软各种&#8221;古老&#8221;的经典技术。(再做点小广告:delphi的kyrix版本还能编译跨平台的应用哦！)</div>
</div>
<div>
<div>ok，开工吧:</div>
<div>开发工具:推荐用delphi 2010(d7也可以，不过添加属性，方法等过程要手动，稍微麻烦点)</div>
<div>1.启用delphi2010&#8211;&gt;File-&gt;New-&gt;Other&#8211;&gt;Active Library</div>
</div>
<p><img class="aligncenter size-full wp-image-106" title="1" src="http://wenjinjin.com/wp-content/uploads/2010/07/1.png" alt="" width="551" height="415" /></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;">2.项目命名为MyActiveX</span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/EvernoteCopyBuffer/fddcc564-bad0-4bd5-bbe8-6434ee9af959.png" alt="" /></span></span></p>
<p><span style="font-family: Simsun;"><span style="line-height: normal; font-size: small;"><a href="http://wenjinjin.com/wp-content/uploads/2010/07/2.png"><img class="aligncenter size-full wp-image-109" title="2" src="http://wenjinjin.com/wp-content/uploads/2010/07/2.png" alt="" width="823" height="352" /></a><br />
</span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 3.File&#8211;&gt;Save All 全部保存</span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><br />
</span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><br />
</span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;">实际上这样就能编译了，不过只是空的dll</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 4.File&#8211;&gt;New&#8211;&gt;Other&#8211;&gt;Active Form</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/EvernoteCopyBuffer/5770f32c-8a19-4ae5-9a86-7cdb2441a99c.png" alt="" /></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><a href="http://wenjinjin.com/wp-content/uploads/2010/07/3.png"><img class="aligncenter size-full wp-image-110" title="3" src="http://wenjinjin.com/wp-content/uploads/2010/07/3.png" alt="" width="551" height="415" /></a> </span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 改名为MyForm</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><a href="http://wenjinjin.com/wp-content/uploads/2010/07/4.png"><img class="aligncenter size-full wp-image-111" title="4" src="http://wenjinjin.com/wp-content/uploads/2010/07/4.png" alt="" width="527" height="418" /></a><br />
</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/EvernoteCopyBuffer/a554f9c5-85db-4a7e-81bb-11fdbfe2123e.png" alt="" /></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 将对应的单元文件，保存为UMyForm.pas</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 5.打开MyAcitveX.ridl文件，切换到design视图，选中IMyForm接口，右击New&#8211;&gt;Property 添加一个属性Msg</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/EvernoteCopyBuffer/940a9e4c-7fc2-4ac4-8bde-39f8db2f03cc.png" alt="" /></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> <a href="http://wenjinjin.com/wp-content/uploads/2010/07/5.png"><img class="aligncenter size-full wp-image-112" title="5" src="http://wenjinjin.com/wp-content/uploads/2010/07/5.png" alt="" width="561" height="376" /></a><br />
</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 将Msg属性的Type改为BSTR 即WideString类型</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><a href="http://wenjinjin.com/wp-content/uploads/2010/07/6.png"><img class="aligncenter size-full wp-image-113" title="6" src="http://wenjinjin.com/wp-content/uploads/2010/07/6.png" alt="" width="698" height="348" /></a><br />
</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/EvernoteCopyBuffer/bf3e3bf9-72a4-4415-802e-b708ea4ad5ea.png" alt="" /></span></span></span></p>
<p><span style="font-family: Simsun;"><span style="line-height: normal; font-size: small;"><br />
</span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 完了之后，点击工具栏中的Refresh Implementation(即上图中工具栏中圈起来的部分)&#8211;这一步很重要，点击之后，它将自动生成属性Msg对应的声明和实现代码模板</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 6.打开UMyForm.pas&#8211;即ActiveForm对应的单元，找到Set_Msg以及Get_Msg的实现部分，补充代码如下:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>function　TMyForm.Get_Msg:　WideString;<br />
begin<br />
result:=_msg;<br />
end;<br />
procedure　TMyForm.Set_Msg(const　Value:　WideString);<br />
begin<br />
_msg　:=　value;<br />
end;</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 当然TMyForm的private部分，得先加一个私有成员 </span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>type<br />
TMyForm　=　class(TActiveForm,　IMyForm)<br />
private<br />
{　Private　declarations　}<br />
_msg:WideString;<br />
...</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 这样我们就为即将生成的ActiveX控件，添加了一个字符串类型的属性Msg，下面来测试一下:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 7.编译项目，会生成一个MyActiveX.ocx，在运行栏里输入</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> regsvr32 C:\Users\jimmy.yang\Desktop\delphi_activex\MyActiveX\MyActiveX.ocx</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 注:这里ocx的路径，请各位根据自己的实际路径修改</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 这样就完成了ocx的注册。</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 8.放到html里测试一下：</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>&lt;OBJECT　ID='x'　name='x'　CLASSID='CLSID:52D17094-0687-4A2F-B2DB-30F3189AC659'　align=center　hspace=0　vspace=0　&gt;&lt;/OBJECT&gt;<br />
&lt;script　type='text/javascript'&gt;<br />
var　x　=　document.getElementById("x");<br />
alert(x.Msg);<br />
&lt;/script&gt;</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 关于CLSID在哪里查看，打开:MyActiveX_TLB.pas文件，定位到下面这里:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>const<br />
//　TypeLibrary　Major　and　minor　versions<br />
MyActiveXMajorVersion　=　1;<br />
MyActiveXMinorVersion　=　0;<br />
LIBID_MyActiveX:　TGUID　=　'{49138437-8265-4B1A-9EAE-D0F615D68464}';<br />
IID_IMyForm:　TGUID　=　'{54A20855-29A3-4C92-85DE-A419DA457C7A}';<br />
DIID_IMyFormEvents:　TGUID　=　'{60BBC967-E1E6-4E98-BAE5-776BFD06E9CC}';<br />
CLASS_MyForm:　TGUID　=　'{52D17094-0687-4A2F-B2DB-30F3189AC659}';</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><br />
</span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 其中 CLASS_MyForm: TGUID对应的就是ClassID</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 运行后，除了弹出一个空白的警告框，暂时看不到其它:)（可不就是这样么？Msg属性没给任何初始值，当然是空字符串，所以弹出一个空的警告框是正常的)</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 9.我们再来添加一些控件和方法，以验证刚才设置的属性确实有效</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 在MyForm上添加一个文件框，一个按钮</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/EvernoteCopyBuffer/ca12e1d6-63cd-45b3-b765-2df3331141dc.png" alt="" /> <a href="http://wenjinjin.com/wp-content/uploads/2010/07/8.png"><img class="aligncenter size-full wp-image-114" title="8" src="http://wenjinjin.com/wp-content/uploads/2010/07/8.png" alt="" width="309" height="71" /></a><br />
</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 按钮的事件如下:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>procedure　TMyForm.Button1Click(Sender:　TObject);<br />
begin<br />
_msg:=　self.Edit1.Text;<br />
end;</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 即把文本框的值赋给属性Msg</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 再继续定位到Set_Msg,略做修改</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>procedure　TMyForm.Set_Msg(const　Value:　WideString);<br />
begin<br />
_msg　:=　value;<br />
self.Edit1.Text　:=　_msg;<br />
end;</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 即设置Msg属性时，同时也把值显示在文本框里，以便等会儿我们好测试在js中给activeX属性赋值的效果</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> ok了，再来测试一下，编译一下，如果通不过，请先运行</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> regsvr32 C:\Users\jimmy.yang\Desktop\delphi_activex\MyActiveX\MyActiveX.ocx /u</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 将刚才注册的ocx反注册，同时关掉浏览器，不然该ocx文件一直被占用，无法更新.</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 修改一下html的代码:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>&lt;OBJECT　ID='x'　name='x'　CLASSID='CLSID:52D17094-0687-4A2F-B2DB-30F3189AC659'　align=center　hspace=0　vspace=0　&gt;&lt;/OBJECT&gt;<br />
&lt;hr　/&gt;<br />
&lt;input　type='button'　value='显示Msg属性的值'　onclick='ShowMsg()'/&gt;<br />
&lt;input　type='button'　value='设置Msg属性的值'　onclick='SetMsg()'/&gt;<br />
&lt;script　type='text/javascript'&gt;<br />
var　x　=　document.getElementById("x");<br />
var　ShowMsg　=　function(){<br />
alert(x.Msg);<br />
}<br />
var　SetMsg　=　function(){<br />
x.Msg　=　'js传过来的值';<br />
}<br />
&lt;/script&gt;</code></span></span></span></span></p>
<div>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;">运行效果:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><a href="http://wenjinjin.com/wp-content/uploads/2010/07/9.png"><img class="aligncenter size-full wp-image-115" title="9" src="http://wenjinjin.com/wp-content/uploads/2010/07/9.png" alt="" width="532" height="194" /></a><br />
</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/EvernoteCopyBuffer/1901bd7f-23df-4f0c-9f9f-70ec82090874.png" alt="" /></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 10.添加Method</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 我们已经知道了如何给ActiveX添加对外公开的属性，但是光有属性显然不够，我们再添加一个Method，参考第5步中的截图，选择new&#8211;&gt;Method,添加</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 一个方法,命名为ShowMsg，Return参数项用默认值HRESULT，然后Parameters添加一个参数，如下图:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/EvernoteCopyBuffer/1de9eeec-0e79-46bc-8b7b-37759221f25b.png" alt="" /></span></span></span></span></p>
<p><span style="font-family: Simsun;"><span style="line-height: normal; font-size: small;"><a href="http://wenjinjin.com/wp-content/uploads/2010/07/10.png"><img class="aligncenter size-full wp-image-116" title="10" src="http://wenjinjin.com/wp-content/uploads/2010/07/10.png" alt="" width="668" height="304" /></a><br />
</span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 同样不要忘记了点击工具栏中的更新按钮,再打开UMyForm.pas，会发现自动添加了一个过程的定义:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> procedure　ShowMsg(const　p:　WideString);　safecall;</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 转到它的实现部分，写几行测试代码:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>procedure　TMyForm.ShowMsg(const　p:　WideString);<br />
begin<br />
showmessage('Msg属性的值为：'　+　_msg　+　#13　+　'传入的参数为：'　+　p);<br />
end;</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 再编译，html代码中添加一些代码:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>&lt;OBJECT　ID='x'　name='x'　CLASSID='CLSID:52D17094-0687-4A2F-B2DB-30F3189AC659'　align=center　hspace=0　vspace=0　&gt;&lt;/OBJECT&gt;<br />
&lt;hr　/&gt;<br />
&lt;input　type='button'　value='显示Msg属性的值'　onclick='ShowMsg()'/&gt;<br />
&lt;input　type='button'　value='设置Msg属性的值'　onclick='SetMsg()'/&gt;<br />
&lt;input　type='button'　value='调用ShowMsg方法'　onclick='CallShowMsg()'/&gt;<br />
&lt;script　type='text/javascript'&gt;<br />
var　x　=　document.getElementById("x");<br />
var　ShowMsg　=　function(){<br />
alert(x.Msg);<br />
}<br />
var　SetMsg　=　function(){<br />
x.Msg　=　'js传过来的值';<br />
}<br />
var　CallShowMsg　=　function(){<br />
x.ShowMsg('这是js传过来的参数');<br />
}<br />
&lt;/script&gt;</code></span></span></span></span></p>
<div><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><br />
</span></span></span></div>
<div>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 运行看下：</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><a href="http://wenjinjin.com/wp-content/uploads/2010/07/11.png"><img class="aligncenter size-full wp-image-117" title="11" src="http://wenjinjin.com/wp-content/uploads/2010/07/11.png" alt="" width="487" height="257" /></a></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><a href="http://wenjinjin.com/wp-content/uploads/2010/07/12.png"><img class="aligncenter size-full wp-image-118" title="12" src="http://wenjinjin.com/wp-content/uploads/2010/07/12.png" alt="" width="668" height="304" /></a><br />
</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/EvernoteCopyBuffer/fd12b967-3835-4e0a-91a3-8a0ce4f39aec.png" alt="" /></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 类似的，我们还可以为ActiveX添加带返回值的function,而非过程procedure，但是比较郁闷的是，我试了半天，delphi中编译正常后，但是在javascript中就是无法取得返回值，估计是delphi的变量类型与javascript的变量类型不匹配引起的，哪位 delphi高人如果知道原因，还请指点一二，在此先谢过.</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 11.深入看下ActiveX中到底有哪些玩意儿？</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 既然ActiveX能加载到网页中，肯定也是dom树的一份子了，想知道ActiveX到底提供了哪些其它属性或方法吗？以下的js代码可以测试出来:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>&lt;div　id="info"&gt;&lt;/div&gt;<br />
&lt;script　type="text/javascript"&gt;<br />
var　_info="";<br />
for(var　p　in　x){<br />
_info　+=　p　+　"："　+　x[p]　+　"&lt;br/&gt;";<br />
}<br />
document.getElementById("info").innerHTML　=　_info;<br />
&lt;/script&gt;</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 当然如果你用IE8的js调试功能，也能看到刚才定义的那些方法和属性：</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><img src="file:///C:/Documents%20and%20Settings/Administrator/Local%20Settings/Temp/EvernoteCopyBuffer/39a82b83-c118-4b48-ace6-3d7f80620d75.png" alt="" /></span></span></span></span></p>
<p><a href="http://wenjinjin.com/wp-content/uploads/2010/07/13.png"><img class="aligncenter size-full wp-image-119" title="13" src="http://wenjinjin.com/wp-content/uploads/2010/07/13.png" alt="" width="779" height="570" /></a></p>
<p><span style="font-family: Simsun;"><span style="line-height: normal; font-size: small;"><br />
</span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 注意一下这里还有其它很多属性，比如Caption，所以你在js中用alert(x.Caption)也能弹出ActiveForm的标题，这是我们通过IE/JS从外部来看ActiveX的，其实也能换个角度从delphi内部看下activex的结构，com技术号称就是一组通用的接口规范，所以我们在delphi内部确实也能发现不少接口:</span></span></span></span></p>
</div>
</div>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;">MyActiveX.ridl中可以看到</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>library　MyActiveX<br />
{<br />
...<br />
interface　IMyForm;<br />
...<br />
...</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 表明IMyForm就是一个接口,再定位到MyActiveX_TLB.pas可以发现:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>type<br />
...<br />
IMyForm　=　interface;<br />
...<br />
MyForm　=　IMyForm;<br />
IMyForm　=　interface(IDispatch)<br />
...</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 说明MyForm就是从IDispatch继承下来的一个接口</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 最后再到UMyForm.pas中可以看到</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>type<br />
TMyForm　=　class(TActiveForm,　IMyForm)<br />
Edit1:　TEdit;<br />
...</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 说明最终的运行窗口，就是继承自TActiveForm并实现了IMyForm的一个类</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 12.事件支持</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 打开MyActiveX.ridl，查看IMyFormEvents部分，可以看到delphi生成的ActiveX控件中已经预置了很多事件</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>dispinterface　IMyFormEvents<br />
{<br />
properties:<br />
methods:<br />
[id(0x000000C9)]<br />
void　OnActivate(void);<br />
[id(0x000000CA)]<br />
void　OnClick(void);<br />
[id(0x000000CB)]<br />
void　OnCreate(void);<br />
[id(0x000000CC)]<br />
void　OnDblClick(void);<br />
[id(0x000000CD)]<br />
void　OnDestroy(void);<br />
[id(0x000000CE)]<br />
void　OnDeactivate(void);<br />
[id(0x000000CF)]<br />
void　OnKeyPress([in,　out]　short*　Key);<br />
[id(0x000000D0)]<br />
void　OnMouseEnter(void);<br />
[id(0x000000D1)]<br />
void　OnMouseLeave(void);<br />
[id(0x000000D2)]<br />
void　OnPaint(void);<br />
};</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 我们可以用javascript来响应这些事件，比如就拿我们最熟悉的OnClick事件，js中要这么处理:</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><code>&lt;OBJECT　ID='x'　name='a'　CLASSID='CLSID:52D17094-0687-4A2F-B2DB-30F3189AC659'　align=center　hspace=0　vspace=0　&gt;&lt;/OBJECT&gt;<br />
&lt;script　type="text/javascript"　event="OnClick"　for="a"&gt;<br />
alert('你点击了ActiveX控件');<br />
&lt;/script&gt;</code></span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 运行后，鼠标在ActiveX的空白处点击，会弹出一个警告框:&#8221;你点击了ActiveX控件&#8221;</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 13.其它问题</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 前面提到了带返回值的function不好弄，其实这个不是什么大问题，完全可以迂回用procedure与属性解决</span></span></span></span></p>
<p><span style="border-collapse: separate; color: #000000; font-family: Arial; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: 14pt;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"><span style="font-family: Simsun; color: #000000; font-size: small;"> 比如我们可以定义一个带参数的procedure，js调用时传入参数，然后在procedure内部，对参数进行处理后，将其赋值为 ActiveX的任何一个类型匹配的属性，比如前面提到的Caption属性，然后js获取Caption属性，相当于就是ActiveX处理后的返回值了</span></span></span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://wenjinjin.com/code_document/delphi_doc/delphi_activex.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>开始整理一些delphi的东西</title>
		<link>http://wenjinjin.com/code_document/delphi_doc/delphi_collecting.html</link>
		<comments>http://wenjinjin.com/code_document/delphi_doc/delphi_collecting.html#comments</comments>
		<pubDate>Tue, 06 Jul 2010 15:43:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[DELPHI文档]]></category>
		<category><![CDATA[开始整理]]></category>

		<guid isPermaLink="false">http://wenjinjin.com/?p=103</guid>
		<description><![CDATA[听说delphi用的人很少了，不过前阵子 要做一个网页启动截屏程序的activex ，找了一些资料，发现用 delphi很容易构建，看了一下，很容易上手，很快就做完了，然后一发不可收拾的用delphi做了几个小玩意，发现delphi开发东西很快，很适合做一些简单桌面需求的快速实现。期间学习了一些文档，在此处整理一下，以备不时之需。
]]></description>
			<content:encoded><![CDATA[<p>听说delphi用的人很少了，不过前阵子 要做一个网页启动截屏程序的activex ，找了一些资料，发现用 delphi很容易构建，看了一下，很容易上手，很快就做完了，然后一发不可收拾的用delphi做了几个小玩意，发现delphi开发东西很快，很适合做一些简单桌面需求的快速实现。期间学习了一些文档，在此处整理一下，以备不时之需。</p>
]]></content:encoded>
			<wfw:commentRss>http://wenjinjin.com/code_document/delphi_doc/delphi_collecting.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>最困难的事</title>
		<link>http://wenjinjin.com/share/know-yourself.html</link>
		<comments>http://wenjinjin.com/share/know-yourself.html#comments</comments>
		<pubDate>Tue, 12 Jan 2010 06:58:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[分享]]></category>

		<guid isPermaLink="false">http://wenjinjin.com/?p=1</guid>
		<description><![CDATA[有人问古希腊哲学家泰勒斯：“你认为人活在这个世界上，什么事情是最困难的？”泰勒斯回答说：“认识你自己。”
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-认识自己难，认识自己的不足更难。
]]></description>
			<content:encoded><![CDATA[<p>有人问古希腊哲学家泰勒斯：“你认为人活在这个世界上，什么事情是最困难的？”泰勒斯回答说：“认识你自己。”</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-认识自己难，认识自己的不足更难。</p>
]]></content:encoded>
			<wfw:commentRss>http://wenjinjin.com/share/know-yourself.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

