有没有更有效的方法来做下面的事情?基本上,我想引用tMemo名称mcpx,而不是像下面这样直接引用对象名称:
if x = 1 then mcp1.Lines.Append(inttostr(cp[x]));
if x = 2 then mcp2.Lines.Append(inttostr(cp[x]));
if x = 3 then mcp3.Lines.Append(inttostr(cp[x]));
if x = 4 then mcp4.Lines.Append(inttostr(cp[x]));
if x = 5 then mcp5.Lines.Append(inttostr(cp[x]));发布于 2019-07-13 01:35:34
在现代的Delphi中,将memos放入数组中非常容易。然后,正如Sertac Akyuz所提到的,使用数组索引访问它们,并跳过if。
Var
MemoArray : array of TMemo;
...
MemoArray := [mcp1,mcp2,mcp3,mcp4,mcp5];
...
// Zero based dynamic array, so need to do the - 1, no need for the if
MemoArray[x-1].Lines.Append(IntToStr(cp[x]));https://stackoverflow.com/questions/57011438
复制相似问题