Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did not understand the question completely, so i will answer all of the cases that could occur:</p> <ol> <li>If you did not understand how 2 of my <code>CountWords</code> examples differ: First one creates and frees class instance each time it is called. Second one only creates class instance on first call, then uses it till the program terminates.</li> <li>If you mean how would that differ if you created a singleton and implemented <code>CountWords</code> in it: it wouldn't differ in functionality, but you would have to write a whole new class for it, then initialize it on program start and use it later. Besides there's a lot of criticism on using singletons (see wiki for more info), so i wouldn't do that.</li> <li>If you are asking about the actual work these two example functions are performing: they obviously yield same results, but first one isn't optimized for running in environment that calls this function a lot. As i said before, you could reach same results by declaring a global variable, but if you do that - you will see your global variable everywhere in your program, whereas it is only needed in one specific location and nowhere else.</li> </ol> <p>P.S. I was actually wrong about <code>const</code> function parameters, it turns out these things behave differently in different delphi versions. Const parameters acted just the same as <code>var</code> parameters in Delphi 6, but in Delphi XE2 it seems local variable is created anyway. Either way i do not recommend messing with <code>const</code> function parameters.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload