Forum > FPC development
Defer Mechanism for FreePascal
Sniper:
Everybody who writes in Golang know about it's defer mechanism.
I found proposal of this useful thing for C (C2x)
http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2542.pdf
Do FPC core developers are interested in "defer" mechanism in freepascal?
marcov:
Sound like procedural form of exception handling. We already have such things in try.except and try.finally.
Bi0T1N:
--- Quote from: marcov on June 26, 2021, 01:31:17 pm ---Sound like procedural form of exception handling. We already have such things in try.except and try.finally.
--- End quote ---
I think that was also the outcome of the thread on the mailing list.
PascalDragon:
--- Quote from: Bi0T1N on June 26, 2021, 01:49:16 pm ---
--- Quote from: marcov on June 26, 2021, 01:31:17 pm ---Sound like procedural form of exception handling. We already have such things in try.except and try.finally.
--- End quote ---
I think that was also the outcome of the thread on the mailing list.
--- End quote ---
Correct. There is no need for a defer. A try … finally might be more verbose, but why sugar coat it?
Also e.g. Lazarus helps you out there quite a bit by completing a try to a try … finally, a tryf to a try … finally with the cursor in the finally-block and a trye to a try … except. And then there's the nifty trycf which will create the following code:
--- 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";}};} ---VarName := TMyClassName.Create;try finally VarName.Free;end;
Where the IDE highlights VarName and TMyClassName as editable blocks you can switch between with Tab (and editing VarName will edit both locations).
AlexTP:
@PascalDragon,
thanks for pointing that out. Offtopic: I am your fan, trying to read all your last messages. :)
Navigation
[0] Message Index
[#] Next page