안녕하세요 좋은생각입니다.
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.
어때요 쉽죠... 어떤 형태의 객체든지 클래스 변수를 사용하게 되면
그 객체를 변수로 담을 수가 있습니다.
클래스 변수에 관련된 내용을 찾아 보세요...
그럼 존 코딩 마니마니....
꿈의 언덕에서 /좋/은/생/각/
|