label at runtime

Moderator: Rathinagiri

User avatar
jairpinho
Posts: 209
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 1 time
Contact:

label at runtime

Post by jairpinho » Tue Sep 05, 2017 4:55 pm

Hello, I need to create 100 label at runtime, after the main window is already active to add in a graphic
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

edk
Posts: 168
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 49 times
Been thanked: 99 times

Post by edk » Tue Sep 05, 2017 8:45 pm

Hi.
Do you mean this behaviour?

Code: Select all

#include <hmg.ch>

Function Main

    DEFINE WINDOW main AT 108 , 360 WIDTH 550 HEIGHT 350 VIRTUAL WIDTH Nil VIRTUAL HEIGHT Nil TITLE "" ICON NIL MAIN CURSOR NIL ON INIT Nil ON RELEASE Nil ON INTERACTIVECLOSE Nil ON MOUSECLICK Nil ON MOUSEDRAG Nil ON MOUSEMOVE Nil ON SIZE Nil ON MAXIMIZE Nil ON MINIMIZE Nil ON PAINT Nil BACKCOLOR Nil NOTIFYICON NIL NOTIFYTOOLTIP NIL ON NOTIFYCLICK Nil ON GOTFOCUS Nil ON LOSTFOCUS Nil ON SCROLLUP Nil ON SCROLLDOWN Nil ON SCROLLLEFT Nil ON SCROLLRIGHT Nil ON HSCROLLBOX Nil ON VSCROLLBOX Nil

    DEFINE BUTTON Button_1
        ROW    280
        COL    30
        WIDTH  100
        HEIGHT 28
        ACTION AddPict()
        CAPTION "Picture"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_2
        ROW    280
        COL    410
        WIDTH  100
        HEIGHT 28
        ACTION AddLabels()
        CAPTION "Labels"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

END WINDOW
        Main.Center
        Main.Activate

Return


FUNCTION addPict()

IF IsControlDefined ( "Image_1" , "Main" )
	Main.Image_1.Release
	RETURN
ENDIF

DEFINE IMAGE Image_1
	PARENT Main
        ROW    30
        COL    60
        WIDTH  420
        HEIGHT 220
        PICTURE "img.jpg"
        HELPID Nil
        VISIBLE .T.
        STRETCH .T.
        ACTION Nil
    END IMAGE

RETURN
****************************************************************
FUNCTION AddLabels()
Local i, cLabelName

Local isControl:=IsControlDefined ( "L_1" , "Main")

FOR i=1 TO 100
	cLabelName:='L_'+ALLTRIM(STR(i))

	IF isControl

		DoMethod("Main", cLabelName, "Release")

	ELSE

	
	    DEFINE LABEL &cLabelName 
		PARENT Main
	        ROW    30+(20*int(i/10))
        	COL    60+(40*(i%10))
	        WIDTH  30
        	HEIGHT 20
        	VALUE ALLTRIM(STR(i))
	        FONTNAME "Arial"
        	FONTSIZE 9
	        VISIBLE .T.
	    END LABEL
	ENDIF
NEXT i
RETURN
By the way, I noticed the strange behavior of the IsControlDefined function:
IsControlDefined ( cLabelName , "Main") does not return "true" for the label controls already defined :shock:

Code: Select all

FUNCTION AddLabels()
Local i, cLabelName

FOR i=1 TO 100
	cLabelName:='L_'+ALLTRIM(STR(i))

	IF IsControlDefined ( cLabelName , "Main")

		DoMethod("Main", cLabelName, "Release")

	ELSE
	
	    DEFINE LABEL &cLabelName 
		PARENT Main
	        ROW    30+(20*int(i/10))
        	COL    60+(40*(i%10))
	        WIDTH  30
        	HEIGHT 20
        	VALUE ALLTRIM(STR(i))
	        FONTNAME "Arial"
        	FONTSIZE 9
	        VISIBLE .T.
	    END LABEL
	ENDIF
NEXT i
RETURN

User avatar
jairpinho
Posts: 209
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 1 time
Contact:

Post by jairpinho » Wed Sep 06, 2017 1:29 am

edk wrote:
Tue Sep 05, 2017 8:45 pm
Hi.
Do you mean this behaviour?

Code: Select all

#include <hmg.ch>

Function Main

    DEFINE WINDOW main AT 108 , 360 WIDTH 550 HEIGHT 350 VIRTUAL WIDTH Nil VIRTUAL HEIGHT Nil TITLE "" ICON NIL MAIN CURSOR NIL ON INIT Nil ON RELEASE Nil ON INTERACTIVECLOSE Nil ON MOUSECLICK Nil ON MOUSEDRAG Nil ON MOUSEMOVE Nil ON SIZE Nil ON MAXIMIZE Nil ON MINIMIZE Nil ON PAINT Nil BACKCOLOR Nil NOTIFYICON NIL NOTIFYTOOLTIP NIL ON NOTIFYCLICK Nil ON GOTFOCUS Nil ON LOSTFOCUS Nil ON SCROLLUP Nil ON SCROLLDOWN Nil ON SCROLLLEFT Nil ON SCROLLRIGHT Nil ON HSCROLLBOX Nil ON VSCROLLBOX Nil

    DEFINE BUTTON Button_1
        ROW    280
        COL    30
        WIDTH  100
        HEIGHT 28
        ACTION AddPict()
        CAPTION "Picture"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

    DEFINE BUTTON Button_2
        ROW    280
        COL    410
        WIDTH  100
        HEIGHT 28
        ACTION AddLabels()
        CAPTION "Labels"
        FONTNAME "Arial"
        FONTSIZE 9
        TOOLTIP ""
        FONTBOLD .F.
        FONTITALIC .F.
        FONTUNDERLINE .F.
        FONTSTRIKEOUT .F.
        ONGOTFOCUS Nil
        ONLOSTFOCUS Nil
        HELPID Nil
        FLAT .F.
        TABSTOP .T.
        VISIBLE .T.
        TRANSPARENT .F.
        MULTILINE .F.
        PICTURE Nil
        PICTALIGNMENT TOP
    END BUTTON

END WINDOW
        Main.Center
        Main.Activate

Return


FUNCTION addPict()

IF IsControlDefined ( "Image_1" , "Main" )
	Main.Image_1.Release
	RETURN
ENDIF

DEFINE IMAGE Image_1
	PARENT Main
        ROW    30
        COL    60
        WIDTH  420
        HEIGHT 220
        PICTURE "img.jpg"
        HELPID Nil
        VISIBLE .T.
        STRETCH .T.
        ACTION Nil
    END IMAGE

RETURN
****************************************************************
FUNCTION AddLabels()
Local i, cLabelName

Local isControl:=IsControlDefined ( "L_1" , "Main")

FOR i=1 TO 100
	cLabelName:='L_'+ALLTRIM(STR(i))

	IF isControl

		DoMethod("Main", cLabelName, "Release")

	ELSE

	
	    DEFINE LABEL &cLabelName 
		PARENT Main
	        ROW    30+(20*int(i/10))
        	COL    60+(40*(i%10))
	        WIDTH  30
        	HEIGHT 20
        	VALUE ALLTRIM(STR(i))
	        FONTNAME "Arial"
        	FONTSIZE 9
	        VISIBLE .T.
	    END LABEL
	ENDIF
NEXT i
RETURN
By the way, I noticed the strange behavior of the IsControlDefined function:
IsControlDefined ( cLabelName , "Main") does not return "true" for the label controls already defined :shock:

Code: Select all

FUNCTION AddLabels()
Local i, cLabelName

FOR i=1 TO 100
	cLabelName:='L_'+ALLTRIM(STR(i))

	IF IsControlDefined ( cLabelName , "Main")

		DoMethod("Main", cLabelName, "Release")

	ELSE
	
	    DEFINE LABEL &cLabelName 
		PARENT Main
	        ROW    30+(20*int(i/10))
        	COL    60+(40*(i%10))
	        WIDTH  30
        	HEIGHT 20
        	VALUE ALLTRIM(STR(i))
	        FONTNAME "Arial"
        	FONTSIZE 9
	        VISIBLE .T.
	    END LABEL
	ENDIF
NEXT i
RETURN


thank you edk worked perfect, I need now the label in the vertical position
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

User avatar
srvet_claudio
Posts: 1949
Joined: Thu Feb 25, 2010 8:43 pm
Location: Uruguay
Has thanked: 31 times
Been thanked: 119 times
Contact:

Post by srvet_claudio » Wed Sep 06, 2017 2:49 am

Try with:

IsControlDefined ( Image_1 , Main )

without quotes in the names of controls and windows
Best regards.
Dr. Claudio Soto
(from Uruguay)
http://srvet.blogspot.com

User avatar
jairpinho
Posts: 209
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 1 time
Contact:

Post by jairpinho » Wed Sep 06, 2017 3:18 am

srvet_claudio wrote:
Wed Sep 06, 2017 2:49 am
Try with:

IsControlDefined ( Image_1 , Main )

without quotes in the names of controls and windows
edk works as Mr Claudio explained IsControlDefined (Image_1, Main)
Thank you Claudio
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

User avatar
gfilatov
Posts: 514
Joined: Fri Aug 01, 2008 5:42 am
Location: Ukraine
Has thanked: 7 times
Been thanked: 57 times
Contact:

Post by gfilatov » Wed Sep 06, 2017 7:14 am

srvet_claudio wrote:
Wed Sep 06, 2017 2:49 am
Try with:

IsControlDefined ( Image_1 , Main )

without quotes in the names of controls and windows
Because IsControlDefined () is pseudo-function
Should be
FUNCTION addPict()

IF IsControlDefined ( Image_1 , Main )
...
and
FUNCTION AddLabels()
Local i, cLabelName

FOR i=1 TO 100
cLabelName:='L_'+ALLTRIM(STR(i))

IF _IsControlDefined ( cLabelName , "Main")
...
Kind Regards,
Grigory Filatov

"Everything should be made as simple as possible, but no simpler." Albert Einstein

User avatar
jairpinho
Posts: 209
Joined: Mon Jul 18, 2011 5:36 pm
Location: Rio Grande do Sul - Brasil
Been thanked: 1 time
Contact:

Post by jairpinho » Wed Sep 06, 2017 11:03 pm

I need now the label in the vertical position
Jair Pinho
HMG ALTA REVOLUÇÃO xBASE
HMG xBASE REVOLUTION HIGH
http://www.hmgforum.com.br

User avatar
mol
Posts: 2853
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 123 times
Been thanked: 65 times
Contact:

Post by mol » Thu Sep 07, 2017 5:46 am

I've created my own label control with vertical center option, but I haven't found method to create vertical orientated label.
Maybe Claudio or Grigory knows if it's possible.

edk
Posts: 168
Joined: Thu Oct 16, 2014 11:35 am
Location: Poland
Has thanked: 49 times
Been thanked: 99 times

Post by edk » Thu Sep 07, 2017 6:06 am

Maybe try use Claudio's bos taurus.

User avatar
mol
Posts: 2853
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 123 times
Been thanked: 65 times
Contact:

Post by mol » Thu Sep 07, 2017 6:27 am

IMO, this is possible only using graphics tools.

Post Reply