C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[71676] Re:동적으로 생성한 콤포넌트를 기존 팔레트에서 생성한 콤포넌트와 속성을 같게 하려면...
둘리.CSIEDA [dooly386] 3224 읽음    2014-08-20 11:49
MemoryStream 이든 뭐든 stream 만들어서 WriteComponent 시키고

이쪽에서 ReadComponent 하시면....


아래 코드는 Delphi 코드지만 C++ 로 금방 바꾸실수 있으실듯. 참조하세요...



uses
  TypInfo;

procedure CloneProperties(const Source: TControl; const Dest: TControl);
var
  ms: TMemoryStream;
  OldName: string;
begin
  OldName := Source.Name;
  Source.Name := ''; // needed to avoid Name collision
  try
    ms := TMemoryStream.Create;
    try
      ms.WriteComponent(Source);
      ms.Position := 0;
      ms.ReadComponent(Dest);
    finally
      ms.Free;
    end;
  finally
    Source.Name := OldName;
  end;
end;

procedure CloneEvents(Source, Dest: TControl);
var
  I: Integer;
  PropList: TPropList;
begin
  for I := 0 to GetPropList(Source.ClassInfo, [tkMethod], @PropList) - 1 do
    SetMethodProp(Dest, PropList[I], GetMethodProp(Source, PropList[I]));
end;

procedure DuplicateChildren(const ParentSource: TWinControl;
  const WithEvents: Boolean = True);
var
  I: Integer;
  CurrentControl, ClonedControl: TControl;
begin
  for I := ParentSource.ControlCount - 1 downto 0 do
  begin
    CurrentControl := ParentSource.Controls[I];
    ClonedControl := TControlClass(CurrentControl.ClassType).Create(CurrentControl.Owner);
    ClonedControl.Parent := ParentSource;
    CloneProperties(CurrentControl, ClonedControl);
    ClonedControl.Name := CurrentControl.Name + '_';
    if WithEvents then
      CloneEvents(CurrentControl, ClonedControl);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  DuplicateChildren(Panel1);
end;

레쓰비 님이 쓰신 글 :
: 동적으로 생성한 에디트 박스를 기존 팔레트에서 생성한 에디트 박스의 모든 속성과 같게 하고 싶은데요...
: 아래 코드와 같이 일일이 하나하나 다 지정하는 방법 말고 간단히 하는방법이 없을까요??
:
: // ((TEdit *)tcmp_edit) --> 동적생성 EditBox 를 나타냅니다.
: //  EditBox1 --> 팔레트에서 생성한 EditBox 를 나타냅니다.
:
: ((TEdit *)tcmp_edit)->Width = EditBox1->Width;
: ((TEdit *)tcmp_edit)->Height = EditBox1->Height;
:    ...
:    ...
:    ...
:    ...
:    ...

+ -

관련 글 리스트
71670 동적으로 생성한 콤포넌트를 기존 팔레트에서 생성한 콤포넌트와 속성을 같게 하려면... 레쓰비 2997 2014/08/18
71676     Re:동적으로 생성한 콤포넌트를 기존 팔레트에서 생성한 콤포넌트와 속성을 같게 하려면... 둘리.CSIEDA 3224 2014/08/20
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.