Forum > General

Hint: Local variable xx of a managed type does not seem to be initialized

<< < (2/4) > >>

Igor Kokarev:
According this article:
https://www.freepascal.org/docs-html/ref/refse20.html
Managed types already initialized by default (nil).

For example, I create a local variable WideString and pass it as var variable to another function.
It should be initialized as nil by default. However Lazarus 2.0 generates:

"project1.lpr(18,12) Hint: Local variable "Str" of a managed type does not seem to be initialized"


--- 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 project1; {$mode objfpc}{$H+} uses  Classes; procedure Test2(var Str: WideString);begin  Str:='wegweg';end; procedure Test1;var  Str:    WideString;begin  Test2(Str);  WriteLn(Str);end; begin  Test1;  ReadLn;end. 

lucamar:
You're right; the only thing that works is "Hide message by inserting IDE directive {$H-}". In fact, selecting to insert "{$warn 5092 off}" really inserts "{$warn 5092 on}" instead.

It's easy to change that "on" to "off" but it's very clearly a bug. You should report it in the bug tracker.

Igor Kokarev:
If I call the popup menu from Messages window and call "Hide with project option (-vm5091)". It does NOT work.

I have to add manually -vm5091 the Custom Options.

P.S. Another minor problem in Messages window. I see 2 hints:

Hint: Start of reading config file C:\lazarus64\fpc\3.0.4\bin\x86_64-win64\fpc.cfg
Hint: End of reading config file C:\lazarus64\fpc\3.0.4\bin\x86_64-win64\fpc.cfg

Althought I have default mode "Filter Verbose Messages and Below".

Igor Kokarev:

--- Quote from: lucamar on February 06, 2019, 01:44:19 pm ---You're right; the only thing that works is "Hide message by inserting IDE directive {$H-}". In fact, selecting to insert "{$warn 5092 off}" really inserts "{$warn 5092 on}" instead.

--- End quote ---
Yes, but it works only for one unit. We have many units where this hints occur.

As I wrote earlier, this hint is useless, because managed types are initialized by default by FPC.

lucamar:

--- Quote from: Igor Kokarev on February 06, 2019, 02:00:07 pm ---As I wrote earlier, this hint is useless, because managed types are initialized by default by FPC.

--- End quote ---

Take the String type, for example: An empty string is initialized to Nil. If you then try to access the characters as if it were an array, say with something like:

--- 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 MyString[1] = 'A' then ...the result will be an exception. The hint, quite properly, simply tells you that maybe you forgot that possibility.

Most hints are of that kind: they attract your attention to something that may need some intervention. If you're usually careful then most of them seem useless ... until that time when you were not careful enough. An example, with other hint that you've probably seen hundred of times, the one saying: "Unused parameter 'Sender'". Mostly useless ... until you see instead "Unused Parameter 'AnotherThing'"; then you know something may be wrong in your code.

That's what hints are for: it's the compiler's way of saying "Excuse me but, are you sure this is what you meant?"

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version