主要内容

本页采用了机器翻译。点击此处可查看最新英文版本。

discardChanges

放弃对数据字典所做的更改

说明

discardChanges(dictionaryObj) 丢弃自上次使用 saveChanges 函数保存字典更改以来对指定数据字典所做的所有更改。discardChanges 还会丢弃对引用的数据字典所做的更改。对目标词典及其引用字典的更改将永久丢失。

示例

示例

全部折叠

创建一个代表数据字典 myDictionary_ex_API.slddSimulink.data.Dictionary 对象,并将该对象分配给变量 myDictionaryObj

myDictionaryObj = Simulink.data.dictionary.open('myDictionary_ex_API.sldd')
myDictionaryObj = 

  Dictionary with properties:

          DataSources: {'myRefDictionary_ex_API.sldd'}
    HasUnsavedChanges: 0
           NumberOfEntries: 4

通过添加名为 myNewEntry 且值 237 的条目来对 myDictionary_ex_API.sldd 进行更改。查看 myDictionaryObjHasUnsavedChanges 属性以确认做出了更改。

dDataSectObj = getSection(myDictionaryObj,'Design Data');
addEntry(dDataSectObj,'myNewEntry',237);
myDictionaryObj
myDictionaryObj = 

  Dictionary with properties:

          DataSources: {'myRefDictionary_ex_API.sldd'}
    HasUnsavedChanges: 1
           NumberOfEntries: 5

放弃对 myDictionary_ex_API.sldd 的所有更改。myDictionaryObjHasUnsavedChanges 属性表示更改已被丢弃。

discardChanges(myDictionaryObj)
myDictionaryObj
myDictionaryObj = 

  Dictionary with properties:

          DataSources: {'myRefDictionary_ex_API.sldd'}
    HasUnsavedChanges: 0
           NumberOfEntries: 4

输入参数

全部折叠

目标数据字典,指定为 Simulink.data.Dictionary 对象。在使用此函数之前,请使用 Simulink.data.dictionary.createSimulink.data.dictionary.open 等函数通过 Simulink.data.Dictionary 对象来表示目标字典。

替代方法

您可以使用模型资源管理器窗口放弃对数据字典的更改。有关详细信息,请参阅 View and Revert Changes to Dictionary Entries

版本历史记录

在 R2015a 中推出