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

但由于不同的返回类型,它仍然是三个(整数、字符串、布尔值)类似的函数(不像?),或者曾经有六个函数,如果我抛出方向参数并得到一组setkeyand getkey,或者,(允许key(overload: call set if 4-th parameter presents)为空,因此检查值不是决定的方法)

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

4

1 回答 1

1

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

但是恕我直言,对于 1 行功能的 3 种变体,就像在蚊子上用大炮射击一样

于 2011-01-02T01:11:07.663 回答