From: Marc@landscap.demon.co.uk (Marc Palmer)
Subject: Re: Delphi, how could you be better?
Date: Wed, 19 Apr 1995 14:05:56 +0000

Hey - try this. It will create an instance of the class specified in the
GetClass call. This is all standard Delphi stuff - it's just not documented
well :

procedure TForm1.FormCreate(Sender: TObject);
begin
{ This only works for classes registered using RegisterClass 
  I don't know if there are standard routines for registering *all* Delphi's
  standard classes. }
  RegisterClasses([TButton, TForm]);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  CRef : TPersistentClass;
  PTI : PTypeInfo;
  AControl : TControl;
begin
  CRef := GetClass('TButton');
  if CRef<>nil then
  begin
     AControl := TControl(TControlClass(CRef).Create(Self));
     with AControl do
     begin
        Parent := Self;
        Width := 50;
        Height := 30;
     end;
     Inc(Id);
  end else MessageDlg('No such class', mtWarning, [mbOk], 0);
end;

Anyone with comments/tips on this let me know.

********************************************************************
* Marc P.                               E-Mail me for PGP 2.6 key  *
*                                                                  *
* "Most of the ideas I have at the moment have to do with things   *
* that are completely impossible, so I am wary about sharing them. *
* They are, however, the only thoughts I have." - Dirk Gently      *
********************************************************************





