Solved

[Rant] Funny limitations of Delphi 6...

Posted on 2006-11-06
10
278 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

724 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