如何在 Inno Setup Scripts 中将字符串版本值转换为数值?
我想开发一个安装包来有条件地升级现有包。 我想根据要安装的版本检查现有软件版本。 为了做到这一点,我必须比较版本字符串。
如何在 Inno 安装脚本中将字符串值转换为数值?
RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Blah blah', 'Version', version)
version = 'V1.R2.12';
numVersion := ??string_to_numerical_value??(version);
I want to develop a setup package for conditionally upgrading an existing package. I want to check the existing software version against to-be-installed version. In order to do that, I have to compare the version strings.
How can I convert the string value to a numerical value in a Inno setup script?
RegQueryStringValue(HKEY_LOCAL_MACHINE, 'Software\Blah blah', 'Version', version)
version = 'V1.R2.12';
numVersion := ??string_to_numerical_value??(version);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这有点棘手,因为您希望正确处理“V1.R2.12”和“V0.R15.42”等版本 - 通过其他答案中的简单转换,您将得到 1212 和 1542,这不会与您期望的方式进行比较。
您需要确定版本号的每个部分可以有多大,并将这些部分乘以该值以获得正确的结束号。 类似这样的:
您可以使用以下代码进行测试:
是否为
AMaxVersion
传递 10、100 或 1000 取决于版本号部分的数量和范围。 请注意,不得溢出LongWord
结果变量,该变量的最大值为 2^32 - 1。This is a little more tricky, as you would want to handle versions like 'V1.R2.12' and 'V0.R15.42' correctly - with the simple conversion in the other answer you would get 1212 and 1542, which would not compare the way you would expect.
You need to decide how big each part of the version number can be, and multiply the parts by that value to get a correct end number. Something like this:
You can test this with the following code:
Whether you pass 10, 100 or 1000 for
AMaxVersion
depends on the number and range of your version number parts. Note that you must not overflow theLongWord
result variable, which has a maximum value of 2^32 - 1.我还没有尝试过(我的 Pascal 知识有点生疏),但类似以下的内容应该可以工作:
请注意,您必须将
i
的起始值和结束值用作我不确定它是否是从零开始的(如果它是“Pascal String”,则s[0]
可能包含字符串的长度)。I haven't tried that (and my Pascal knowledge is a bit rusty), but something like the following should work:
Please not that you'll have to play with the start and end value for
i
as I'm not sure whether it is zero-based or not (s[0]
may contain the length of the string if it is a "Pascal String").我在注册表中实现了两个版本字符串(实际上是一个字符串和一个双字值)以克服复杂性。
这很简单。 虽然这不是这个问题的答案,但是当面对复杂性时,人们可能会以另一种方式思考,这可以通过一种更简单的方式来避免。
I've implemented two version strings (actually one string and one dword value) in the registry to overcome complexity.
That's simple. Though not an answer to this question, however one might think the other way around when faced with complexity, which could be avoided in a simpler way.