Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2008-01

FPC + GTK2 : Using variable into a Widget name ?

4 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Unknown author

Hi,

I use FPC with GTK2 and I have the following problem : In a loop with I'd like to be able to use the indice (incremented integer) on the name of widget to perform some actions.
Here is an example :

  var
    pFSImage01, pFSImage02, pFSImage03 : PGtkWidget;
  ...
  For I:=1 to 3 do
  begin
  	pFSImage0#I# := gtk_image_new_from_file('./mypix.jpg');
  	gtk_fixed_put(pGTKFIXED(pFSFixed), pGTKWIDGET(pFSImage0#I#) , 100*I,
20);
  	gtk_widget_show(pFSImage0#I#);
  end;

So I'd like any #I# above are remplaced with the real I value. This would considerably improve/reduce my code.
But I'm able to achieve this. Does anyone know ?

Thanks.
Tom

Jonas Maebe
to Unknown author
Show quoted text 23 lines
I use FPC with GTK2 and I have the following problem : In a loop with I'd like to be able to use the indice (incremented integer) on the name of widget to perform some actions. Here is an example : var pFSImage01, pFSImage02, pFSImage03 : PGtkWidget; ... For I:=1 to 3 do begin pFSImage0#I# := gtk_image_new_from_file('./mypix.jpg'); gtk_fixed_put(pGTKFIXED(pFSFixed), pGTKWIDGET(pFSImage0#I#) , 100*I, 20); gtk_widget_show(pFSImage0#I#); end; So I'd like any #I# above are remplaced with the real I value. This would considerably improve/reduce my code. But I'm able to achieve this. Does anyone know ?

Use an array?

Jonas

Vincent Snijders
to Unknown author: I use FPC with GTK2 and I have the following problem : In a loop with I'd like to be able…
Show quoted text 5 lines
Hi, I use FPC with GTK2 and I have the following problem : In a loop with I'd like to be able to use the indice (incremented integer) on the name of widget to perform some actions.

Use an array.

Show quoted text 5 lines
Here is an example : var pFSImage01, pFSImage02, pFSImage03 : PGtkWidget; ...
   var pFSImage : array[1..3] of PGtkWidget;
    For I:=1 to 3 do
    begin
         pFSImage[I] := gtk_image_new_from_file('./mypix.jpg');
   	gtk_fixed_put(pGTKFIXED(pFSFixed), pGTKWIDGET(pFSImage[I]) , 100*I, 20);
    	gtk_widget_show(pFSImage[I]);
    end;

Vincent

bartek
to Unknown author: I use FPC with GTK2 and I have the following problem : In a loop with I'd like to be able…
Show quoted text 26 lines
Hi, I use FPC with GTK2 and I have the following problem : In a loop with I'd like to be able to use the indice (incremented integer) on the name of widget to perform some actions. Here is an example : var pFSImage01, pFSImage02, pFSImage03 : PGtkWidget; ... For I:=1 to 3 do begin pFSImage0#I# := gtk_image_new_from_file('./mypix.jpg'); gtk_fixed_put(pGTKFIXED(pFSFixed), pGTKWIDGET(pFSImage0#I#) , 100*I, 20); gtk_widget_show(pFSImage0#I#); end; So I'd like any #I# above are remplaced with the real I value. This would considerably improve/reduce my code. But I'm able to achieve this. Does anyone know ? Thanks. Tom

What about fixed size arrays?

var
	pFSImage: array[0..3] of pGTKWidget;
	i: integer;
begin
	for i:= 0 to 3 do
	begin
		pFSImage[i] := your code here
		more code
	end;
end;

You could also use dynamic arrays if you don't know the array size at compile time. There is more information in the reference manual of FPC.

bartek