Recent

Author Topic: Stuff at the beginning of a new program?  (Read 5772 times)

undermanager

  • Jr. Member
  • **
  • Posts: 58
Stuff at the beginning of a new program?
« on: August 13, 2012, 11:35:23 pm »
When I start a new program, I get a lot of 'stuff' apearing (see below). I usually delete this from my Pascal programs, and everything always works fine. Why is it there if it doesn't affect my programs? What (Non-techy explanation) is this code doing? I have searched for a simple explanation of what all this is but can't find anything below Einstein level.

Thanks.


program project1;

{$mode objfpc}{$H+}

uses


  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };
{$R *.res}   

Blaazen

  • Hero Member
  • *****
  • Posts: 3241
  • POKE 54296,15
    • Eye-Candy Controls
Re: Stuff at the beginning of a new program?
« Reply #1 on: August 13, 2012, 11:56:04 pm »
{$mode} are Pascal dialects. There can be Delphi or TP (TurboPascal) for better compatibility. Keep the objpas, it's the best.
{$H+} is type of strings. Keep it. http://www.freepascal.org/docs-html/prog/progsu23.html#x29-280001.1.23

This stuff
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}

is important if you are planning to use Threads in unix/linux (or in a multiplatform application).
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/

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Stuff at the beginning of a new program?
« Reply #2 on: August 13, 2012, 11:58:31 pm »
Quote
I have searched for a simple explanation of what all this is but can't find anything below Einstein level.
Does this and this sound Einstein to you?

undermanager

  • Jr. Member
  • **
  • Posts: 58
Re: Stuff at the beginning of a new program?
« Reply #3 on: August 14, 2012, 01:18:05 am »
Thanks Blaazan.

Can you tell me how to use a Pascal library like Crt or sysutils, please. I get an error with hte following, although if I comment out the stuff above Crt, it all works fine:

program project1;

{$mode objfpc}{$H+}

uses

  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes
  { you can add units after this };

  Crt;


{$R *.res}

begin
  writeln('Hello world');
  readln();

end.




{$mode} are Pascal dialects. There can be Delphi or TP (TurboPascal) for better compatibility. Keep the objpas, it's the best.
{$H+} is type of strings. Keep it. http://www.freepascal.org/docs-html/prog/progsu23.html#x29-280001.1.23

This stuff
  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}

is important if you are planning to use Threads in unix/linux (or in a multiplatform application).

typo

  • Hero Member
  • *****
  • Posts: 3051
Re: Stuff at the beginning of a new program?
« Reply #4 on: August 14, 2012, 02:32:37 am »
Code: [Select]
program project1;

{$mode objfpc}{$H+}

uses

  {$IFDEF UNIX}{$IFDEF UseCThreads}
  cthreads,
  {$ENDIF}{$ENDIF}
  Classes,
  Crt, SysUtils
  { you can add units after this };

{$R *.res}

begin
  writeln('Hello world');
  readln();
end.

undermanager

  • Jr. Member
  • **
  • Posts: 58
Re: Stuff at the beginning of a new program?
« Reply #5 on: August 14, 2012, 03:07:27 am »
Thanks. I'm never going to get the hang of when to use / not use commas and semicolons in Lazarus!!

 :D

howardpc

  • Hero Member
  • *****
  • Posts: 4144
Re: Stuff at the beginning of a new program?
« Reply #6 on: August 14, 2012, 07:21:25 am »
The Pascal rule is straightforward: every Pascal statement has to end in a semicolon, thus:
Pascal statement 1;
Pascal statement 2;
Pascal statement 3;

This means it is simple for the compiler to parse the source, which is one reason Pascal compilers are fast.

Commas are mostly used to separate items within a Pascal statement, so in a uses statement
Code: [Select]
uses Classes;
does not need a comma (only one item in the list),

whereas the statements:
Code: [Select]
uses Classes, Dialogs;

Code: [Select]
uses Classes, Dialogs, SysUtils;
do need commas, since there is more than one item in the list.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8836
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Stuff at the beginning of a new program?
« Reply #7 on: August 14, 2012, 08:06:17 am »
Quote
The Pascal rule is straightforward: every Pascal statement has to end in a semicolon
Correction: Pascal statements are separated rather than terminated by semicolon. The semicolon is read as "and then" in English.

 

TinyPortal © 2005-2018