Jump to content

dummzeuch

Members
  • Content Count

    2650
  • Joined

  • Last visited

  • Days Won

    92

Posts posted by dummzeuch


  1. 1 hour ago, PeterBelow said:

    if you organize your program's tasks into classes then you can replace nested procedures with private methods of the class and either pass needed values as parameters or move the local variables used as private fields to the class declaration. IMO that gives a much cleaner and easier to understand design, and it keeps down the size of the methods.

    Unless, of course you need a local type declaration that you don't want to be visible outside the unit. Such a type can be declared inside a procedure / method and used within that method and any nested procedure. To convert these nested procedures into methods, you will have to move the type declaration outside the main procedure/method. The same applies to constants.


  2. 3 hours ago, David Heffernan said:

    I always prefer to pass parameters because it makes it much clearer what the input/output of the function is. 

     

    Usually the so called convenience you refer to just leads to obfuscation. 

    In my opinion using this kind of variables falls into the same class as using break and continue in a loop. A little bit better than goto, a little bit worse than using exit.

    I use it sparingly, but as I said: Sometimes it is just convenient.


  3. Having read through this entire thread, I can only repeat what others already said: Changing the interface part of SysUtils requires recompiling nearly all other RTL and VCL units. That was already the case with Delphi 7.

     

    I also agree that this is most likely not the best solution to your actual problem.

     

    You said you needed a global variable in the interface section of SysUtils that multiple functions in that unit access. Which functions are you talking about and what is the purpose of this change? If you don't tell us, we can't suggest alternative solutions.

    • Like 3

  4. 1 hour ago, Lajos Juhász said:

    Also until developers did not start to use multiple languages.

    I have never ever confused Pascal Strings with C char* types. (And I have done quite a lot C programming at the beginning of my career, parallel to using Turbo Pascal and Visual Basic, before I chose Delphi as my main programming tool.)


  5. 3 hours ago, David Heffernan said:

    I don't disagree with that point. My point is that it was a bad idea in the first place to make strings 1 based.

    Depends. Back then (in the 1970ies *1) it made a lot of sense to store strings that way. And when moving from Pascal to Delphi (>20 years later) and introducing longstrings (Delphi 2?) it already was a decision between keeping backwards compatibility to Pascal vs. being compatible with C.

     

    Edit: (*1: I'm not sure when strings were introduced into Pascal: Was it an addition in Turbo Pascal (1986) or did they already exist in the original Pascal?)


  6. Since Delphi is kind of a legacy programming language nowadays, backwards compatibility is very important. You don't want to throw away millions lines of proven code because they don't work any more, or even worse, because they are now buggy. So trying to change strings to be zero based was a bad idea, even if it was "just for mobile platforms".

    • Like 3

  7. 5 hours ago, David Schwartz said:

    Aside from that, did you get anything from reading the post? (I don't have a compiler in my head, and I figured if I didn't show the declarations then someone would ding me on that.)

    My point is that you can't declare variables or types like this in Delphi. This is C like syntax. In Delphi you have to give a low and a high limit for an array. So at least you don't have to guess.


  8. 8 hours ago, David Schwartz said:

    Considering Delphi:

     

    Given this declaration: var ary[10] : char; str[10] : string;

    [dcc32 Error] Project1.dpr(10): E2029 ',' or ':' expected but '[' found
    [dcc32 Error] Project1.dpr(10): E2029 '(' expected but ';' found
    [dcc32 Error] Project1.dpr(10): E2029 Expression expected but ';' found
     

×