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

델파이 Q&A
Delphi Programming Q&A
[6320] [답변] CITYHOCK/ 변수값으로 폼 동적생성
dashform [ ] 1116 읽음    1999-06-23 09:08
안녕하세요 좋은생각입니다.

Form Class명을 변수로 받아 폼을 생성할수 있습니다.

그럼 태스팅 프로그램 소스를 보면

Unit1, Unit2에 다른 원하는 폼을 만든다음 이를 Form Class명을

변수로 받아 어떻게 만드는가를 보겠습니다.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
    ComboBox1: TComboBox;
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure ComboBox1Change(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  a  : array[1..2] of TComponentClass;

implementation

uses Unit3, Unit2;

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
     a[1] := TForm2;
     a[2] := TForm3;
end;

procedure TForm1.ComboBox1Change(Sender: TObject);
var
   aa : TComponent;
   b  : Integer;
begin
   if combobox1.text = 'Form2' then
      b := 1
   else if combobox1.text = 'Form3' then
      b := 2;

   aa := a[b].Create(Self);
   TForm(aa).Show;
end;

end.

어때요 쉽죠... 어떤 형태의 객체든지 클래스 변수를 사용하게 되면

그 객체를 변수로 담을 수가 있습니다.

클래스 변수에 관련된 내용을 찾아 보세요...

그럼 존 코딩 마니마니....

                            꿈의 언덕에서  /좋/은/생/각/


+ -

관련 글 리스트
6320 [답변] CITYHOCK/ 변수값으로 폼 동적생성 dashform 1116 1999/06/23
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.