PDA

View Full Version : noob question about lazarus



will57
18-12-2010, 09:09 PM
hi all,

I'm a total newb to Pascal and this is my first post on these forums.


My question is really simple. I've installed Lazarus on my computer with the required extras.

I'm following a tutorial and the program is supposed to write some lines of text to the screen but nothing appears. What I do get is a box saying execution stopped or something like it.

Here's the code :


program Kitty_Cat;

begin
Writeln('This program');
Writeln('actually does something.');
Writeln(' hey' );
readln
end.




{ Result of execution

This program
actually does something.

}

sadly the program doesn't do anything.


Any ideas what I need to do to get the text written to the screen ?

Thanks for any help.

JSoftware
19-12-2010, 12:07 AM
Try to run it from a command line. That should at least show something

What platform are you on?

code_glitch
19-12-2010, 12:08 AM
did you build/compile the code before running it? Try ctrl + f9 in the program code before running. You should get a 'compiled successfully' or something along those lines message and then try running it. Also, did you make a CONSOLE program? or custom program? Lazarus gets on my nerves because it always assumes you want to make a lcl program. Which I don't. Ever.

Edit: darn it Jsoft. Got in there right before me... ;)

will57
19-12-2010, 12:39 AM
<quote>

Also, did you make a CONSOLE program? or custom program?

</quote>


Thanks for the replies guys. I think you've caught the problem there. I think I made it an application not a program so I guess that's what it was.

I was using using Mandriva but I've since reinstalled windows because I didn't like mandriva much. Too many passwords to put in!

I'll start the tutorials again now. Hopefully I'll get a bit further this time.

Is it a good idea to switch from C to Pascal ?

C was driving me nuts so I thinking that's one reason.

Thanks again.

de_jean_7777
19-12-2010, 03:11 AM
Try to add the {$APPTYPE CONSOLE} directive at the top of your programs source. This will make the program compile as a console program as Lazarus by default assumes programs are GUI. Or go to Project > Project Options > Linking and untick checkbox next to "win32 gui application" or similar.

You can get a better description of the APPTYPE directive here (http://www.freepascal.org/docs-html/prog/progsu79.html#x86-850001.2.3).

imcold
19-12-2010, 11:16 AM
Lazarus gets on my nerves because it always assumes you want to make a lcl program. Which I don't. Ever.

Use New Project -> Program for non-lcl progs.

WILL
19-12-2010, 09:07 PM
Welcome to PGD!

Unfortunately as everyone else has been indicating, Windows being a visual platform, doesn't bring up a command prompt (aka DOS prompt) screen for you so you won't see that it actually IS executing, it's just not showing you the text that was printed. Actually it probably did show you it just opened the prompt window and closed it so fast you could have possibly seen it. :)

If you do open a command prompt it'll show it as once opened, the command prompt will stay open as an active program shell and act just like good old DOS. :)

The same here can be said for programs compiled for Linux and Mac OS X as well. With the exception that Linux programs will likely keep a "terminal" (same thing as the command prompt) open after execution unless told to do otherwise as the beginning of your program.

And yes switching to Pascal to learn concepts of programming is always a good idea. Pascal was created to teach programming and has grown to be a very strong and useful language over the many years it's been in use. After you've learned the basics of programming in Pascal you can eventually move on to learning Object Oriented Programming with Object Pascal too which brings programming to a whole new level and lets you be more organized as you make bigger and more complex programs.

Hope some of this helps and you stick with our community. Each person asking questions and helping others makes this site all the more nicer to visit. :)

code_glitch
19-12-2010, 10:04 PM
Erm - sorry to say this will but you blundered a little. In his original code he does have a readln statement at the end... And yes, I missed it the first time - who doesn't? otherwise everything else is right on the money. As always. :D

On my lazarus I would do
Project -> New Project -> New Custom Program.
Its the one that is NOT maintained by lazarus as I find it counter - productive for it to add code I specifically don't want there... But some people find it useful, like half of the community whom use lazarus and tell me its leagues ahead of my plain text IDEs like Geany and programmers notepad. Oh well - I gave it a few goes - it bugged my and I returned to my IDEs. Although the debugger is wonderful - don't let anyone tell you different - I find I prefer ultimate control over my code. Just like sudo mode - it just does it. No questions asked. ;)

WILL
20-12-2010, 01:43 AM
Erm - sorry to say this will but you blundered a little. In his original code he does have a readln statement at the end... And yes, I missed it the first time - who doesn't? otherwise everything else is right on the money. As always. :D

Ah right! Ok, it would pause until you hit the return key, but then it would disappear. Perhaps Vista and Windows 7 treat command prompts differently than Windows XP and previous?

code_glitch
20-12-2010, 10:20 AM
Nope, it would disappear. But on ubuntu if you just launch the program without $APPTYPE CONSOLE directive it never shows up in the first place - but it does create a thread that uses cpu and ram... And when you close it - the terminal window also goes. I found, in linux, either use the IDE to launch it or Ctrl + Alt + T and cd to the location the app is and do ./ProgramFile to run it in a terminal window that stays where it is...

JSoftware
20-12-2010, 10:40 AM
I think you only need {$APPTYPE CONSOLE} in Delphi mode

will57
22-12-2010, 02:02 AM
hi again guys.

Thanks for all the help everyone. I'd been trying to use lazarus and spent a lot of time getting confused with it and I think I aught to say that I decided I'd stay with C but this evening I've changed my mind again. It's a big decision for me as it took me ages to learn C.

Anyway, my next plan is try and get to grips with Lazarus as it's very exciting to be learning something new so I intend to be a participating member of this community.

Thanks again for the warm welcome.

Speak again soon.

:)