◆Delphi中有没有这样的伪指令?窗体建立时,窗体上的THotKey控件从全局数组中载入热键。
窗体上有16个THotKey控件当然可以像下面那样一个一个的手写,但是如果有100个1000个呢?
我想在编译阶段用简单的方法使THotKey控件与数组中的元素一一对应,就像是宏汇编中的重复汇编伪指令REPT那样!而不是在运行时遍历窗体上的所有组件判断是否是THotKey控件然后用对应的数组元素赋值。
Delphi中有没有这样的伪指令?或者其它的方法?var
  GArray: array[1..CiArrayN] of Integer; //热键procedure TForm2.FormCreate(Sender: TObject);
begin
  HotKey1.HotKey := GArray[1];
  HotKey2.HotKey := GArray[2];
  HotKey3.HotKey := GArray[3];
  HotKey4.HotKey := GArray[4];
  HotKey5.HotKey := GArray[5];
  HotKey6.HotKey := GArray[6];
  HotKey7.HotKey := GArray[7];
  HotKey8.HotKey := GArray[8];
  HotKey9.HotKey := GArray[9];
  HotKey10.HotKey := GArray[10];
  HotKey11.HotKey := GArray[11];
  HotKey12.HotKey := GArray[12];
  HotKey13.HotKey := GArray[13];
  HotKey14.HotKey := GArray[14];
  HotKey15.HotKey := GArray[15];
  HotKey16.HotKey := GArray[16];                            
end;
也就是说如何简化上面的写法?
比如说我想这样:(假设能用MASM宏汇编写的话)
  x = 1
  REPT 16
  HotKey&x.HotKey := GArray[&x]; //写的不对,领会精神吧。
  x = x + 1
  ENDM
编译的时候就展开成上面FormCreate中的那样,有办法吗?(重点是--在编译的时候展开) 如果没有答案就把分给回复的人分了。

解决方案 »

  1.   

    应该说没有。为什么不采用动态创建控件数组的方法呢?而且不见得比用宏的方法复杂多少。var
      GArray: array[1..CiArrayN] of Integer; //热键
      HotKey: array[1..CiArrayN] of THotKey;procedure TForm2.FormCreate(Sender: TObject);
    var
      i: Integer;
    begin
      for i:=Low(HotKey) to High(HotKey) do
      begin
        HotKey[i] := THotKey.Create(Self);
        HotKey[i].HotKey := GArray[i];
      end;
    end;
      

  2.   

    var i: integer;
    begin
       for i:=0 to 1000 do
       begin
         if FindComponent('HotKey' + IntToStr(i)) is THotKey then
         begin
            (FindComponent('HotKey' + IntToStr(i) as THotKey).HotKey := GArray[i];
         end;
       end;end;
      

  3.   

    To:DDGG(叮叮当当) 
    谢谢回复。
    如果动态创建THotKey控件的话还要计算它们的位置,我嫌麻烦。To:aiirii(ari-淘金坑)
    你说的这种是在运行期进行的,应该不是我要的效果,不过还是谢谢你。