BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

strange problem of source code disapearing?

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc
View previous topic :: View next topic  
Author Message
S Sheldon
Guest





PostPosted: Tue Feb 22, 2005 9:30 am    Post subject: strange problem of source code disapearing? Reply with quote



hi

I have a large'ish project consisting of several forms, and over 10 units
of code. I am having a problem adding 3 procedures to my main form. It looks
a bit like this:

tform1 = class(tform)
blah blah
blah blah
procedure NextEn1;
procedure NextEn2;
procedure NextEn3;
blah blah


I then have stub procedures further down in the code:

procedure tform1.nextEn1;
begin
end;

procedure tform1.nextEn2;
begin
end;

procedure tform1.nextEn3;
begin
end;

they are then called by:
procedure next;
begin
if ...... then nextEn1
else if ......... then nextEn2
else if ........... then nextEn3

But whenever I try and compile this both the stub procedures and their
declarations disappear from the source code and I am left with an error on
the line calling the procedure??

I am probably being really stupid.......

But can someone please help me to see the light here?

Thanks
D


Back to top
Peter Gertner
Guest





PostPosted: Tue Feb 22, 2005 10:46 am    Post subject: Re: strange problem of source code disapearing? Reply with quote



Hi,

If there is only whitespace between the begin and end of a procedure
or function, the compiler just removes the procedure, because he
recognizes that it is unnecessary.
You can simply put some comment in the stub procedures to make them
seem "usefull" to the compiler.
I'm not sure if this feature belongs to code optimization, it may also
work if you switch off optimization in the project properties, but
note that the compiler won't optimize anything if you do so.

Bye
Peter
--
Alles, was man tun muss, ist die richtige Taste zum richtigen
Zeitpunkt zu treffen.
- Johann Sebastion Bach
Back to top
J French
Guest





PostPosted: Tue Feb 22, 2005 10:52 am    Post subject: Re: strange problem of source code disapearing? Reply with quote



On Tue, 22 Feb 2005 09:30:38 -0000, "S Sheldon"
<Sarah_sheldon (AT) hotmail (DOT) com> wrote:

<snip>

Quote:
I then have stub procedures further down in the code:

procedure tform1.nextEn1;
begin
// <----- Put '//' in here
end;

procedure tform1.nextEn2;
begin
end;



Back to top
Rob Kennedy
Guest





PostPosted: Tue Feb 22, 2005 6:16 pm    Post subject: Re: strange problem of source code disapearing? Reply with quote

Peter Gertner wrote:
Quote:
Hi,

If there is only whitespace between the begin and end of a procedure
or function, the compiler just removes the procedure, because he
recognizes that it is unnecessary.
You can simply put some comment in the stub procedures to make them
seem "usefull" to the compiler.
I'm not sure if this feature belongs to code optimization, it may also
work if you switch off optimization in the project properties, but
note that the compiler won't optimize anything if you do so.

It has nothing to do with the optimization setting. The IDE simply
removes empty event handlers. The IDE considers any method declared in
the default published section of the class to be an event handler. If
the event handler is empty when the form gets saved, then the IDE
removes it from the class declaration and clears any event properties on
the form that refered to that handler. (As an exception to the "empty"
rule, methods that contain a single call to "inherited" are also removed
since they add nothing beyond the ancestor's implementation.)

Usually, this has no effect on the program. Actions, however, will
automatically disable themselves if they have no assigned OnExecute
event handler. An empty event handler is enough to keep one enabled, but
the IDE will work against you in that case.

The easy solution is to enter a comment in the event handler so it is no
longer empty. The comment is also the perfect place to explain why you
have a method without any code it in.

A better solution, in Sheldon's case, is to move the methods out of the
form's default published section. If he really needs those methods to be
published (and he probably doesn't), then he can declare an explicit
published section in the class. That tells the IDE that it is not to
touch those methods since they aren't event handlers. Declare the
methods with the lowest visibility necessary.

--
Rob

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> comp.lang.pascal.delphi.misc All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.