【问题标题】:How to store a stack in a custom property in LiveCode?如何将堆栈存储在 LiveCode 的自定义属性中?
【发布时间】:2014-08-07 21:48:20
【问题描述】:

我正在开发一个 iOS 应用程序。我想使用文档文件夹中的堆栈来存储一些数据和首选项。我知道我可以通过在创建独立时复制它来在引擎文件夹中包含一个堆栈,但是将堆栈存储在我的主堆栈的自定义属性中似乎更容易和更清晰。我可以在应用程序的第一次运行时创建数据堆栈并将其存储在文档文件夹中。

我认为我可以在开发过程中做到这一点:

set the cDataStack of stack "My Main Stack" to URL ("binfile:" & tDataStackFilePath)

然后当需要创建新的数据存储堆栈时,请执行以下操作:

set the defaultFolder to the documents folder
put the cDataStack of me into URL ("binfile:DataStack1.livecode")

...但这对我不起作用。它会创建一个 0kb 的文件,而我希望它是原始文件的副本。

这是为 iOS 创建数据堆栈的合理方式吗? 我的代码是否展示了正确的概念?

【问题讨论】:

    标签: ios livecode


    【解决方案1】:

    可能我的 cDataStack 是空的。也许,me指的是错误的控件或堆栈。试试这个:

    // set the property
    put URL ("binfile:" & tDataStackFilePath) into myStackData
    if myStackData is not empty then
      set the cDataStack of stack "My Main Stack" to myStackData
      put the result into rslt
      if rslt is not empty then
        beep
        answer error rslt
      end if
    else
      beep
      answer error "This file is empty or doesn't exist."
    end if
    
    // get the propety
    put specialFolderpath("documents") & "/DataStack1.LiveCode" into myPath
    if the cDataStack of me is not empty then
      put the cDataStack of me into URL ("binfile:" & myPath)
      put the result into rslt
      if rslt is not empty then
        beep
        answer error rslt
      end if
    else
      beep
      answer error "The property is empty."
    end if
    

    您无需在打开堆栈之前将其写入磁盘。你可以这样做:

    go stack the cDataStack of me
    put the result into rslt
    if rslt is not empty then
      beep
      aswer error rslt
    end if
    

    【讨论】:

    • 已确认...很有魅力。是的,“我”指的是包含堆栈的测试按钮,而不是堆栈本身。另外,我认为我的文件 URL 格式可能不正确。无论如何,它现在正在工作。谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-05
    • 2010-10-27
    • 1970-01-01
    • 2015-03-15
    • 2013-07-19
    • 2022-01-14
    相关资源
    最近更新 更多