[lazarus] Learning component building blocks
Payne Thomas E CNIN
payne_t at crane.navy.mil
Sun Jul 18 17:29:05 EDT 1999
This is way off the latest discussions, but I am trying things on the ground
floor.
I am aiming at using FPC and LAZARUS in the real world when they are done,
but at the moment I am trying to learn how to use the basic tools, at hopes
to
contribute for everyones benefit.
My simple program below was attempting to mix serial comm with a GTK gui. I
can talk through the serial port OK by itself. I can get the buttons to
work by
themselves. But when I add any gtk calls to the basic serial I/O it behaves
abnormally.
Anyone have a clue why gtk would interfere with the serial port?
Tom
_______________________________________________________________
Program tdc1;
Uses linux,glib,gdk,gtk,sysutils;
Const myLine : String[80] = #128#00#03#21#12#164;
Var myFD : Longint;
procedure lcp_status_command( widget : pGtKWidget;
data
: gpointer); cdecl;
begin
writeln('sending the command');
if length(myLine)<>fdwrite (myFD,myLine[1],
Length(myLine)) then
Writeln ('Error when writing to file !');
end;
procedure quit_program( widget : pGtkWidget; event : pGdkEvent;
data : gpointer); cdecl;
begin
fdClose(myFD);
gtk_main_quit();
end;
var
window, button, box1 : pGtkWidget;
begin
myFD:=fdOpen ('/dev/cua0',Open_WrOnly); //from fdopen example in
FPC
if myFD>0 then
begin
if length(myLine)<>fdwrite (myFD,myLine[1],
Length(myLine)) then
Writeln ('Error when writing to file !');
{ //Taken from GTK 1.2 tutorial, section 3.3, and converted to .pp
//* This is called in all GTK applications. Arguments are
// parsed
// * from the command line and are returned to the
// application. */
gtk_init (@argc, @argv);
//* Create a new window */
window := gtk_window_new (GTK_WINDOW_TOPLEVEL);
//* This is a new call, this just sets the title of our
// * new window to "Hello Buttons!" */
gtk_window_set_title (GTK_WINDOW (window), 'Hello Buttons!');
//* Here we just set a handler for delete_event that
// immediately
// * exits GTK. */
gtk_signal_connect (GTK_OBJECT (window), 'delete_event',
GTK_SIGNAL_FUNC (@quit_program), NULL);
//* Sets the border width of the window. */
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
//* We create a box to pack widgets into. This is described
// in detail
// * in the "packing" section. The box is not really visible,
// it
// * is just used as a tool to arrange widgets. */
box1 := gtk_hbox_new(FALSE, 0);
//* Put the box into the main window. */
gtk_container_add (GTK_CONTAINER (window), box1);
//* Creates a new button with the label "Button 1". */
button := gtk_button_new_with_label ('Button 1');
//* Now when the button is clicked, we call the "callback"
// function
// * with a pointer to "button 1" as its argument */
gtk_signal_connect (GTK_OBJECT (button), 'clicked',
GTK_SIGNAL_FUNC (@lcp_status_command),
Nil);
//* Instead of gtk_container_add, we pack this button into the
// invisible
// * box, which has been packed into the window. */
gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
//* Always remember this step, this tells GTK that our
// preparation for
// * this button is complete, and it can now be displayed. */
gtk_widget_show(button);
//* Do these same steps again to create a second button */
button := gtk_button_new_with_label ('Button 2');
//* Call the same callback function with a different argument,
// * passing a pointer to "button 2" instead. */
gtk_signal_connect (GTK_OBJECT (button), 'clicked',
GTK_SIGNAL_FUNC (@lcp_status_command),
Nil);
gtk_box_pack_start(GTK_BOX(box1), button, TRUE, TRUE, 0);
//* The order in which we show the buttons is not really
// important, but I
// * recommend showing the window last, so it all pops up at
// once. */
gtk_widget_show(button);
gtk_widget_show(box1);
gtk_widget_show (window);
//* Rest in gtk_main and wait for the fun to begin! */
gtk_main ();
}
end
else
writeln('Error opening File');
end.
More information about the Lazarus
mailing list