Monday, June 2, 2008

How To Pass A Class Into Function/Procedure?

define the class type as follow... assuming that you are going to pass in a generic TFrame.

type TFrameClass=class of TFrame;

procedure TForm1.CreateSomething(FrameClass: TFrameClass; const Caption: String);
var
F: TFrame;
begin
F := FrameClass.Create(Self);
F.Label1.Caption := Caption;
end;

...
...

begin
CreateSomething(TMyFrame, 'Test);
end.

No comments: