Recent

Author Topic: needs a little help..  (Read 17149 times)

Flaze07

  • New Member
  • *
  • Posts: 36
needs a little help..
« on: July 03, 2017, 04:37:42 pm »
hi so in order to make a gui app
which option should I choose ??

when I try to
Code: Pascal  [Select][+][-]
  1. uses Graphics;
  2.  

in simple programs;
it errors
« Last Edit: July 03, 2017, 04:39:42 pm by Flaze07 »
pascal is good for learning programming language

Thaddy

  • Hero Member
  • *****
  • Posts: 16135
  • Censorship about opinions does not belong here.
Re: needs a little help..
« Reply #1 on: July 03, 2017, 04:47:51 pm »
You should simply start up lazarus and choose File|New|Application.

You can also write GUI apps in FPC itself, but that is definitely not for beginners. You have to do everything by hand and it becomes very complex very quickly.

With Lazarus it is as easy as the above.
« Last Edit: July 03, 2017, 04:51:49 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

Handoko

  • Hero Member
  • *****
  • Posts: 5374
  • My goal: build my own game engine using Lazarus
Re: needs a little help..
« Reply #2 on: July 03, 2017, 04:57:15 pm »
« Last Edit: July 03, 2017, 05:10:16 pm by Handoko »

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: needs a little help..
« Reply #3 on: July 03, 2017, 04:59:23 pm »
Found this some time ago... (Windows only):

Runs fine and fast...  :D
Code: Pascal  [Select][+][-]
  1. {
  2.   Copyright (c) 1996 by Charlie Calvert
  3.   Modifications by Florian Klaempfl
  4.  
  5.   Standard Windows API application written in Object Pascal.
  6.   No VCL code included. This is all done on the Windows API
  7.   level.
  8. }
  9.  
  10. {$APPTYPE GUI}
  11. {$MODE DELPHI}
  12. program WinHello;
  13.  
  14. uses
  15.   Windows;
  16.  
  17. const
  18.   AppName = 'WinHello';
  19.  
  20. function WindowProc(Window: HWnd; AMessage: UINT; WParam : WPARAM;
  21.                     LParam: LPARAM): LRESULT; stdcall; export;
  22.  
  23.   var
  24.      dc : hdc;
  25.      ps : paintstruct;
  26.      r : rect;
  27.  
  28. begin
  29.   WindowProc := 0;
  30.  
  31.   case AMessage of
  32.     wm_paint:
  33.       begin
  34.          dc:=BeginPaint(Window,@ps);
  35.          GetClientRect(Window,@r);
  36.          DrawText(dc,'Hello world by Free Pascal',-1,@r,
  37.            DT_SINGLELINE or DT_CENTER or DT_VCENTER);
  38.          EndPaint(Window,ps);
  39.          Exit;
  40.       end;
  41.     wm_Destroy:
  42.       begin
  43.          PostQuitMessage(0);
  44.          Exit;
  45.       end;
  46.   end;
  47.  
  48.   WindowProc := DefWindowProc(Window, AMessage, WParam, LParam);
  49. end;
  50.  
  51.  { Register the Window Class }
  52. function WinRegister: Boolean;
  53. var
  54.   WindowClass: WndClass;
  55. begin
  56.   WindowClass.Style := cs_hRedraw or cs_vRedraw;
  57.   WindowClass.lpfnWndProc := WndProc(@WindowProc);
  58.   WindowClass.cbClsExtra := 0;
  59.   WindowClass.cbWndExtra := 0;
  60.   WindowClass.hInstance := system.MainInstance;
  61.   WindowClass.hIcon := LoadIcon(0, idi_Application);
  62.   WindowClass.hCursor := LoadCursor(0, idc_Arrow);
  63.   WindowClass.hbrBackground := GetStockObject(WHITE_BRUSH);
  64.   WindowClass.lpszMenuName := nil;
  65.   WindowClass.lpszClassName := AppName;
  66.  
  67.   Result := RegisterClass(WindowClass) <> 0;
  68. end;
  69.  
  70.  { Create the Window Class }
  71. function WinCreate: HWnd;
  72. var
  73.   hWindow: HWnd;
  74. begin
  75.   hWindow := CreateWindow(AppName, 'Hello world program',
  76.               ws_OverlappedWindow, cw_UseDefault, cw_UseDefault,
  77.               cw_UseDefault, cw_UseDefault, 0, 0, system.MainInstance, nil);
  78.  
  79.   if hWindow <> 0 then begin
  80.     ShowWindow(hWindow, CmdShow);
  81.     ShowWindow(hWindow, SW_SHOW);
  82.     UpdateWindow(hWindow);
  83.   end;
  84.  
  85.   Result := hWindow;
  86. end;
  87.  
  88. var
  89.   AMessage: Msg;
  90.   hWindow: HWnd;
  91.  
  92. begin
  93.   if not WinRegister then begin
  94.     MessageBox(0, 'Register failed', nil, mb_Ok);
  95.     Exit;
  96.   end;
  97.   hWindow := WinCreate;
  98.   if longint(hWindow) = 0 then begin
  99.     MessageBox(0, 'WinCreate failed', nil, mb_Ok);
  100.     Exit;
  101.   end;
  102.  
  103.   while GetMessage(@AMessage, 0, 0, 0) do begin
  104.     TranslateMessage(AMessage);
  105.     DispatchMessage(AMessage);
  106.   end;
  107.   Halt(AMessage.wParam);
  108. end.
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Thaddy

  • Hero Member
  • *****
  • Posts: 16135
  • Censorship about opinions does not belong here.
Re: needs a little help..
« Reply #4 on: July 03, 2017, 05:36:50 pm »
Yeah, we started off with that in TP7.... Charlie also wrote it in Pascal...
Anyway if you positively absolutely have to you can "simply" do this with the fpc editor (DON'T DO THIS!)
Code: Pascal  [Select][+][-]
  1. program sanslazaruside;
  2. {$mode objfpc}{$H+}
  3. uses
  4.   Interfaces, Forms;  // no res file needed...
  5. type
  6.   TForm1 = class(TForm)
  7.   end;
  8.  
  9. var
  10.   Form1: TForm1;
  11.  
  12. begin
  13.   Application.Initialize;
  14.   Application.CreateForm(TForm1, Form1);
  15.   Form1.Caption := 'GUI Application created from code';
  16.   Form1.SetBounds(100,100,700,500);
  17.   Application.Run;
  18. end.

You have to set a lot of the correct paths, but it works.

Plz just use lazarus, File|New|Application. You will be a lot happier.... 8-) O:-) And you need Lazarus units installed anyway.
« Last Edit: July 03, 2017, 05:47:40 pm by Thaddy »
If I smell bad code it usually is bad code and that includes my own code.

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: needs a little help..
« Reply #5 on: July 03, 2017, 06:42:58 pm »
Plz just use lazarus, File|New|Application. You will be a lot happier.... 8-) O:-) And you need Lazarus units installed anyway.
Definitely +1 (more +10)
a smaller start (assuming we're on windows) is
Code: Pascal  [Select][+][-]
  1. program PrjHelloWorld;
  2. {$apptype gui}
  3. uses windows;
  4. begin
  5.   MessageBox(0,'Hello World','Greetings',0);
  6. end.
But that is just a Messagebox, no Application.
As Thaddy said: Please use/start with Lazarus ...
« Last Edit: July 03, 2017, 06:54:23 pm by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Thaddy

  • Hero Member
  • *****
  • Posts: 16135
  • Censorship about opinions does not belong here.
Re: needs a little help..
« Reply #6 on: July 03, 2017, 07:09:34 pm »
It is not even cross platform, this  is:
Code: Pascal  [Select][+][-]
  1. program sanslazarus;{$mode objfpc}{$H+}
  2. uses Interfaces,Dialogs;begin ShowMessage('Hello, there');end.
O:-)
If I smell bad code it usually is bad code and that includes my own code.

Flaze07

  • New Member
  • *
  • Posts: 36
Re: needs a little help..
« Reply #7 on: July 03, 2017, 07:11:23 pm »
Thank you for the advice  :D
So pascal is the first programming language I understand (tried to learn C++ on the web, understood nothing)
Anyways
so
Class is like Java's class (pointer )and
Object is like C++'s class (no pointer), am I right ?
And because I kinda dislike memory management (before I knew object I still do it , just afraid there might me memory leak ) should I use object ?

P.S win api is awesome I made several console aplication game using it
« Last Edit: July 03, 2017, 07:17:16 pm by Flaze07 »
pascal is good for learning programming language

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: needs a little help..
« Reply #8 on: July 03, 2017, 07:23:05 pm »
It is not even cross platform, this  is:
Code: Pascal  [Select][+][-]
  1. program sanslazarus;{$mode objfpc}{$H+}
  2. uses Interfaces,Dialogs;begin ShowMessage('Hello, there');end.
O:-)
No, it has to look like :
Code: Pascal  [Select][+][-]
  1. program PrjHelloWorld3;{$mode objfpc}{$H+}
  2. uses Interfaces,Dialogs,forms;begin Application.Initialize; ShowMessage('Hello, there');end.
And you have to import LCL, but you're right, that's cross platform ...

otherwise you get :
Code: Text  [Select][+][-]
  1. Failed to create win32 control, error: 1407 : Fensterklasse wurde nicht gefunden.
  2. [FORMS.PP] ExceptionOccurred
  3.   Sender=Exception
  4.   Exception=Failed to create win32 control, error: 1407 : Fensterklasse wurde nicht gefunden.
  5.   Stack trace:
  6.   $00000001001476F3
  7.   $000000010015D63C
  8.   $0000000100103FEE
  9.   $00000001000E269F
  10.   $00000001000E89A3
  11.   $00000001000E99CA
  12.   $00000001001036A1
  13.   $0000000100104C08
  14.   $00000001000F51C0
  15.   $000000010009AAB7
  16.   $000000010009A8CD
  17.   $000000010001801C
  18.   $0000000100017E86
  19.   $00000001000188F5
  20.   $0000000100024EF7
  21.   $00000001000DFD88
  22.   $00000001000A45BA
  23. TApplication.HandleException Failed to create win32 control, error: 1407 : Fensterklasse wurde nicht gefunden.
  24.   Stack trace:
  25.   $00000001001476F3
  26.   $000000010015D63C
  27.   $0000000100103FEE
  28.   $00000001000E269F
  29.   $00000001000E89A3
  30.   $00000001000E99CA
  31.   $00000001001036A1
  32.   $0000000100104C08
  33.   $00000001000F51C0
  34.   $000000010009AAB7
  35.   $000000010009A8CD
  36.   $000000010001801C
  37.   $0000000100017E86
  38.   $00000001000188F5
  39.   $0000000100024EF7
  40.   $00000001000DFD88
  41.   $00000001000A45BA
  42. Exception at 00000001001476F3: Exception:
  43. Failed to create win32 control, error: 1407 : Fensterklasse wurde nicht gefunden.
  44.  
« Last Edit: July 03, 2017, 07:25:00 pm by jc99 »
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

Thaddy

  • Hero Member
  • *****
  • Posts: 16135
  • Censorship about opinions does not belong here.
Re: needs a little help..
« Reply #9 on: July 03, 2017, 09:31:38 pm »
Probably only on Windows. Works like a charm on Linux.
If I smell bad code it usually is bad code and that includes my own code.

jc99

  • Hero Member
  • *****
  • Posts: 553
    • My private Site
Re: needs a little help..
« Reply #10 on: July 03, 2017, 09:37:39 pm »
Probably only on Windows. Works like a charm on Linux.
So much on crossplatform ...

What's the size of the bin on linux ? On windows its about 2.2M.
BWT the win only has about 44K.
OS: Win XP x64, Win 7, Win 7 x64, Win 10, Win 10 x64, Suse Linux 13.2
Laz: 1.4 - 1.8.4, 2.0
https://github.com/joecare99/public
'~|    /''
,_|oe \_,are
If you want to do something for the environment: Twitter: #reduceCO2 or
https://www.betterplace.me/klimawandel-stoppen-co-ueber-preis-reduzieren

RAW

  • Hero Member
  • *****
  • Posts: 868
Re: needs a little help..
« Reply #11 on: July 04, 2017, 01:44:18 am »
Quote
BWT the win only has about 44K.
Yes, really nice ... 43,5 k..
(x64: 1,5 MB RAM)

BTW: compiles fine with {$MODE OBJFPC}{$H+}{$J-}...

I'm curious who will win the RAM-Game: WIN-API, KOL, fpGUI, MSE-IDE, LLCL...
Never really did that test.. nowadays nobody seems to care about that (of course), but it's interesting..  :D   
Windows 7 Pro (x64 Sp1) & Windows XP Pro (x86 Sp3).

Flaze07

  • New Member
  • *
  • Posts: 36
Re: needs a little help..
« Reply #12 on: July 04, 2017, 07:21:47 am »
I think I got it wrong
so the lcl is a gui library...
does that means it is unlike C++'s sfml ??
pascal is good for learning programming language

Flaze07

  • New Member
  • *
  • Posts: 36
Re: needs a little help..
« Reply #13 on: July 04, 2017, 09:27:08 am »
so I need TCanvas to make something like C++'s sfml can make ?
pascal is good for learning programming language

Ñuño_Martínez

  • Hero Member
  • *****
  • Posts: 1191
    • Burdjia
Re: needs a little help..
« Reply #14 on: July 04, 2017, 09:49:39 am »
Thank you for the advice  :D
So pascal is the first programming language I understand (tried to learn C++ on the web, understood nothing)
That's the point.  C++ is one of the worst languages to start with.
Anyways
so
Class is like Java's class (pointer )
It is a simplification, but yes, it is.
and
Object is like C++'s class (no pointer), am I right ?
Again, it is a simplification, but yes, you are.
And because I kinda dislike memory management (before I knew object I still do it , just afraid there might me memory leak ) should I use object ?
No, you shouldn't.

OBJECT is only for backwards compatibility with (the very) old Turbo Pascal compilers.  You should use CLASS based objects instead.  I learned that recently.

As I've said, CLASS objects are similar to pointers but it is a simplification.  Actually there are some compiler magic that makes memory management a bit more easy than in Java and C++ (not garbage manager).  It isn't too hard.

You can read more about this in the CLASS vs. OBJECT and memory management discussion I had at Pascal Game Development forums.

If you need automatic objects like in C++ you can use advanced records, but you must remember they're not objects (no inheritance, can't be used to implement TNotifyEvent responses, etc.).

Anyway you should follow some of the tutorials to learn more.
so I need TCanvas to make something like C++'s sfml can make ?
Nope, you don't need TCanvas.  Please follow the tutorials to learn more.
« Last Edit: July 04, 2017, 09:53:01 am by Ñuño_Martínez »
Are you interested in game programming? Join the Pascal Game Development community!
Also visit the Game Development Portal

 

TinyPortal © 2005-2018