Title: Create Form Procedure
Question: I need to know if it is possible to pass the class name and a variable of that class into a procedure that will create the form. (Explained Below)
Answer:
I am trying to create a generic procedure that will allow me to check for an instance of a form, create the form is no instance is found, or simply show the form if it has already been created. To do this manually I can use the following code:
// Check to see if an instance has already been created
if Application.FindComponent('MyForm') = nil then
// No instance found, so create the form
MyForm := TMyForm.Create(Application);
// Show the form
RecSrcForm.Show;
This is sufficent and works, but I have an form in which I make many of these calls, so in the interest of optimizing the source code size, I want to be able to call a procedure like this:
OpenForm(MyForm,TMyForm);
I am trying to write something along the lines of this:
procedure OpenForm(aFormVariable: ?????; aFormClass: ?????);
begin
if Application.FindComponent(aFormVariable.Name) = nil then
aFormVariable := aFormClass.Create(Application);
end;
I'm not even sure if this is possible, but if it is, what types would I have to use for aVariable and aFormClass?