Hi,
I'm stuck storing a constructor in a variable to avoid circular unit-dependencies. Those could be avoided by using correct subclasses, but that would break the purpose of event-driven-programming.
This is the constructor i want to pass:
//Unit TaskForm
TTaskForm = class(TForm)
constructor CreateNew(TheOwner: TComponent; ntinfo: TTaskInfo);
This is the class it is being passed to:
//Unit TaskPanel
TTaskFormConstructor = function(TheOwner: TComponent; ntinfo: TTaskInfo): TForm of object;
{ TTaskPanel }
TTaskPanel = class(TPanel)
constructor Create(TheOwner: TComponent; ntinfo: TTaskInfo;
nparentFormConstr: TTaskFormConstructor);
This is the assignment containing the assignment in question:
tmppanel := TTaskPanel.Create(Self, tmptask, TTaskFormConstructor(@TTaskForm.CreateNew) );
Yields this error:
taskform.pas(125,47) Error: Illegal type conversion: "<address of function(TComponent,TTaskInfo):TTaskForm of object;Register>" to "<procedure variable type of function(TComponent,TTaskInfo):TForm of object;Register>"
I want to avoid re-ordering the classes, because the inherited classes make use of the various TForm-Events - like OnMouseMove and such - and when those are reused in subclasses, my original handlers would be overriden.
kind regards, yogo1212
#Edit: changed names for clarity