Duplicating components at Run-Time

后端 未结 4 2027
鱼传尺愫
鱼传尺愫 2020-12-06 11:03

Is there a simple way to duplicate all child components under parent component, including their published properties?

For example:

  • TPanel
    • TLa
4条回答
  •  醉酒成梦
    2020-12-06 11:30

    You can write the source component into a stream and read it back into the target component.

    MemStream := TMemoryStream.Create;
    try
      MemStream.WriteComponent(Source);
      MemStream.Position := 0;
      MemStream.ReadComponent(Target);
    finally
      MemStream.Free;
    end;
    

    You may get problems with duplicate component names though.

提交回复
热议问题