Forum > Beginners

undef not working?

(1/1)

srvaldez:
it seems that undef doesn't work or perhaps I am doing something wrong?

--- Code: ---program undef_test;

var
MySymbol:longint;
{$undef MySymbol} 
{$ifndef Mysymbol} 
Mysymbol:double;
{$endif}
begin
writeln(sizeof(Mysymbol));
end.

--- End code ---

TRon:
Defines work with (compile time) symbols not identifiers/variables.


--- 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";}};} ---program undef_test; {$define this_symbol}var  {$ifdef this_symbol}  variable_identifier : longint;  {$undef this_symbol}  {$else}  variable_identifier : double;  {$endif} begin  {$if declared(variable_identifier)}  writeln(sizeof(variable_identifier));  {$endif}end. 
See Compiler defines during compilation for more information on defines that are present during compilation. That is besides symbols that you can declare yourself (as per example or at the command-line with option -d)

If you want to check if a Pascal symbol is declared or not the you can use {$if declared(symbol_name)}, see also Compile time expressions, in particular the chapter Definition

edit: modified example code to make the example more clear and added if declared example.

srvaldez:
thanks TRon :)

Navigation

[0] Message Index

Go to full version