Solved

[Rant] Funny limitations of Delphi 6...

Posted on 2006-11-06
10
270 Views
Last Modified: 2012-05-05
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?
0
Comment
Question by:Wim ten Brink
10 Comments
 
LVL 21

Expert Comment

by:ziolko
ID: 17881332
first of all why use 32 string variables?? isn't it better to use TStringList???

ziolko
0
 
LVL 21

Expert Comment

by:ziolko
ID: 17881399
...or array[0..31] of string
ziolko.
0
 
LVL 21

Expert Comment

by:ziolko
ID: 17881450
You can go to Project -> Options -> Complier -> Syntax Options and uncheck Strict var-strings and warning should go away :)
ziolko.
0
 
LVL 17

Author Comment

by:Wim ten Brink
ID: 17881795
@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
 
LVL 21

Expert Comment

by:ziolko
ID: 17882084
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 3

Accepted Solution

by:
Kyanar earned 500 total points
ID: 17895466
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
 
LVL 17

Author Comment

by:Wim ten Brink
ID: 17896281
@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
 
LVL 17

Author Comment

by:Wim ten Brink
ID: 17912990
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
 
LVL 2

Expert Comment

by:WallaceAdrian
ID: 17913024
Which version of Delphi are you using? I tried it on 2005 and I don't get the problem.
0
 
LVL 17

Author Comment

by:Wim ten Brink
ID: 17913073
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

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now