[fpc-pascal] Basically on the right track?

Patrick patrick at spellingbeewinnars.org
Thu Dec 27 16:11:40 CET 2012


Wow ! I was really surprised to see all these emails when I woke up 
today! Thanks everyone.

So my message was held in the moderator queue for a while and I have 
been reading more.

Sorry for not reading through the man pages of fpc. I found the -Fu switch.

I have also read more about gpc and it seems abandoned, sorry for 
mentioning it here.

At the end of the email I have the hello world gtk program I tried to 
compile, the compiler error and an apt-get message from debian stable 
showing gtk dev installed.

I have been able to compile gtk c examples and other languages.



"Is it possible to specify the libraries to use to fpc ? In Ada we have 
.gpr files that can list where things are to be found. "

"What do you mean with this question ? "

This was an odd question to ask, sorry. With Ada we have .gpr files that 
can be used in place of Makefiles(for the most part). With fpc switches 
I will be fine now, sorry for the noise.

I am enjoying my holidays, I hope you guys are too !

-Patrick





:fpc hello_gtk.pas
Free Pascal Compiler version 2.4.0-2 [2010/02/20] for x86_64
Copyright (c) 1993-2009 by Florian Klaempfl
Target OS: Linux for x86-64
Compiling hello_gtk.pas
Linking hello_gtk
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
/usr/bin/ld: cannot find -lgtk
hello_gtk.pas(70,1) Error: Error while linking
hello_gtk.pas(70,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcx64 returned an error exitcode (normal if you did not 
specify a source file to be compiled)


root at foo:/# apt-get install libgtk2.0-dev
Reading package lists... Done
Building dependency tree
Reading state information... Done
libgtk2.0-dev is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 23 not upgraded.
N: Ignoring file 'squeeze-backports.list.save' in directory 
'/etc/apt/sources.list.d/' as it has an invalid filename extension
root at foo:/#


PROGRAM hello_world;

USES gtk, gdk, glib;

{ ---------------------------------hello-------------------------------- }

PROCEDURE hello( widget : pGtkWidget ; data : gpointer ); cdecl;
{ This is a callback function. The data arguments are ignored in this 
example. More on callbacks later }
BEGIN
writeln('Hello World!');
END; { ------------------------------hello------------------------------ }

{ ----------------------------delete_event------------------------ }
FUNCTION delete_event( widget : pGtkWidget ; event : pGdkEvent ; data : 
gpointer ) :
gint; cdecl;
{ If you return FALSE from the --delete_event-- signal handler, GTK will 
emit the --destroy-- signal. Returning TRUE means you don't want
the window to be destroyed. This is useful for popping up 'are you sure 
you want to quit?' type dialogs. }
BEGIN
writeln('delete event occurred');
{ Returning FALSE from the function, as we do here, causes the 
--destroy-- signal to be emitted. }
delete_event := 0; { i.e. FALSE }
END; { -----------------------------delete_event-------------------------- }

{ -----------------------------destroy---------------------------- }
PROCEDURE destroy( widget : pGtkWidget ; data : gpointer ); cdecl;
{ Another callback - this one will kill the app }
BEGIN
gtk_main_quit();
END; { 
-------------------------------destroy------------------------------- }

{ -----------------------Global Variables------------------------ }
VAR
window, button : pGtkWidget; { GtkWidget is the storage type for widgets }
{ --------------------------Main Program-------------------------- }
BEGIN
{ This is called in all GTK applications. Arguments are parsed from the 
command line and are returned to the application. }
gtk_init(@argc, @argv);

window := gtk_window_new(GTK_WINDOW_TOPLEVEL); { Create a new window }

{ When the window is given the --delete_event-- signal (this is given by 
the window manager, usually by the --close-- option,
or on the titlebar), we ask it to call the delete_event() function as 
defined above. The data passed to the callback function
is NIL and is ignored in the callback function. }
gtk_signal_connect(GTK_OBJECT(window), 'delete_event',
GTK_SIGNAL_FUNC(@delete_event), NIL);

{ Here we connect the --destroy-- event to a signal handler. This event 
occurs when we call gtk_widget_destroy() on the window,
or if we return FALSE in the --delete_event-- callback. }
gtk_signal_connect(GTK_OBJECT(window), 'destroy',
GTK_SIGNAL_FUNC(@destroy), NIL);

{ Creates a new button with the label 'Hello World'. }
button := gtk_button_new_with_label('Hello World');

{ When the button receives the --clicked-- signal, it will call the 
procedure hello() -defined above- passing it NIL as its argument. }
gtk_signal_connect(GTK_OBJECT(button), 'clicked',
GTK_SIGNAL_FUNC(@hello), NIL);

{ This packs the button into the window (a gtk container). }
gtk_container_add(GTK_CONTAINER(window), button);

{ The final step is to display this newly created widget. }
gtk_widget_show(button);

{ and the window }
gtk_widget_show(window);

{ All GTK applications must have a gtk_main(). Control ends here and 
waits for an event to occur (like a key press or mouse event). }
gtk_main();
END.



More information about the fpc-pascal mailing list