Recent

Author Topic: Few noob questions  (Read 4060 times)

GoDxNero

  • Jr. Member
  • **
  • Posts: 58
Few noob questions
« on: November 20, 2009, 02:28:23 pm »
Well I tried to search around in the forum but it seems like my question is to noob to have yet to be written.

Anyway I would like to ask what are the use of units ? Can I use it to divide my huge code into small divisions or like that ? Perhaps I saw somewhere people dividing their codes into many units. If so will it be better to use it for some really huge code or it doesnt matter ?

Secondly I got so much var that its painfull to look, so will this be good for the program if i do somethings like this:

var
point1, stats1 : String;
point2, stats2 : String;

Well its just an example of what I mean. I got like 50 + variable and I want to sort them to have a better look.
« Last Edit: November 20, 2009, 02:30:05 pm by GoDxNero »

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Few noob questions
« Reply #1 on: November 20, 2009, 02:54:03 pm »
Hi,
if you add new form to your application it has its own unit. You can also add only unit (without form). These units must be added in "uses section" of your code.
(In Lazarus in Menu: File->New Unit or File->New Form)

You can also separate long unit to include (*.inc or *.pp)  files. You can do it so: You select piece of your code and copy/paste it to new file. This file can be called for example:  myfile.inc . And you use directive {$I myfile.inc} on the place where you have taken the code. Easy.

I don't understand very well to your second question, you can do also this:

Code: [Select]
var point1, stats1,
    point2, stats2: String;
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

GoDxNero

  • Jr. Member
  • **
  • Posts: 58
Re: Few noob questions
« Reply #2 on: November 20, 2009, 03:52:45 pm »
thanks . Its still hard to see though. Is it allowed to add such comment Like //----- between those var lines ?

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Few noob questions
« Reply #3 on: November 20, 2009, 03:57:27 pm »
Yes, you can give comment anywhere you want.
//comment
or
{more lines
 comment}
Lazarus 2.3.0 (rev main-2_3-2863...) FPC 3.3.1 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12302
  • Debugger - SynEdit - and more
    • wiki
Re: Few noob questions
« Reply #4 on: November 20, 2009, 03:58:42 pm »
Secondly I got so much var that its painfull to look, so will this be good for the program if i do somethings like this:

var
point1, stats1 : String;
point2, stats2 : String;

Well its just an example of what I mean. I got like 50 + variable and I want to sort them to have a better look.

Group them, yes, but not just optical.

Your example above suggest that certein variables belong together, and certain of such groups are repaeted.

Code: [Select]
type
  TPoinStat = record
    Point: String;
    Stat: String;
  end;

var
  pstat1, pstat2: TPointStat;

Even better. probably you wil have bits and pieces of code related to them. like maybe compare with another point, if both values (or just one value is equal.

If there is enough code, consider a class of it's own, and move the code.

Consider
  if (point1 = point2) and (stat1 = stat2) then
and
  if pstats1.equals(pstat2) then

--------
Any comment is allowed.

Whatever helps you read your code.
If you work with others, you will establish common rules in the team.



 

TinyPortal © 2005-2018