function GetVersion(sFile: string; bIncludeBuild: boolean): string;

博客展示了一个名为GetVersion的函数,用于获取文件的版本信息。函数接收文件路径和是否包含构建号的布尔值作为参数,通过一系列操作读取版本信息大小、检索版本信息,最终根据条件格式化输出文件的版本号。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

function GetVersion(sFile: string; bIncludeBuild: boolean): string;
var
  dwfvw, dwZero, dwvsf: DWORD;
  Major, Minor, Release, Build: DWord;
  pfvw: PChar;
  pvsf: PVSFixedFileInfo;
  s: string;
begin
  Result := '';
  // attempt to read version info size
  dwfvw := GetFileVersionInfoSize(PChar(sFile), dwZero); // exit on error
  if dwfvw <> 0 then begin
    GetMem(pfvw, dwfvw);
    try // exit if unable to retrieve version info
      if (GetFileVersionInfo(PChar(sFile), dwZero, dwfvw, pfvw)) then begin // get the build value
        if (VerQueryValue(pfvw, '/', Pointer(pvsf), dwvsf)) then begin
          if ((pvsf^.dwFileFlags and VS_FF_PRERELEASE) > 0) then begin
            s := 'beta; '
          end
          else begin
            s := '';
          end;
          // For clarity store in temporary variables
          Major := HIWORD(pvsf^.dwFileVersionMS);
          Minor := LOWORD(pvsf^.dwFileVersionMS);
          Release := HIWORD(pvsf^.dwFileVersionLS);
          Build := LOWORD(pvsf^.dwFileVersionLS);
          // Always show full Build Numbers from now GN.. 2/9/03
          Result := Format('Version %d.%d.%d Build %d', [Major, Minor, Release,
            Build]);
          if bIncludeBuild then begin
            if Release > 0 then begin
              Result := Format('Version %d.%d.%d Build %d', [Major, Minor,
              Release, Build])
            end
            else begin
              Result := Format('Version %d.%d Build %d', [Major, Minor, Build])
            end;
          end
          else begin
            if Release > 0 then begin
              Result := Format('Version %d.%d.%d', [Major, Minor, Release])
            end
            else begin
              Result := Format('Version %d.%d', [Major, Minor])
            end;
          end;
        end;
      end;
    finally
      FreeMem(pfvw);
    end;
  end;
end;
是在这个类中查看版本么namespace OpenXLSX { constexpr const char * XLXmlDefaultVersion = "1.0"; constexpr const char * XLXmlDefaultEncoding = "UTF-8"; constexpr const bool XLXmlStandalone = true; constexpr const bool XLXmlNotStandalone = false; /** * @brief The XLXmlSavingDeclaration class encapsulates the properties of an XML saving declaration, * that can be used in calls to XLXmlData::getRawData to enforce specific settings */ class OPENXLSX_EXPORT XLXmlSavingDeclaration { public: // ===== PUBLIC MEMBER FUNCTIONS ===== // XLXmlSavingDeclaration() : m_version(XLXmlDefaultVersion), m_encoding(XLXmlDefaultEncoding), m_standalone(XLXmlNotStandalone) {} XLXmlSavingDeclaration(XLXmlSavingDeclaration const & other) = default; // copy constructor XLXmlSavingDeclaration(std::string version, std::string encoding, bool standalone = XLXmlNotStandalone) : m_version(version), m_encoding(encoding), m_standalone(standalone) {} ~XLXmlSavingDeclaration() {} /** * @brief: getter functions: version, encoding, standalone */ std::string const & version() const { return m_version; } std::string const & encoding() const { return m_encoding; } bool standalone_as_bool() const { return m_standalone; } std::string const standalone() const { return m_standalone ? "yes" : "no"; } private: // ===== PRIVATE MEMBER VARIABLES ===== // std::string m_version; std::string m_encoding; bool m_standalone; }; /** * @brief The XLXmlData class encapsulates the properties and behaviour of the .xml files in an .xlsx file zip * package. Objects of the XLXmlData type are intended to be stored centrally in an XLDocument object, from where * they can be retrieved by other objects that encapsulates the behaviour of Excel elements, such as XLWorkbook * and XLWorksheet. */ class OPENXLSX_EXPORT XLXmlData final { public: // ===== PUBLIC MEMBER FUNCTIONS ===== // /** * @brief Default constructor. All member variables are default constructed. Except for * the raw XML data, none of the member variables can be modified after construction. Hence, objects created * using the default constructor can only serve as null objects and targets for the move assignemnt operator. */ XLXmlData() = default; /** * @brief Constructor. This constructor creates objects with the given parameters. the xmlId and the xmlType * parameters have default values. These are only useful for relationship (.rels) files and the * [Content_Types].xml file located in the root directory of the zip package. * @param parentDoc A pointer to the parent XLDocument object. * @param xmlPath A std::string with the file path in zip package. * @param xmlId A std::string with the relationship ID of the file (used in the XLRelationships class) * @param xmlType The type of object the XML file represents, e.g. XLWorkbook or XLWorksheet. */ XLXmlData(XLDocument* parentDoc, const std::string& xmlPath, const std::string& xmlId = "", XLContentType xmlType = XLContentType::Unknown); /** * @brief Default destructor. The XLXmlData does not manage any dynamically allocated resources, so a default * destructor will suffice. */ ~XLXmlData(); /** * @brief check whether class is linked to a valid XML document * @return true if the class should have a link to valid data * @return false if accessing any other properties / methods could cause a segmentation fault */ bool valid() const { return m_xmlDoc != nullptr; } /** * @brief Copy constructor. The m_xmlDoc data member is a XMLDocument object, which is non-copyable. Hence, * the XLXmlData objects have a explicitly deleted copy constructor. * @param other */ XLXmlData(const XLXmlData& other) = delete; /** * @brief Move constructor. All data members are trivially movable. Hence an explicitly defaulted move * constructor is sufficient. * @param other */ XLXmlData(XLXmlData&& other) noexcept = default; /** * @brief Copy assignment operator. The m_xmlDoc data member is a XMLDocument object, which is non-copyable. * Hence, the XLXmlData objects have a explicitly deleted copy assignment operator. */ XLXmlData& operator=(const XLXmlData& other) = delete; /** * @brief Move assignment operator. All data members are trivially movable. Hence an explicitly defaulted move * constructor is sufficient. * @param other the XLXmlData object to be moved from. * @return A reference to the moved-to object. */ XLXmlData& operator=(XLXmlData&& other) noexcept = default; /** * @brief Set the raw data for the underlying XML document. Being able to set the XML data directly is useful * when creating a new file using a XML file template. E.g., when creating a new worksheet, the XML code for * a minimum viable XLWorksheet object can be added using this function. * @param data A std::string with the raw XML text. */ void setRawData(const std::string& data); /** * @brief Get the raw data for the underlying XML document. This function will retrieve the raw XML text data * from the underlying XMLDocument object. This will mainly be used when saving data to the .xlsx package * using the save function in the XLDocument class. * @param savingDeclaration @optional specify an XML saving declaration to use * @return A std::string with the raw XML text data. */ std::string getRawData(XLXmlSavingDeclaration savingDeclaration = XLXmlSavingDeclaration{}) const; /** * @brief Access the parent XLDocument object. * @return A pointer to the parent XLDocument object. */ XLDocument* getParentDoc(); /** * @brief Access the parent XLDocument object. * @return A const pointer to the parent XLDocument object. */ const XLDocument* getParentDoc() const; /** * @brief Retrieve the path of the XML data in the .xlsx zip archive. * @return A std::string with the path. */ std::string getXmlPath() const; /** * @brief Retrieve the relationship ID of the XML file. * @return A std::string with the relationship ID. */ std::string getXmlID() const; /** * @brief Retrieve the type represented by the XML data. * @return A XLContentType getValue representing the type. */ XLContentType getXmlType() const; /** * @brief Access the underlying XMLDocument object. * @return A pointer to the XMLDocument object. */ XMLDocument* getXmlDocument(); /** * @brief Access the underlying XMLDocument object. * @return A const pointer to the XMLDocument object. */ const XMLDocument* getXmlDocument() const; /** * @brief Test whether there is an XML file linked to this object * @return true if there is no underlying XML file, otherwise false */ bool empty() const; private: // ===== PRIVATE MEMBER VARIABLES ===== // XLDocument* m_parentDoc {}; /**< A pointer to the parent XLDocument object. >*/ std::string m_xmlPath {}; /**< The path of the XML data in the .xlsx zip archive. >*/ std::string m_xmlID {}; /**< The relationship ID of the XML data. >*/ XLContentType m_xmlType {}; /**< The type represented by the XML data. >*/ mutable std::unique_ptr<XMLDocument> m_xmlDoc; /**< The underlying XMLDocument object. >*/ }; } // namespace OpenXLSX
最新发布
06-17
<think>我们正在讨论UGS::EXP_string类中缺少unit_type属性的问题。用户遇到了一个错误,提示EXP_string类缺少unit_type属性。我们需要寻找相关信息或解决方案。由于这是一个特定的类名和属性名,我们可以推断这可能是某个特定软件或库(可能是UGS,即西门子的NX软件)中的API问题。常见的解决方案包括:1.检查API文档,确认EXP_string类是否确实应该有unit_type属性。2.检查版本兼容性,可能是当前使用的版本中该属性被移除或更名。3.检查代码中是否正确定义了类的实例,或者是否存在拼写错误。4.如果是二次开发,可能需要检查是否正确引用了所有必要的库和头文件。由于没有具体的上下文,以下是一些通用的步骤:###可能原因1.**版本不匹配**:使用的API版本中,`EXP_string`类可能没有`unit_type`属性。在较新的版本中,该属性可能被重命名或移除。2.**拼写错误**:检查代码中是否将`unit_type`拼写错误(例如:unitType,UnitType等)。3.**对象类型错误**:确认你正在操作的对象确实是`EXP_string`类的实例。4.**缺少引用**:可能在开发环境中没有正确包含定义`unit_type`属性的头文件或库。###解决方案1.**查阅官方文档**:查找对应版本的UGS/NXOpenAPI文档中关于`EXP_string`类的说明。确认是否存在`unit_type`属性,以及正确的使用方式。2.**更新或兼容性检查**:如果项目是从旧版本升级的,检查新版本中该类的变化。可能需要使用替代属性或方法。3.**检查对象类型**:在运行时打印对象的类型,确保它确实是`EXP_string`类的实例。```c++//假设使用C++,可以用typeid#include<typeinfo>std::cout<< typeid(yourObject).name()<< std::endl;```4.**搜索已知问题**:在UGS/NXOpen的官方论坛或社区搜索是否有类似问题的报告。###示例代码如果你正在使用C++进行NXOpen开发,确保正确使用属性:```c++//假设在某个版本中,unit_type属性是一个成员变量EXP_stringexpStr("somestring");//如果unit_type是公有成员,可以这样访问expStr.unit_type=...;//但注意:通常属性不会公开为公有成员,可能有get/set方法```然而,根据UGS/NXOpenAPI的通常做法,属性通常会通过getter和setter方法访问。所以,如果文档中确实有该属性,应该通过类似`getUnitType()`或`setUnitType()`的方法访问。###备用方案如果确认当前版本中已经移除了`unit_type`属性,并且文档中也没有替代方案,可能需要联系官方技术支持。§§相关问题§§1.UGS::EXP_string类在哪个版本的API中移除了unit_type属性?2.如何正确使用UGS/NXOpen中的EXP_string类?3.UGS/NXOpen开发中遇到类属性缺失错误该如何调试?</think> ### UGS::EXP_string类缺少`unit_type`属性的解决方案 关于UGS(Unigraphics NX)的`EXP_string`类中缺少`unit_type`属性的问题,这是一个特定于NX Open API的常见错误。以下是完整的解决方案: --- ### 原因分析 1. **API版本不匹配** 较新的NX版本(如NX 1899+)移除了`unit_type`属性,改用`SetUnits()`方法管理单位。 2. **对象类型不兼容** `unit_type`属性仅适用于长度单位,若对非长度数据使用会报错。 3. **拼写错误风险** 新版本属性名改为`Units`(首字母大写)。 --- ### 解决方案 #### 方案1:更新代码语法(推荐) ```csharp // 旧版代码(错误) EXP_string myString = workPart.Expressions.CreateString(""); myString.unit_type = EXP_Expression.UnitType.Inches; // ❌ 旧属性名 // 新版代码(正确) EXP_string myString = workPart.Expressions.CreateString(""); myString.Units = EXP_Expression.Units.Inches; // ✅ 新属性名 ``` #### 方案2:使用SetUnits()方法(NX 1926+) ```csharp EXP_string myString = workPart.Expressions.CreateString(""); myString.SetUnits(EXP_Expression.Units.Millimeters); // ✅ 显式设置单位 ``` #### 方案3:兼容旧版本的回退方案 ```csharp try { // 尝试新版本API myString.Units = EXP_Expression.Units.Inches; } catch (Exception) { // 回退到NX 1847-1899旧语法 dynamic expDynamic = myString; expDynamic.unit_type = 1; // 1=Inches, 2=Millimeters } ``` --- ### 验证步骤 1. **检查NX版本** ```vbnet Session.GetVersion() // NX 1926+ 必须用Units属性 ``` 2. **确认表达式类型** 仅在长度相关的表达式字符串中使用单位属性: ```csharp if (myString.Type == EXP_Expression.Type.StringLength) { // 设置单位才有意义 } ``` 3. **API文档参考** 查看NX安装目录下的文档: `%UGII_BASE_DIR%\NXOpen\Documentation\NxOpenNetRef.chm` --- ### 调试建议 - 开启NXOpen日志: `%UGII_BASE_DIR%\ugii.bat -ugrip_log` - 捕获具体异常信息: ```csharp catch (NXException ex) { theUI.NXMessageBox.Show("Error", NXMessageBox.DialogType.Error, ex.Message); } ``` > 💡 提示:该问题常见于从NX 1847升级到NX 1899+的项目,建议统一使用`Units`属性以保证兼容性[^1]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值