Recent

Author Topic: "Hello world unit"?  (Read 14431 times)

Etron770

  • New member
  • *
  • Posts: 9
"Hello world unit"?
« on: September 10, 2006, 09:33:10 am »
Hi to all here,
I am new in the Lazarus system but very familar with the old Borland Pascal.

but I started programming 25 jears ago with the well known code:

uses crt;
begin
clrscr;
textbackgrnd(white);
writeln;
writeln('hello World');
writeln;
repeat until keypressed;
end.  

Now my son (10 jears) would like to begin with programming and i am missing such easy style of programming.
Ok I could use the DOS free pascal but the next step

the graphic commands line rectangle circle are not available in that compiler, because the dos VGA modes are of course no longer present.

Maybe there is any unit ready to use for beginners. I looked in the internet and they recommend some simple languages for beginning, but I would prefere pascal for my son, and I think its better to learn a language to write everything (exept the functions and procedures).

There is a lot of code in the windows based editor already to implement the own one.

any hints for me ? ;-)

CCRDude

  • Hero Member
  • *****
  • Posts: 596
RE: "Hello world unit"?
« Reply #1 on: September 10, 2006, 04:07:25 pm »
You can still use the those simple text mode things with FreePascal ;)

Anyway, I recently noticed that there were a few "oo-based" (well, actually more just form-based) entry tutorials at DelphiBasics, which you could use the same way with Lazarus :)

Etron770

  • New member
  • *
  • Posts: 9
RE: "Hello world unit"?
« Reply #2 on: September 10, 2006, 07:51:19 pm »
shure that we could use the simple textmode things, but it stops with the basic graphic commands.
I am missing the basic things to learn the language.
We started assemble programming with a pascal tool which emulated an assembler.
So maybe there would be a pascal tool which emulates the old grahic and text based funtions but the output is in a window program.
I think it would be helpful to teach pascal without any objects but in an modern fashin window.

I will look to the delphi sites

Regards Knut

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: "Hello world unit"?
« Reply #3 on: September 10, 2006, 09:20:57 pm »
You could teach him using TCanvas directly, if you know it well enougth. A simple code is:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Canvas.TextOut(0, 0, 'MyText');
  Canvas.Brush.Color := clWhite;
  Canvas.Rectangle(30, 30, 300, 300);
end;

And latter he can use Mouse and Keyboard events to detect things.

felipemdc

  • Administrator
  • Hero Member
  • *
  • Posts: 3538
RE: "Hello world unit"?
« Reply #4 on: September 10, 2006, 09:25:54 pm »
By the way, I think that the crt unit is portable. So your initial code should just work on Win32 or modern unixes.

> the graphic commands line rectangle circle are not available in that compiler, because the dos VGA modes are of course no longer present.

Are you use?? I think they should be available. Look for them here:

http://www.freepascal.org/docs-html/rtl/index.html

marmin

  • Jr. Member
  • **
  • Posts: 86
    • http://www.naton.org
"Hello world unit"?
« Reply #5 on: September 11, 2006, 04:59:28 am »
Nothing beats a book, like 'learn Delphi in xx days' ( I forgot the exact day count.) Lazarus code is 99% like Delphi .
In fact some of them are displayed on the ads, to the left.
Marmin^.Style
Location: Pointer Land!

CCRDude

  • Hero Member
  • *****
  • Posts: 596
"Hello world unit"?
« Reply #6 on: September 11, 2006, 08:44:48 am »
Book or tutorials or complete trial-n-error - that's an individual thing I guess, one can't say that one beats the other ;)

Etron770

  • New member
  • *
  • Posts: 9
Re: RE: "Hello world unit"?
« Reply #7 on: September 11, 2006, 11:39:37 am »
Quote from: "sekel"
By the way, I think that the crt unit is portable. So your initial code should just work on Win32 or modern unixes.

> the graphic commands line rectangle circle are not available in that compiler, because the dos VGA modes are of course no longer present.

Are you use?? I think they should be available. Look for them here:

http://www.freepascal.org/docs-html/rtl/index.html


Thank`s a lot that`s just what I was looking for, but I was not aware that the graphic modes are ported to windows and I do not need bgi drivers.

So now I am able to start pascal lessons with my son without any object orientated stuff.

Regards Knut

Etron770

  • New member
  • *
  • Posts: 9
RE: Re: RE: "Hello world unit"?
« Reply #8 on: September 12, 2006, 10:42:25 am »
Does naybody know how to redirect the keyboard funtions to the graph window. Just now the text window must be used for inputs?

CCRDude

  • Hero Member
  • *****
  • Posts: 596
RE: Re: RE: "Hello world unit"?
« Reply #9 on: September 12, 2006, 10:58:21 am »
Doing this without OO is always a bit complicated, back in DOS times I often used interrupts for this, but I guess that's not really a preferred (or maybe not even a working) solution nowadays.

Thinking about the simple approach: are KeyPressed and ReadKey no longer working?

Etron770

  • New member
  • *
  • Posts: 9
RE: Re: RE: "Hello world unit"?
« Reply #10 on: September 12, 2006, 11:31:28 am »
I am trying to build a simple unit for basic commands without window based graphic, to do the first steps with my son without object orientaded stuff
I did it in Dos times also and I have my complete libraries with interupt handlers but I am sure XP is not as easy as DOS and Win 3.X, but the first problem is that there is no asm interface in lazarus.

Swithcing in the old Graphic mode:
 { We want an 8 bit mode }
  gd := D8bit;

  gm := m640x480;
  initgraph(gd,gm,'');

  { Make sure you always check graphresult! }
  error := graphResult;
  if (error <> grOk) Then
    begin
    writeln('640x480x256 is not supported!');
    halt(1)
    end;
  { We are now in 640x480x256 }            
_____________________________________________________________

opens two windows:
one text window and the graphic window
_________________________________________________________________
I tried to get the keystrokes and send it to the graphic window
No problem to get the keystrokes and send it to the screen, but it is not possible to do the inputs in the graphic window
I must use the text window to write the text.
Ok no problem for teaching but not very fine.
________________________________________________________________
function readGln(xpos,ypos:integer):string;
var K,hex:word;
xpos_intern : integer;
begin
xpos_intern := xpos;
Repeat
    hex:=GetKeyEvent;
    K:=TranslateKeyEvent(hex);
    KeyEventToString(K);
    if hex <> 7181
    then
    outTextXY(xpos_intern,ypos,GetKeyEventChar(K));  {output in graphic mode)
   write(GetKeyEventChar(K)); {outout in textmode}
   inc(xpos_intern,10);
  Until hex=7181; {Return}

end;

.. the funciton is not ready ...

Etron770

  • New member
  • *
  • Posts: 9
RE: Re: RE: "Hello world unit"?
« Reply #11 on: September 12, 2006, 11:53:45 am »
found it unit Wincrt function readkey as easy as possible

But I have no helpfiles (see http://www.lazarus.freepascal.org/index.php?name=PNphpBB2&file=viewtopic&t=2865&highlight= )
so I  did a search in the sourcecodes.

THX Knut

ramengo

  • Newbie
  • Posts: 2
"Hello world unit"?
« Reply #12 on: September 16, 2006, 08:56:24 am »
Hi Etron770,

I'm just trying to do the same thing: teaching Turbo Pascal to my nephew.
I was already using Lazarus to write some simple Win32 app and don't want to install other tools: at the end there's FreePascal inside which is very good !

So, please, point me to good example of source code adapted for Lazarus.
TIA.

 

TinyPortal © 2005-2018