[Rant] Funny limitations of Delphi 6...

Well, I happen to be working on a big project and one function tends to be a bit complex. And I get this weird error:

[Warning] ImportExportDataModule.pas(1013): Return value of function 'Limitation' might be undefined

Well, I simplified the whole code to the following:

function Limitation: string;
var
  V00, V01, V02, V03, V04, V05, V06, V07, V08, V09: string;
  V10, V11, V12, V13, V14, V15, V16, V17, V18, V19: string;
  V20, V21, V22, V23, V24, V25, V26, V27, V28, V29: string;
  V30, V31: string;
begin
  Result := '';
end;

And yes, I set the return value of this function correctly. And I get about 30 hints about unused variables. But ignore the hints. Focus on the warning! Why does it generate this warning?

Well, a simple count of the number of variables within this function just reveals that I have 32 variables. Plus one for the result, making a total of 33. If I would remove any one of them then my problem is gone! No more warning by just removing one of them...

It makes me feel real sad though to realise that Delphi has such a strange limitation. Makes me wonder why it gives an error and if it has any effects on how the generated code will run. It's one of those things that make me feel real uncomfortable inside...

Oh, well. Done with the ranting. Time for the question... Where does this limit come from, where is it documented and what will happen if I just ignore it? And what happens with procedures that have over 32 variables? Do they have similar limitations too?

But most important question: Can this warning be ignored without ANY risks?
LVL 17
Wim ten BrinkSelf-employed developerAsked:
Who is Participating?
 
KyanarCommented:
The astounding part is the last comment on QC Entry 735 (http://qc.borland.com/wc/qcmain.aspx?d=735)

"Still exists in Delphi 2006"
0
 
ziolkoCommented:
first of all why use 32 string variables?? isn't it better to use TStringList???

ziolko
0
 
ziolkoCommented:
...or array[0..31] of string
ziolko.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

 
ziolkoCommented:
You can go to Project -> Options -> Complier -> Syntax Options and uncheck Strict var-strings and warning should go away :)
ziolko.
0
 
Wim ten BrinkSelf-employed developerAuthor Commented:
@ziolko, I already have a solution! (Reduce number of variables) but I'm asking about the "Why?"... :-)

The datatype used for the local variables matters little. What matters is the datatype of the function itself. If I return an integer, pointer, object then I don't get this warning. If I return a string, a variant or an IUnknown interface then I will get this warning. It has to do with the way Delphi puts them on the stack or whatever. The following code will generate the same result:

function Limitation: IUnknown;
var
  V00, V01, V02, V03, V04, V05, V06, V07, V08, V09,
  V10, V11, V12, V13, V14, V15, V16, V17, V18, V19,
  V20, V21, V22, V23, V24, V25, V26, V27, V28, V29,
  V30, V31: boolean;
begin
  Result := nil;
end;

The original code used about 35 different variables. It needed 5 parameters (3 of them optional) and the other 30 variables all had their purpose. I did reduce them by using an array but had to alter some code for it to use an array instead. Basically, this function was one that had grown over time. It's purpose was to transform an XML file to another format using MSXML/XSLT and the XSLT file wanted several parameters. As things developed, more and more parameters were added to the XSLT file (most of them easily calculated) but every parameter resulted in one additional parameter in the local variables. Of course, the easy fix was putting all those parameters in a single array and then passing that array to the XSLT.

It is not that I need to have a solution here. I need reassurance that this warning has no effects on my code. I have become a bit suspicious now because Delphi didn't give me a more appropiate warning about this.

So, basically -half-answering my own question now- what happens is that the compiler will add space on it's stack for 32 local variables. Now, if the function result can be returned in the AH/AX/EAX registers of the processor (like with integers, booleans and pointers) or in ST(0) of the Floating point processor then Delphi won't generate this error. However, for other datatypes the compiler is acting a bit different. In those cases the compiler adds a temporary location (on the stack, I think) to contain this value and my fear is that this location is overwritten by one of the local variables, thus this would be a compiler bug. Or whatever...
0
 
ziolkoCommented:
yeah I think I've "jumped the gun" a bit, I haven't look who aksed this question:)
anyway, I strated palying with such a function and yup I've noticed that it's function result that matters:
- changed result to shortstring - no warning
- changed variables type to boolean (function result left as string) - warning is still there


ziolko.
0
 
Wim ten BrinkSelf-employed developerAuthor Commented:
@ziolko: Yep, when I ask a Delphi question, it generally tends to be a lot more difficult than the average Q's here at EE. :-)

@Kyanar, thanks for finding that link! At least now I know that upgrading to D2006 would NOT solve this bug. Still leaves only one question, though. Does this warning mean that my data (or possibly the stack) might get corrupted if I just ignore it? In other words, is it save to ignore?
0
 
Wim ten BrinkSelf-employed developerAuthor Commented:
Oh, well. Time to close this Q. We'll just have to wait for a response from Borland about this. Kyanar, thanks for the link!
0
 
WallaceAdrianCommented:
Which version of Delphi are you using? I tried it on 2005 and I don't get the problem.
0
 
Wim ten BrinkSelf-employed developerAuthor Commented:
It failed in Delphi 6 and apparantly it still goes wrong in Delphi 2006 although I haven't had a chance to test this...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.