数组键名和文件条目的更好关联是什么?

发布于 2024-10-09 07:02:43 字数 814 浏览 0 评论 0原文

资料来源:

  // write
  Path := 'Data/_prefixed' + dynarray1[v].Name;
  with XMLConfig1 do begin; 
      SetValue(Path  + '/RealName', dynarray1[v].Name);
  end;
  ..
  // read
  Path := 'Data/_prefixed' + listOfVars.Strings[v]; 
  with XMLConfig1 do begin;
     dynarray1[v].Name := GetValue(Path + '/RealName', '');
  end;

我考虑编写简单的宏,例如:

procedure getsetkey(Keyname,Var:string; var Value: **overloaded**; Direction: integer);
getset('Data/_prefixed'+Keyname, Var

但由于返回类型不同,它仍然是三个(整数、字符串、布尔)类似的函数(没有什么像?),或者是六个函数,如果我抛出 Direction 参数并得到一个集合setkeygetkey,或 key(重载:如果存在第 4 个参数则调用 set),(值允许为空,因此检查值不是决定的方法)

有什么方法可以缩短函数数量并将 dynarray1[v].Element_Name 与可以传递给 GetValue() 的键相关联?某种类似反射的 API 来访问键名?

Source:

  // write
  Path := 'Data/_prefixed' + dynarray1[v].Name;
  with XMLConfig1 do begin; 
      SetValue(Path  + '/RealName', dynarray1[v].Name);
  end;
  ..
  // read
  Path := 'Data/_prefixed' + listOfVars.Strings[v]; 
  with XMLConfig1 do begin;
     dynarray1[v].Name := GetValue(Path + '/RealName', '');
  end;

I think about writing simple macro like:

procedure getsetkey(Keyname,Var:string; var Value: **overloaded**; Direction: integer);
getset('Data/_prefixed'+Keyname, Var

but due to different return types it is still three (integer, string, boolean) similar functions (nothing like ?), or ever six function, if I throw out Direction argument and get a sets of setkey and getkey, or key(overload: call set if 4-th parameter presents), (Value is allowed to be empty, so checking the value isn't the way to decide)

Any way to shorten number of functions and to associate dynarray1[v].Element_Name with a key that may be passed to GetValue()? Some kind of Reflection-like API to access key names?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2024-10-16 07:02:43

变体会更合乎逻辑。如果您可以获得反射/RTTI 信息(例如您想要保存的所有内容都是已发布的属性),那也是可能的。

但恕我直言,对于 1 行函数的 3 种变体,就像用佳能在蚊子上射击一样

Variants would be more logical. If you can get reflection/RTTI info (e.g. everything you want to save is a published property) that is also possible.

But IMHO for 3 variants of a 1 line function that is like shooting with a canon on a mosquito

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文