Am I able to pass a procedure to another procedure as a variable.
I am currently generating a PopupMenu on dynamically according to files found in a specified directory structure.
I have a procedure that does this, currently I am passing parameters including the TPopupMenu itself, a string for the directory to perform the search in along with an integer indicating the number of levels to go down in the search.
Ideally I also want to introduce the passing of a variable which is itself a procedure.
Suppose I have the calling form (MainForm) which passes its TPopupMenu component to the procedure in the unit (MenuBuild) to set up the TPopupMenu as required. I have a procedure 'Proc1' which I want to have set as the 'OnClick' event for each of the TMenuItems I have against the TPopUpMenu. I had thought that I may have been able to pass this as a parameter to the procedure in the 'MenuBuild' unit using something like 'SetupPopupMenu(PopupMenu1, ..., Proc1)' which would set the 'OnClick' event for each added TMenuItem accordingly.
However I get presented with the error 'Incompatible types : method pointer and regular procedure'
How can I get round this ?
Am I able to pass a procedure as a parameter to another procedure ?
Hope that this makes sense to people and that someone can give me some advice with this.
Thanks in advance
Steve
I am currently generating a PopupMenu on dynamically according to files found in a specified directory structure.
I have a procedure that does this, currently I am passing parameters including the TPopupMenu itself, a string for the directory to perform the search in along with an integer indicating the number of levels to go down in the search.
Ideally I also want to introduce the passing of a variable which is itself a procedure.
Suppose I have the calling form (MainForm) which passes its TPopupMenu component to the procedure in the unit (MenuBuild) to set up the TPopupMenu as required. I have a procedure 'Proc1' which I want to have set as the 'OnClick' event for each of the TMenuItems I have against the TPopUpMenu. I had thought that I may have been able to pass this as a parameter to the procedure in the 'MenuBuild' unit using something like 'SetupPopupMenu(PopupMenu1, ..., Proc1)' which would set the 'OnClick' event for each added TMenuItem accordingly.
However I get presented with the error 'Incompatible types : method pointer and regular procedure'
How can I get round this ?
Am I able to pass a procedure as a parameter to another procedure ?
Hope that this makes sense to people and that someone can give me some advice with this.
Thanks in advance
Steve