存储“记录阵列”的最佳方式在设计时 [英] Best way of storing an "array of records" at design-time

查看:129
本文介绍了存储“记录阵列”的最佳方式在设计时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组数据,我需要在设计时存储,以便在运行时构建一组组件的内容。

I have a set of data that I need to store at design-time to construct the contents of a group of components at run-time.

这样的东西:

type
  TVulnerabilityData = record
    Vulnerability: TVulnerability;
    Name: string;
    Description: string;
    ErrorMessage: string;
  end;

在设计时存储这些数据的最佳方式是什么,以便以后在运行时检索?我会有大约20条记录,我知道每个记录的所有内容,但我坚持使用最好的方式存储数据。

What's the best way of storing this data at design-time for later retrieval at run-time? I'll have about 20 records for which I know all the contents of each "record" but I'm stuck on what's the best way of storing the data.

我想出的只有半个优雅的想法是在这个单元的初始化中创建每个记录:

The only semi-elegant idea I've come up with is "construct" each record on the unit's initialization like this:

var
  VulnerabilityData: array[Low(TVulnerability)..High(TVulnerability)] of TVulnerabilityData;

....

initialization
  VulnerabilityData[0].Vulnerability := vVulnerability1;
  VulnerabilityData[0].Name := 'Name of Vulnerability1';
  VulnerabilityData[0].Description := 'Description of Vulnerability1';
  VulnerabilityData[0].ErrorMessage := 'Error Message of Vulnerability1';

  VulnerabilityData[1]......
  .....
  VulnerabilityData[20]......

有没有比这更好的和/或更优雅的解决方案?

Is there a better and/or more elegant solution than this?

感谢阅读和您可能提供的任何见解。

Thanks for reading and for any insights you might provide.

推荐答案

您还可以将数组声明为const并初始化...



You can also declare your array as consts and initialize it...

const
  VulnerabilityData: array[Low(TVulnerability)..High(TVulnerability)] of TVulnerabilityData =
( 
    (Vulnerability : vVulnerability1; Name : Name1; Description : Description1;  ErrorMessage : ErrorMessage1),
    (Vulnerability : vVulnerability2; Name : Name2; Description : Description2;  ErrorMessage : ErrorMessage2),
[...]
    (Vulnerability : vVulnerabilityX; Name : NameX; Description : DescriptionX;  ErrorMessage : ErrorMessageX)
    )
);

我没有在这台电脑上仔细检查语法的IDE ...可能是逗号或两个丢失。但这是你应该怎么做我想。

I don't have an IDE on this computer to double check the syntax... might be a comma or two missing. But this is how you should do it I think.

这篇关于存储“记录阵列”的最佳方式在设计时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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