[fpc-pascal] TThread.Queue vs TThread.Synchronize
Sven Barth
pascaldragon at googlemail.com
Mon Feb 23 20:38:54 CET 2015
On 23.02.2015 20:24, Philippe Lévi wrote:
> may be I do not catch it well ... problem with my english understan ... may be. "we'll get" ... you mean some day it should be possible to program it? .... correct?
>
> you mean it will be possible to use a pointer to local function in a call?
>
> or I misunderstand ...
Yes, it's future tense. And also there's the "I hope".
Also under certain circumstances you can already pass local procedures
to other functions (requires 2.7.1 or newer):
=== code begin ===
program tnested;
{$mode objfpc}{$H+}
{$modeswitch nestedprocvars}
type
TProc = procedure is nested;
procedure WriteStr(const aMsg: String);
begin
Writeln(aMsg);
end;
procedure AnotherTest(aProc: TProc);
begin
aProc();
end;
procedure Test;
var
s: String;
procedure PrintStr;
begin
Writeln(s);
end;
begin
s := 'Hello World';
AnotherTest(@PrintStr);
end;
begin
Test;
end.
=== code end ===
There is however an important difference to anonymous functions: If you
- in this example - leave the scope of "Test" the variable "s" will no
longer be valid. An anonymous function on the other hand will capture
that variable and will allow the use of the procedure variable even
later on.
E.g. the following would work with anonymous methods, but not with
nested procedure variables:
=== code begin ===
type
TStringProc = reference to procedure; // this will work
//TStringProc = procedure is nested; // this will not work
function Test: TStringProc;
var
s: String;
procedure PrintStr;
begin
Writeln(s);
end;
begin
s := 'Hello World';
Result := @PrintStr;
end;
=== code end ===
Of course the above only applies if we should managed to get local
procedures supported for anonymous function variables...
Regards,
Sven
More information about the fpc-pascal
mailing list