Ian Branch 127 Posted March 31, 2019 Hi Team, I think, from time to time I have seen a function embedded in another function. I think. Something like.. function foobar(param1, param2: string): string; var somevar: string; begin function inside(Param3: string): string; var anothervar: string; Begin Do something with Param3; .... ... Result := anothervar; end; ... Somevar := inside(somestring); Result := Somevar; end; Is this doable? If so, what is the mechanism for it pls? Why do I want to do this? So I can embed a function in the main function and not have to have it as a separate app function. Regards & TIA, Ian Share this post Link to post
Remy Lebeau 1398 Posted March 31, 2019 (edited) Yes, it is doable, but the syntax is slightly different than you showed. The inner function has to be defined before the 'begin' of the outer function, eg: function foobar(param1, param2: string): string; var somevar: string; function inside(Param3: string): string; var anothervar: string; Begin Do something with Param3; ... Result := anothervar; end; begin Somevar := inside(somestring); Result := Somevar; end; This is covered in Embarcadero's documentation: Nested Routines Edited March 31, 2019 by Remy Lebeau 1 Share this post Link to post