Forum > Beginners
Nest assignment into if-statement
BrainChemistry:
Hi there,
I saw in C examples, expressions like "if (var = func()) = value {}" but I wonder if something like this is possible in Free Pascal?
Pseudo-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";}};} ---if ( ex_var := ex_func( ex_param ) ) = 0 thenbegin //whateverend;
Thanks for your help in advance.
BeniBela:
You can only do it like this:
--- Code: ---function assignwrap(out assignee: integer; const data: integer): integer;
begin
result := data;
assignee := data;
end;
if assignwrap(ex_var, ex_func(ex_param)) = 0 then ...
--- End code ---
Pascal is an ugly language
taazz:
--- Quote from: BrainChemistry on January 09, 2016, 01:12:36 am ---Hi there,
I saw in C examples, expressions like "if (var = func()) = value {}" but I wonder if something like this is possible in Free Pascal?
Pseudo-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";}};} ---if ( ex_var := ex_func( ex_param ) ) = 0 thenbegin //whateverend;
Thanks for your help in advance.
--- End quote ---
either
--- 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";}};} ---ex_var := ex_func( ex_param )if ( ex_var = 0) thenbegin //whateverend; or
--- 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";}};} --- if ( ex_func( ex_param ) = 0) thenbegin //whateverend;
BrainChemistry:
--- Quote from: BeniBala ---Pascal is an ugly language
--- End quote ---
Very rarely, but sometimes yes :-\.
The wrapping solution is nice but makes it more lines of code, that is what I'd like to prevent :-).
--- Quote from: taazz ---
--- 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";}};} ---ex_var := ex_func( ex_param )if ( ex_var = 0) thenbegin //whateverend;
--- End quote ---
Yes, that is what I rather did before. The idea was to change it into one line.
--- Quote from: taazz ---
--- 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";}};} ---if ( ex_func( ex_param ) = 0) thenbegin //whateverend;
--- End quote ---
I need to work with the return value afterwards, so this solution is neat but not suitable in my case.
Thanks you two for clearification :)!
taazz:
--- Quote from: BrainChemistry on January 09, 2016, 10:53:06 am ---The wrapping solution is nice but makes it more lines of code, that is what I'd like to prevent :-).
--- End quote ---
Not really you just make sure you have a unit with overloaded functions for most of the basic types somewhere and use that when needed. Its a nice solution and not to different from your original showcase.
Navigation
[0] Message Index
[#] Next page