Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Any other way to comment without it always appearing inline with code

Status
Not open for further replies.

ProgressingPilgrims

Programmer
Apr 4, 2008
4
US
Is there a way to attach programmer notes to any code line, such that one could for example leave an explanation in an otherwise hidden text box that pops up when a programmer wishes to read a perhaps longer explanation than one would want to include by commenting out a line with //?
 
Not without adding code which would just add complexity, and since you would be writing the code to do such a thing anyway (and writing the text), you might as well just write the text to begin with. If it helps:

Code:
// This is a short comment meant for the same line as a code

Code:
{ but this is also a comment and I can type as long as I want until I type the closing curly brace like this }

----------
Measurement is not management.
 
Actually there is, though not what it was intended for, it works:
Code:
//doube click file-name below to read my comments
{$I mycomments.inc}

To test it, copy and paste the above into any form, then do what it says. If it does not exist, the IDE will open a dialog box with 3 choices:
o Create a new Form
o Create a new Unit
o Create a new Textfile

Select Textfile.

My mycomments.inc file contains:
Code:
(* type as much text as you want *)


Roo
Delphi Rules!
 
roo I'm trying to do what you said in the unit of my dll where I need the functionality, so dropped the two lines into the middle of some procedure code but if I double click on {$I mycomments.inc} it just becomes editable like any other text. I also tried it in the interface section without avail

What am I missing?
 
Errata:
Code:
//press ctrl-enter on file-name below to read my comments
{$I mycomments.inc}
:p

Roo
Delphi Rules!
 
Sorry Pilgrim, I realized my mistake and posted the correction. Then saw you'd already tried it and failed. I said double-click out of habit. Ctrl-Enter should work.

Include files were once common in the dos-pascal days...
Delphi still supports them. Can contain code or comments.

HTH

Roo
Delphi Rules!
 
While this technically works, it has two problems from a code management standpoint:

1) Will the file be kept with the app and be recognized as part of the app? And if so, will the maintainer (you, or someone else) think to pop into it every once in a while to update the comments? Comments in this way are very prone to be either lost or deprecated very easily. Deprecated comments, IMO, are much worse than not commenting code at all.

2) Ultimately, either your co-workers, or your predecessor (assuming this is for a company/contractor) will likely look at it and wonder what in the world you were thinking. And likely will take the file and pull it back into the main source anyway muttering under their breath about "what this guy was on while he did it".

3) Very non-standard and would likely not pass code-review for the reasons I stated above, along with numerous others.

----------
Measurement is not management.
 
you can always use regions (depends on your delphi version)

so you can fold/expand a longer documenting section

use these tags

{$REGION 'code comments'}
{$ENDREGION}


/Daddy

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Glenn - Good point(s). Note that include files can contain full path BUT fails if long file (folder) names contain spaces. IE: the following will fail:
{$I \\MYSERVER\Users\USERNAME\My Documents\mycomments.inc}

I totally agree - Not recommended for corporate use.
A simple comment referencing a company spec.doc would be more appropriate.

Daddy - D7 reported "Invalid compiler directive 'REGIONS'". :-(

OT - A friend just brought back some pictures from eastern Europe where someone was driving a garden tiller down the highway.

Roo
Delphi Rules!
 
You guys are great. I tried both methods successfully. I think I like the region folding since it stays with the code instead of an external file. But the external file created with {$I mycomments.inc} will be handy for proprietary comments in the trading systems development in that it would not be available to someone hacking into the source code.

All the best!
 
Roo,

there are other versions than D7. It are new features likes this that ease my daily programmming. While D7 was the most stable version Borland ever produced (no doubt about that!), it is getting old...

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top