Delphi FireMonkey在应用程序内部存储数据 [英] Delphi FireMonkey store data inside application

查看:73
本文介绍了Delphi FireMonkey在应用程序内部存储数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在Delphi XE5 FireMonkey(Android)移动应用程序中存储一些自定义的静态数据。我在网络上看到过 RC_DATA解决方案,但这是特定于Windows的。
我需要一个跨平台的解决方案。

I need to store some custom, static data inside my Delphi XE5 FireMonkey (Android) mobile application. I have seen a 'RC_DATA' solution on the web, but it is windows-specific. I need a cross-platform solution.

这是我发现的RC_DATA解决方案: http://delphidabbler.com/articles?article=2

Here is the RC_DATA solution I discovered:http://delphidabbler.com/articles?article=2

代码示例中的注释读取://资源类型-RT_RCDATA(来自Windows单元)

A comment in the code sample reads: // resource type - RT_RCDATA (from Windows unit)

我从此注释得出结论,Windows单元内的代码特定于Windows。

I concluded from this comment that the code inside the Windows unit was Windows-specific. I apologize if this is not the case.

由于Chris表示实际上是跨平台的,所以我会尝试一下。谢谢克里斯。

Since Chris said that it is, in fact, cross-platform, I will try it out. Thank you Chris.

关于请求组件或库,我已经阅读并重新阅读了我的问题,但我没有看到。我想解决方案可能会包含一个组件或库,但是我从来没有想过。再次,如果我做错了事,我深表歉意。

With respect to asking for a component or library, I have read and re-read my question and I just don't see it. I guess a 'solution' COULD POSSIBLY include a component or library, but that was never in my mind. Again, I apologize if I did something wrong.

推荐答案

远离Windows的 RC_DATA解决方案具体来说,它实际上是Delphi提供的最直接的跨平台方法。您需要做的是通过Project | Resources和Images ...将文件添加到项目中。由于其他资源类型 是Windows特定的,因此对于每种资源,请坚持使用RCDATA。然后,要加载,请像在VCL应用程序中一样使用 TResourceStream (在<$ c中声明 RT_RCDATA $ c> System.Types ):

Far from what you call the '"RC_DATA" solution' being Windows-specific, it is actually the most straight-forwardly cross platform way Delphi provides. What you need to do is to add the files to the project via Project|Resources and Images...; since the other resource types are Windows-specific, just stick to RCDATA for each one. Then, to load, use TResourceStream like you might have done in a VCL application (RT_RCDATA is declared in System.Types):

procedure LoadStringsFromRes(Strings: TStrings; const ResName: string);
var
  Stream: TResourceStream;
begin
  Stream := TResourceStream.Create(HInstance, ResName, RT_RCDATA);
  try
    Strings.LoadFromStream(Stream);
  finally
    Stream.Free;
  end;
end;

此外,如果由于某种原因您想在尝试加载给定资源之前检查其是否存在, System 单元为非Windows平台实现Windows API FindResource 函数。

Also, if for some reason you want to check whether a given resource exists before trying to load it, the System unit implements the Windows API FindResource function for non-Windows platforms.

嵌入式资源的另一种选择是使用Project | Deployment将文件添加到应用程序捆绑包(OS X和iOS)或APK(Android)中。尽管这可能被认为是一种更平台本地的工作方式,但是适当的远程路径是特定于平台的……坦率地说,如果一个人如此痴迷于平台本地化,他们将无法处理嵌入式资源。 ,那么他们就不会首先使用FMX ...

An alternative to embedded resources is to use Project|Deployment to add files to the application bundle (OS X and iOS) or APK (Android). While this might be considered a more 'platform native' way of doing things, the appropriate 'remote path' is platform-specific... and frankly, if a person is so obsessed at being platform-native they can't handle embedded resources, then they wouldn't be using FMX in the first place...

更新:关于该文章,现在已经链接到它,它显示了如何手动写出RES文件,这不是人们通常要做的-如果您不使用IDE的小型资源管理器,那么通常的方法是创建RC脚本并使用Borland或Microsoft资源编译器进行编译。

Update: with regard to the article that has now been linked to, it's showing how to write out a RES file manually, which isn't what a person would normally do - if you aren't using the IDE's little resource manager, then the normal way is to create a RC script and compile it with either the Borland or Microsoft resource compiler.

这篇关于Delphi FireMonkey在应用程序内部存储数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆