Thanks for the fix, but it makes the code a bit more complicated than I'd hoped/thought based on my (over simple?) impression that local fns are used in place of those in units. John<br><br><div class="gmail_quote">On 18 November 2011 16:55, Sven Barth <span dir="ltr"><<a href="mailto:pascaldragon@googlemail.com">pascaldragon@googlemail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Am 18.11.2011 17:47, schrieb John Lee:<div><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Sorry for confusion, my email wasn't clear...<br>
old fpc version, that I have to use because of availability of various<br>
units...Free Pascal Compiler version 2.2.2 [2008/08/03] for i386<br>
<br>
this is jim.pp---<br>
unit jim;<br>
interface<br>
function fna:string;<br>
function fnb:string;<br>
<br>
implementation<br>
function fna:string;<br>
begin<br>
fna:='jim';<br>
end;<br>
function fnb:string;<br>
begin<br>
fnb:=fna;<br>
end;<br>
end.<br>
<br>
this is fred.pp---<br>
uses jim;<br>
<br>
function fna:string;<br>
begin<br>
fna:='fred';<br>
end;<br>
<br>
begin<br>
writeln(fnb);<br>
end.<br>
<br>
This writeln gives jim, ie the version in jim - I'd like it to be fred &<br>
thought that it would! What can I do please, to _force_ fnb to use the<br>
fred version of fna?<br>
</blockquote>
<br></div></div>
As I said per se this is expected, because the "jnb" in "jim" only knows about the "jna" in "jim", but not about the "jna" in your main program.<br>
<br>
Possible solution:<br>
<br>
Extend your unit "jim" the following way (this is the "function variable" approach I mentioned):<br>
<br>
=== unit jim begin ===<br>
<br>
unit jim;<br>
<br>
interface<br>
<br>
type<br>
TStringFunc = function: String;<br>
<br>
function fna: String;<br>
function fnb(aFunc: TStringFunc = Nil): String;<br>
<br>
implementation<br>
<br>
function fna: String;<div class="im"><br>
begin<br>
fna := 'jim';<br>
end;<br>
<br></div>
function fnb(aFunc: TStringFunc): String;<br>
begin<br>
if Assigned(aFunc) then<br>
fnb := aFunc<br>
else<br>
fnb := fna;<br>
end;<br>
<br>
end.<br>
<br>
=== unit jim end ===<br>
<br>
And your main program will then look like this:<br>
<br>
=== main program begin ===<br>
<br>
uses jim;<br>
<br>
function fna: String;<div class="im"><br>
begin<br>
fna := 'fred';<br>
end;<br>
<br>
begin<br></div>
writeln(fnb(@fna)); // will print "fred"<br>
writeln(fnb); // will print "jim"<br>
end.<br>
<br>
=== main program end ===<br>
<br>
For further information about procedure/function variables I refer you to the documentation: <a href="http://www.freepascal.org/docs-html/ref/refse17.html#x45-520003.6" target="_blank">http://www.freepascal.org/<u></u>docs-html/ref/refse17.html#<u></u>x45-520003.6</a><br>
<br>
Of course you are free to ask further questions if you need help on this or another topic. ;)<div class="HOEnZb"><div class="h5"><br>
<br>
Regards,<br>
Sven<br>
______________________________<u></u>_________________<br>
fpc-pascal maillist - <a href="mailto:fpc-pascal@lists.freepascal.org" target="_blank">fpc-pascal@lists.freepascal.<u></u>org</a><br>
<a href="http://lists.freepascal.org/mailman/listinfo/fpc-pascal" target="_blank">http://lists.freepascal.org/<u></u>mailman/listinfo/fpc-pascal</a><br>
</div></div></blockquote></div><br>