Forum > Beginners

overloading original FPC functions

(1/3) > >>

what is the danger here? I recently ran into issue with name that I liked being already taken by function that does something entirely different in System unit. I tried changing names, but eventually overloaded the function, everything else did not sound right. I remember from C# I think, I could change the order of "using" claim unit, so that correct function is being called. Or was there something about appending the function with unit name. "Overload" seem to be more assertive. But with my lack of experience, I am not sure if this won't bite me later. Please share your thoughts.

Curt Carpenter:
The question to ask yourself, in my opinion, is "which approach is kinder to someone in the future that may need to read this code?"

This should work

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Myunit.myfunctionname  //this call your functionFunctionname   //this call the default functin 

In general you are correct to assume that unit order matters, but in your case the original function is in system and the system unit is included implicitly, so that does not help very much.
For the same reason it is not a good idea to override or overload or reintroduce functions from system if, as you state, your function has a completely different meaning: suppose you need the functionality from system? Although it will work it is not good design.
@Paolo's answer is a good solution, but it is in my opinion a better solution to rename your function.
Note that this assumes that the function from system and your own function have the exact same parameter list and result. Otherwise there is - in mode objfpc - no need, because your function would be an implicit overload.
Still, that can cause problems. Better rename.

I think fpc should be more strict to prevent reusing things that should be reserved words. I once used Dec as a key for resource strings and the dec() function was no longer accessible


[0] Message Index

[#] Next page

Go to full version