Initialising a record lazarus / 21-General ---------------------------------------------------------------------- mtanner · 2021-04-25 08:47 This is not a very important question, just one of those niggling coding questions, and one which would frequently save me a line of code if I could do it. I suspect the answer might teach me something interesting about Lazarus/FPC.. I define a record, say TStuff=record    A:double;   { detailed fields not important }    B:integer; end; and a const: const StuffZero:TStuff=(A:Nan;B:zero); and I can then code var MyStuff:TStuff; MyStuff:=StuffZero; but I cannot code: var MyStuff:TStuff=StuffZero; It puzzles me why this is so when I can code var X:double=0; and similarly for user-defined scalar variables. ---------------------------------------------------------------------- wp · 2021-04-25 09:35 This is because of the peculiar construct (inherited from Turbo Pascal) that a typed "const" with initialization is not a constant, but an initialized variable. Therefore, it is not known whether StuffZero has not been changed along the way until it is assigned to MyStuff. Likewise, the following simpler code does not work either: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // This does not work because "zero" is not necessarily constantconst  zero: Integer = 0;var  x: Integer = zero; // But this works because zero cannot be changedconst  zero = 0;var  x: Integer = zero; ---------------------------------------------------------------------- mtanner · 2021-04-25 10:17 Thanks, useful to understand. Just out of curiosity, does  C/C++ have similar initialisation constructs? ---------------------------------------------------------------------- korba812 · 2021-04-25 10:37 There is a workaround for this problem by using macros or "management operators": Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program Project1; {$MACRO ON}{$modeswitch ADVANCEDRECORDS} uses  Math; type   { TStuff }   TStuff=record    A:double;   { detailed fields not important }    B:integer;    class operator Initialize(var ARec: TStuff);  end; const  Zero = 0; {$define StuffZero:=(A: Nan; B: Zero)} var  MyStuff: TStuff = (A: Nan; B: Zero);  MyStuff2: TStuff = StuffZero;  MyStuff3: TStuff; { TStuff } class operator TStuff.Initialize(var ARec: TStuff);begin  ARec.A := Nan;  ARec.B := Zero;end; begin  WriteLn(MyStuff.A);  WriteLn(MyStuff2.A);  WriteLn(MyStuff3.A);end. ---------------------------------------------------------------------- Thaddy · 2021-04-25 13:08 You can also call Default() to initialize records. Aside: NaN should be detectable, but not assignable. In general, indeed, you can use the management operator as described above. Technically, though, initializing to NaN at compile time should throw an error. Same with infinity too. Regarding other languages: I am not aware of C++ (certainly not C) being able to do that at compiler level. That would be library level. There are no intrinsics for this scenario in C style languages. The gish is that both NaN and infinity can not be logically expressed as a constant. (And obviously, they are not!) NaN - 1 is undefined, Infinity + 1 is still infinity.... ---------------------------------------------------------------------- jamie · 2021-04-25 13:50 Quote from: mtanner on April 25, 2021, 10:47:08 amThis is not a very important question, just one of those niggling coding questions, and one which would frequently save me a line of code if I could do it. I suspect the answer might teach me something interesting about Lazarus/FPC.. I define a record, say TStuff=record    A:double;   { detailed fields not important }    B:integer; end; and a const: const StuffZero:TStuff=(A:Nan;B:zero); and I can then code var MyStuff:TStuff; MyStuff:=StuffZero; but I cannot code: var MyStuff:TStuff=StuffZero; It puzzles me why this is so when I can code var X:double=0; and similarly for user-defined scalar variables. it's a compiler deficiency and all the blanket theories does not help in the cause. Be glad you have what you got. I need to check Delphi but I wonder if it even supports doing this with the basic types? ---------------------------------------------------------------------- Thaddy · 2021-04-25 14:02 Quote from: jamie on April 25, 2021, 03:50:53 pmit's a compiler deficiency No it is not. It it pure logic. At the most the issue at hand describes some deficiency in Boolean logic.. which happens to be the basis of modern computing.... ---------------------------------------------------------------------- PascalDragon · 2021-04-25 19:36 Quote from: jamie on April 25, 2021, 03:50:53 pmit's a compiler deficiency and all the blanket theories does not help in the cause. Be glad you have what you got. I need to check Delphi but I wonder if it even supports doing this with the basic types? The behavior is the same in Delphi and even TP. ---------------------------------------------------------------------- jamie · 2021-04-25 19:40 Quote from: PascalDragon on April 25, 2021, 09:36:36 pmQuote from: jamie on April 25, 2021, 03:50:53 pmit's a compiler deficiency and all the blanket theories does not help in the cause. Be glad you have what you got. I need to check Delphi but I wonder if it even supports doing this with the basic types? The behavior is the same in Delphi and even TP. I checked Delphi, unless there is a switch I don't have on, I can not initialize the variables in the VAR section with Delphi, Fpc can do that. this is with 10.3, I can check 10.4 tomorrow.. ---------------------------------------------------------------------- PascalDragon · 2021-04-25 19:46 Quote from: jamie on April 25, 2021, 09:40:48 pmQuote from: PascalDragon on April 25, 2021, 09:36:36 pmQuote from: jamie on April 25, 2021, 03:50:53 pmit's a compiler deficiency and all the blanket theories does not help in the cause. Be glad you have what you got. I need to check Delphi but I wonder if it even supports doing this with the basic types? The behavior is the same in Delphi and even TP. I checked Delphi, unless there is a switch I don't have on, I can not initialize the variables in the VAR section with Delphi, Fpc can do that. this is with 10.3, I can check 10.4 tomorrow.. I am talking about global variables and constants. No one here said anything about local variables. For local variables FPC indeed allows initialization while Delphi does not, but FPC follows the same rules as for global variables which behave the same between FPC and Delphi. ---------------------------------------------------------------------- lucamar · 2021-04-25 21:08 Quote from: Thaddy on April 25, 2021, 04:02:04 pmQuote from: jamie on April 25, 2021, 03:50:53 pmit's a compiler deficiency No it is not. It it pure logic. Note that it happens (the compiler error) even if {$J-} (or {$WRITEABLECONST OFF} or -Sj-) is specified, which although "understandable" is not quite as logical ---------------------------------------------------------------------- mtanner · 2021-04-28 09:27 Thanks for all the info. Just a couple of comments. Nan is a valid state for a double variable, and if it is detectable than I do not see why it should not be assignable. I have a fairly complicated set of routines for evaluating the performance (meaning a vector/record of several different measurements) of systems which are similar but with important differences, such that some measurements are not relevant for some system variants. So it is useful to set the vector of measurements to Nan at the start of each evaluation routine, so that a calling routine can detect that some particular measurement value has not been calculated (either because it is not relevant, in which case the calling routine has a bug by trying to use it, or because the evaluation routine has a bug in that it is not providing a result that it should do. I am here using Nan to mean "undefined" rather than "numerically invalid". I get the fact that compatibility with Delphi is important, but would it be sensible/possible to have an alternative to "const", say "constfix" to declare a record that really is constant, not just an initialised variable as in Delphi, and it could then be possible to write constfix FixRec:TMyRec=(A:0;B:Nan,.... ... var LclRec:TMyRec=FixRec; A related question is that I can write var X:double=123; var Y:double=123; but not var X,Y:double=123; The last statement seems to me completely unambiguous, and would be usefully more concise. ---------------------------------------------------------------------- Thaddy · 2021-04-28 09:48 https://en.wikipedia.org/wiki/NaN ---------------------------------------------------------------------- mtanner · 2021-04-28 10:59 Thaddy, I will study the link you gave with interest. Seems like particle physics, ask a question and the answer just leads to deeper questions! ---------------------------------------------------------------------- mtanner · 2021-04-28 11:06 Perhaps the "correct" way for what I am trying to achieve is to use variant variables, and then a variable that had not been assigned a meaningful result would be empty. Trouble with that is likely to be the performance impact of the numerically intensive work I do. ---------------------------------------------------------------------- Thaddy · 2021-04-28 11:07 NaN and Infinity are merely something every profesional programmer has to face at least once in their carreer. A deeper understanding of what those mean is therefor essential. ---------------------------------------------------------------------- winni · 2021-04-28 11:14 Hi! a) NaN / Nan ≠ 1 b) ∞ + 42 = ∞ Winni ---------------------------------------------------------------------- PascalDragon · 2021-04-28 11:15 Quote from: mtanner on April 28, 2021, 11:27:45 amI get the fact that compatibility with Delphi is important, but would it be sensible/possible to have an alternative to "const", say "constfix" to declare a record that really is constant, not just an initialised variable as in Delphi, and it could then be possible to write constfix FixRec:TMyRec=(A:0;B:Nan,.... ... var LclRec:TMyRec=FixRec; No. The compiler simply can not handle such constructs without larger rework which we are not intending to do. Quote from: mtanner on April 28, 2021, 11:27:45 amA related question is that I can write var X:double=123; var Y:double=123; but not var X,Y:double=123; The last statement seems to me completely unambiguous, and would be usefully more concise. This is by design. ---------------------------------------------------------------------- Zvoni · 2021-04-28 14:06 I'm trying to wrap my mind around the fact, that someone wants to use a constant record. IIRC, a constant (e.g. Const MY_USELESS_CONST:Integer = 42;) is just a symbol used in Source-code for readability, and during compilation that symbol is replaced with the actual (constant) value. It's also the reason why it took so much time for me to get used, that in Laz/FPC we can use Constant Arrays (which, coming from a vb6-background, i couldn't understand) So, how in the name of the holy 8 bits, is a constant record supposed to work? Especially if you have different types for the record-members (Integers, Doubles, Strings, Woolen Socks....) Am i wrong?!?! ---------------------------------------------------------------------- Thaddy · 2021-04-28 14:09 Quote from: winni on April 28, 2021, 01:14:44 pmHi! a) NaN / Nan ≠ 1 b) ∞ + 42 = ∞ Winni You understand it. You should name your math teacher or professor... ---------------------------------------------------------------------- lucamar · 2021-04-28 14:22 Quote from: Zvoni on April 28, 2021, 04:06:33 pmSo, how in the name of the holy 8 bits, is a constant record supposed to work? Especially if you have different types for the record-members (Integers, Doubles, Strings, Woolen Socks....) One way is to think of it as if it were a collection of constants with simpler types, so you have "normal" constants which are refered by names such as: Myrecord.TheString and MyRecord.WoolenSocks instead of plain TheString or WoolenSocks. Only problem is that, unlike with simple types, the compiler doesn't (yet?) know to interpret constant records in the absence of a type so they have to be declared as typed constants which behave somewhat differently than "normal" untyped ones, hence giving rise to threads like this one. ---------------------------------------------------------------------- Thaddy · 2021-04-28 14:26 Quote from: lucamar on April 28, 2021, 04:22:05 pmOne way is to think of it as if it were a collection of constants with simpler types, so you have "normal" constants which are refered by names such as: Myrecord.TheString and MyRecord.WoolenSocks instead of plain TheString or WoolenSocks. In Dutch we say Foei! You know better than that. Although the concepts of NaN and Infinity are strange for people that are only relying on add and substract... And YOU know... ---------------------------------------------------------------------- lucamar · 2021-04-28 14:50 Quote from: Thaddy on April 28, 2021, 04:26:21 pmQuote from: lucamar on April 28, 2021, 04:22:05 pmOne way is to think of it as if it were a collection of constants with simpler types, so you have "normal" constants which are refered by names such as: Myrecord.TheString and MyRecord.WoolenSocks instead of plain TheString or WoolenSocks. In Dutch we say Foei! You know better than that. Although the concepts of NaN and Infinity are strange for people that are only relying on add and substract... And YOU know... I was answering (maybe badly, I admit) to Zvoni's post, where he says: "how in the name of the holy 8 bits, is a constant record supposed to work?". Nothing to do with NaN, Infinity or the prize of sheep in Alaska Though it's very flattering that you consider that I know about those things ---------------------------------------------------------------------- mtanner · 2021-04-28 14:56 To PascalDragon. I entirely understand the point that something on my wish-list might require a lot of work, disproportionate to any benefit. I am not in a position to judge how much work on the compiler might be required. But I asked the original question because (a) Maybe I can code something  a better way, but don't know how to (b) Dumb questions can be very educational (c) From my own experience of supporting my own users, sometimes they ask for an enhancement I had not thought about, but realise I can provide it with very little effort. (d) If you don't ask you generally don't get. So when you say a new construct, or marginal benefit, would take a lot of effort, I appreciate the point. I am though puzzled by your comment on var X:double=123; var Y:double=123; is ok but not var X,Y:double=123; when it is permissible to code var X,Y:double; In the spirit of asking dumb questions to learn something, why is this "by design". I cannot think what sort of design consideration would lead to this restriction. Unless it is simply a TP/Delphi quirk which has to be followed for compatibility. ---------------------------------------------------------------------- wp · 2021-04-28 14:59 Quote from: mtanner on April 28, 2021, 04:56:02 pmvar X,Y:double=123; I would very much appreciate to have such a feature. The annoying hints of FPC 3.2.+ about uninitialized variables could be removed very elegantly this way. ---------------------------------------------------------------------- lucamar · 2021-04-28 15:09 Quote from: mtanner on April 28, 2021, 04:56:02 pmI am though puzzled by your comment on var X:double=123; var Y:double=123; is ok but not var X,Y:double=123; when it is permissible to code var X,Y:double; In the spirit of asking dumb questions to learn something, why is this "by design". I cannot think what sort of design consideration would lead to this restriction. Unless it is simply a TP/Delphi quirk which has to be followed for compatibility. I'm not, by far, PascalDragon but AFAIR when this has been discussed the feel of the developers (and others) was that allowing that construction introduced some sintactic ambiguity (e.g. whether it was only Y that would end up initializad or both Y and X) that would lower the strictness of Pascal sintax. Note, among other things, that such a sintax would allow for e.g. a long list of initialized vars, each in its own line: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var{Suppose it much longer!}  a,  b,  c,  d,  e: Integer = 0; If you now want to discard var e or add a long comment in the middle of the list or some such operation the code might lose some clarity leading to compile- or run-time errors. Generally speaking, it was felt that loosing the "simplicity" and strictness of Pascal for so little (perceived) advantage wasn't worth the effort. At least that's what I understood ---------------------------------------------------------------------- mtanner · 2021-04-28 15:39 Lucamar, Thanks for your comment.  I don't myself see any ambiguity in var X,Y:double=123; But maybe I'm biased by my experience a long time ago with IBM's PL/I. A good language in it's day, although it had the unfortunate feauture of the opposite of strict data-typing. You could try and assign any variable type to any other variable type, and PL/I would try and find a built-in coversion routine.  I think this may have been the influence of COBOL (one of the few languages I have never used much), since PL/I was designed to combine the features of COBOL, Fortran, and Algol I think. I found the advent of strict data typing in Turbo Pascal a great advantage, since it basically turned run-time bugs into compile-time messages. Anyway, enough history, but PL/I did, as far as I recall, allow Declare X,Y:float=123; and also X,Y,Z:=0;  meaning that all three variables are assigned the value 0; I never found any ambiguity in these constructs. ---------------------------------------------------------------------- speter · 2021-04-28 23:20 Maybe the following could work (as being less ambiguous): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var  a = b = c : double = 123; cheers S. ---------------------------------------------------------------------- mtanner · 2021-04-29 06:48 speter, Not too keen on that notation. Everyone seems content that var X,Y,Z:double; means the variables X,Y,Z denote double values. The description after the colon is applied to the list before the colon.  So var X,Y,Z:double=123; should be interpreted in the same way, the description after the colon applies to the preceeding list. It's very similar to arithmetic operator precedence, the "," forming the list has greater precedence" than the ":". ---------------------------------------------------------------------- PascalDragon · 2021-04-29 07:12 Quote from: Zvoni on April 28, 2021, 04:06:33 pmI'm trying to wrap my mind around the fact, that someone wants to use a constant record. Why not? Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const  NullPoint: TPoint = (x: 0; y: 0); Quote from: Zvoni on April 28, 2021, 04:06:33 pmIIRC, a constant (e.g. Const MY_USELESS_CONST:Integer = 42;) is just a symbol used in Source- code for readability, and during compilation that symbol is replaced with the actual (constant) value. What you describe is only true for untyped constants, e.g. Const MY_USELESS_CONST = 42. A typed constant, like your example of const MY_USELESS_CONST: Integer = 42 is for all intents and purposes similar to a variable with the exception that you can't write to it (at least if writable consts are disabled with $J-). Such a typed constant has memory reserved in the binary's data area and you can use a pointer to it. For untyped constants that is not the case, they neither have space in the resulting binary nor can you take a pointer to them. Quote from: Zvoni on April 28, 2021, 04:06:33 pmSo, how in the name of the holy 8 bits, is a constant record supposed to work? Especially if you have different types for the record-members (Integers, Doubles, Strings, Woolen Socks....) Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i type  TWoolType = (    Sheep,    Cotton,      Bambus  );   TWoolenSocks = record    &Type: TWoolType;    Color: TColor;  end;   TMyRecord = record    i: Integer;    d: Double;    s: String;    w: TWoolenSocks  end; const  MyRecord: TMyRecord = (i: 42; d: 3.141; s: 'Hello World'; w: (&Type: Bambus; Color: clRed)); Quote from: lucamar on April 28, 2021, 05:09:30 pmQuote from: mtanner on April 28, 2021, 04:56:02 pmI am though puzzled by your comment on var X:double=123; var Y:double=123; is ok but not var X,Y:double=123; when it is permissible to code var X,Y:double; In the spirit of asking dumb questions to learn something, why is this "by design". I cannot think what sort of design consideration would lead to this restriction. Unless it is simply a TP/Delphi quirk which has to be followed for compatibility. I'm not, by far, PascalDragon but AFAIR when this has been discussed the feel of the developers (and others) was that allowing that construction introduced some sintactic ambiguity (e.g. whether it was only Y that would end up initializad or both Y and X) that would lower the strictness of Pascal sintax. Note, among other things, that such a sintax would allow for e.g. a long list of initialized vars, each in its own line: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i var{Suppose it much longer!}  a,  b,  c,  d,  e: Integer = 0; If you now want to discard var e or add a long comment in the middle of the list or some such operation the code might lose some clarity leading to compile- or run-time errors. Generally speaking, it was felt that loosing the "simplicity" and strictness of Pascal for so little (perceived) advantage wasn't worth the effort. At least that's what I understood From the compiler's point of view there is no ambiguity. Technically that functionality would be possible without much problem. But it's indeed that it could lead to obscure bugs if one needs to adjust more complex var section and forgets that there is a initialization some lines further down. Take such a section from FPC's parser for example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i          var           srsym: tsym;           srsymtable: TSymtable;           hdef: tdef;           pd: tprocdef;           orgstoredpattern,         storedpattern: string;           callflags: tcallnodeflags;         t : ttoken;           consumeid,           wasgenericdummy,         allowspecialize,           isspecialize,           unit_found, tmpgetaddr: boolean;           dummypos,           tokenpos: tfileposinfo;           spezcontext : tspecializationcontext;         cufflags : tconsume_unitsym_flags;  If the Booleans would have e.g. = True and I miss that when adding a new Boolean variable that should be False and I also miss to initialize it (been there, done that!) the compiler will not warn that the variable is not initialized (like it would now!) and I might need to debug a while to find out what's wrong. While one could argue that a = True is harder to miss in e.g. an IDE that does nice highlighting of things there is also the possibility that it's less obvious if macros come into play: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$define IsTrue := = True} var  Foo: Boolean IsTrue; ---------------------------------------------------------------------- Zvoni · 2021-04-29 08:09 Quote from: PascalDragon on April 29, 2021, 09:12:34 amCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i const  NullPoint: TPoint = (x: 0; y: 0);OK, understood and accepted. QuoteWhat you describe is only true for untyped constants, e.g. Const MY_USELESS_CONST = 42. A typed constant, like your example of const MY_USELESS_CONST: Integer = 42 is for all intents and purposes similar to a variable with the exception that you can't write to it (at least if writable consts are disabled with $J-). Such a typed constant has memory reserved in the binary's data area and you can use a pointer to it. For untyped constants that is not the case, they neither have space in the resulting binary nor can you take a pointer to them. Just to see, if i understood it correctly: So during "Code-Design" (don't have a better word for it) use untyped Constants for readability, since the compiler is going to replace the Symbol with the actual value (if i use the Const 259 times in my code, the compiler is going to replace the symbol with the value 259 times). And since it's an untyped literal value you can't get a pointer to it, since you compare to the value itself instead of the value stored at some memory-address (as in a variable, or as you said: a typed constant) Correct? ---------------------------------------------------------------------- PascalDragon · 2021-04-29 11:22 Quote from: Zvoni on April 29, 2021, 10:09:47 amQuoteWhat you describe is only true for untyped constants, e.g. Const MY_USELESS_CONST = 42. A typed constant, like your example of const MY_USELESS_CONST: Integer = 42 is for all intents and purposes similar to a variable with the exception that you can't write to it (at least if writable consts are disabled with $J-). Such a typed constant has memory reserved in the binary's data area and you can use a pointer to it. For untyped constants that is not the case, they neither have space in the resulting binary nor can you take a pointer to them. Just to see, if i understood it correctly: So during "Code-Design" (don't have a better word for it) use untyped Constants for readability, since the compiler is going to replace the Symbol with the actual value (if i use the Const 259 times in my code, the compiler is going to replace the symbol with the value 259 times). And since it's an untyped literal value you can't get a pointer to it, since you compare to the value itself instead of the value stored at some memory-address (as in a variable, or as you said: a typed constant) Correct? Essentially, yes. ---------------------------------------------------------------------- Thaddy · 2021-04-29 11:53 Indeed, but also note it is much more efficient. To some this may be counter-intuitive. ---------------------------------------------------------------------- Zvoni · 2021-04-29 12:03 OK, thx. Which brings us back neatly to the original Post of "Constant record": Since a record is always "typed", it basically behaves like any other variable (or in the context of the discussion: as a typed constant): Meaning: it is (constant) "data" somewhere in memory, which has actually been allocated (contrary to untyped constant as in the discussion before). Which brings us back to my original question: Why would someone like to have a "feature" like a constant record? Since you don't gain anything noteworthy except maybe a "writeprotect". Initialize that record (using Advanced Record methods --> Constructor, Default-Function), and never use it left of a ":=" (this includes passing it to a function/procedure, which does the assignment). ---------------------------------------------------------------------- PascalDragon · 2021-04-30 07:11 Quote from: Zvoni on April 29, 2021, 02:03:29 pmWhich brings us back to my original question: Why would someone like to have a "feature" like a constant record? Since you don't gain anything noteworthy except maybe a "writeprotect". Initialize that record (using Advanced Record methods --> Constructor, Default-Function), and never use it left of a ":=" (this includes passing it to a function/procedure, which does the assignment). And that write protection is the important part. Of course you could say in some comment "hey, never write to this", but what if someone does? Depending on where and how such a variable is used this could be a potential attack vector for a malicious coder or simply be a source of bugs e.g. what if my null point mentioned above is suddenly changed to (100 / - 40)? Also, back in the Turbo Pascal days, typed constants (which were always writeable), could be used as static variables inside functions, essentially being a kind of "poor man's scoping": Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$J+} procedure Test;const  Val: Integer = 0;begin  Writeln(Val);  Inc(Val);end; begin  Test; // will print 0  Test; // will print 1end. ---------------------------------------------------------------------- lucamar · 2021-04-30 09:58 Quote from: PascalDragon on April 30, 2021, 09:11:07 amAlso, back in the Turbo Pascal days, typed constants (which were always writeable), could be used as static variables inside functions, [snip] They can be used in exactly the same way in FPC too, in case you didn't know ---------------------------------------------------------------------- PascalDragon · 2021-04-30 13:45 Quote from: lucamar on April 30, 2021, 11:58:53 amQuote from: PascalDragon on April 30, 2021, 09:11:07 amAlso, back in the Turbo Pascal days, typed constants (which were always writeable), could be used as static variables inside functions, [snip] They can be used in exactly the same way in FPC too, in case you didn't know I probably should have mentioned that my example was done with FPC ---------------------------------------------------------------------- garlar27 · 2021-04-30 15:41 Quote from: mtanner on April 25, 2021, 10:47:08 amThis is not a very important question, just one of those niggling coding questions, and one which would frequently save me a line of code if I could do it. [...] Well I had a similar problem 9 years ago. And this is the solution: Quote from: Martin_fr on April 05, 2012, 05:14:37 pmHave you tried Code: [Select]procedure MyFillByte(out x;count:SizeInt;value:byte); begin   FillByte(x, count,value); end; AFAIK the "out" resets all the managed types However if you use AllocMem, then you must (once, the first time) use the real fillbyte I've been using that solution for almost a decade and it works like a charm. Long story short: The problem I had initially was a memory leak when using FillByte(MyRecordVar, SizeOf(MyRecordVar)); when the record had a "string" or an "array of" field and Martin_fr gave me the perfect solution.