[fpc-pascal] Are there any drawbacks to "reference to"?
Hairy Pixels
genericptr at gmail.com
Mon Jun 20 15:46:22 CEST 2022
> On Jun 20, 2022, at 8:39 PM, Michael Van Canneyt via fpc-pascal <fpc-pascal at lists.freepascal.org> wrote:
>
> It allows you to run callbacks without having to declare variables globally:
>
> Function DoSomething : String;
>
> var
> L : TStringList;
>
> begin
> L:=TstringList.Create;
> SomeCallBack(procedure(s : string)
> begin
> L.Add(S);
> end
> );
> Result:=L.Text;
> L.free;
> end.
>
> With a regular procedure or procedure of object, you'd need to define L
> outside of DoSomething.
I think you could use “is nested” and it would work also but see my other email with my example of a plain procedure which seems to capture for some reason.
Regards,
Ryan Joseph
More information about the fpc-pascal
mailing list