Page 1 of 2

#Define mutiline

Posted: Wed May 06, 2020 7:25 am
by Otto
Hello,
Can we insert multiple lines at the same time with #define?

Thank you in advance
Otto

Re: #Define mutiline

Posted: Wed May 06, 2020 11:05 am
by nageswaragunupudi
If you mean in one #define, can we create multiple definitions, then it is not possible.
Each define has to be separate.
I am not sure if I understood you correctly.

Re: #Define mutiline

Posted: Wed May 06, 2020 12:13 pm
by Otto
Dear Mr. Rao,
Yes, that's exactly what I want. Because of the better readability of the source code, it would be fine.
Even when checking the source code, you only need to look at this one #define.
For example:
@ ( oDlg:nHeight - 30 )/2.05, 5 BUTTON "MoveUp" SIZE 35,12 PIXEL OF oDlg ACTION SwapRow( oBrw, .f. )
@ ( oDlg:nHeight - 30 )/2.05, 50 BUTTON "MoveDn" SIZE 35,12 PIXEL OF oDlg ACTION SwapRow( oBrw, .t. )

#DEFINE COLOFFSETBTN nOffset += 5 + oBtn:nwidth
#define MYBTN @ ( oDlg:nHeight - 30 )/2.05, nOffset BUTTON oBtn PROMPT

COLOFFSETBTN
MYBTN "MoveDn" PIXEL OF oDlg ACTION SwapRow( oBrw, .t. )
COLOFFSETBTN
MYBTN "HideSel" PIXEL OF oDlg msginfo("test")
COLOFFSETBTN
MYBTN "Show Select" PIXEL OF msginfo("test")
COLOFFSETBTN
MYBTN "Artikeldatei aktualisieren" ACTION f_verteilen(aData) OF oDlg PIXEL


With Harbourino preprocessor I do it like this.

$-> MYBTN : Caption=MoveUp; Action= msginfo("test")
$-> MYBTN : Caption=MoveDn; Action= SwapRow( oBrw, .t. )
$-> MYBTN : Caption=HideSel; Action= msginfo("test")
$-> MYBTN : Caption=Show Select; Action= msginfo("test")
$-> MYBTN : Caption=Artikeldatei aktualisieren; Action=f_verteilen(aData)

Image

I replace for example
@ ( oDlg:nHeight - 30 )/2.05, 5 BUTTON "MoveUp" SIZE 35,12 PIXEL OF oDlg ACTION SwapRow( oBrw, .f. )
@ ( oDlg:nHeight - 30 )/2.05, 50 BUTTON "MoveDn" SIZE 35,12 PIXEL OF oDlg ACTION SwapRow( oBrw, .t. )

( Calculation of vertical positioning is all automaically. )
with
$-> MYBTN : Caption=MoveUp; Action= SwapRow( oBrw, .f. )
$-> MYBTN : Caption=MoveDn; Action= SwapRow( oBrw, .t. )

I thought maybe it is also possible with #define.
Best regards
Otto

Re: #Define mutiline

Posted: Wed May 06, 2020 2:10 pm
by nageswaragunupudi

Code: Select all

#xtranslate NEXTBTN <prompt> ACTION <uaction> => ;
   nOffset += 5 + oBtn:nwidth ;;
   @ ( oDlg:nHeight - 30 )/2.05, nOffset BUTTON oBtn PROMPT <prompt> OF oDlg PIXEL ACTION <uaction>

// ....

   NEXTBTN "myprompt" ACTION MsgInfo( "ok" )

 
is preprocessed by Harbour as:

Code: Select all

   nOffset += 5 + oBtn:nwidth ; oBtn := TButton():New( ( oDlg:nHeight - 30 )/2.05, nOffset, "myprompt", oDlg, {|| MsgInfo( "ok" )},,,,, .F., .T., .F.,, .F.,,, .F., "oBtn", .F. )
 

Re: #Define mutiline

Posted: Wed May 06, 2020 2:17 pm
by nageswaragunupudi
With define

Code: Select all

#define NEXTBTN nOffset += 5 + oBtn:nwidth; @ ( oDlg:nHeight - 30 )/2.05, nOffset BUTTON oBtn PROMPT
 
With the above definition, this works

Code: Select all

   NEXTBTN "MoveDn" PIXEL OF oDlg ACTION SwapRow( oBrw, .t. )
 

Re: #Define mutiline

Posted: Wed May 06, 2020 4:10 pm
by Otto
Dear Mr. Rao,
thank you so much. I think this offers much power to build his own toolbox.
Best regards,
Otto

Re: #Define mutiline

Posted: Wed May 06, 2020 5:42 pm
by Otto
Dear Mr. Rao,

I can't find out a way for the first button to define.
I tried this but with no success.
iif( VALTYPE( oBtn) = "C", ( nOffset += 5 + oBtn:nwidth ), nOffset )

So I ended up using 2 xTranslate.

Code: Select all

#xtranslate NEXTBTN <prompt> ACTION <uaction> => ;
  nOffset += 5 + oBtn:nwidth ;;
   @ ( oDlg:nHeight - 30 )/2.05, nOffset BUTTON oBtn PROMPT <prompt> SIZE NIL, 25 OF oDlg PIXEL ACTION <uaction>
   
   
   #xtranslate NEXTBTN1 <prompt> ACTION <uaction> => ;
   @ ( oDlg:nHeight - 30 )/2.05, nOffset BUTTON oBtn PROMPT <prompt> SIZE NIL, 25 OF oDlg PIXEL ACTION <uaction>

Code: Select all

 
     #include "nextbtn.ch"
  
    NEXTBTN1 "MoveDn"     ACTION SwapRow( oBrw, .t. )

   NEXTBTN "MoveUp"      ACTION SwapRow( oBrw, .f. )
   
   NEXTBTN "MoveDn"      ACTION SwapRow( oBrw, .t. )

 
Sure, you have a solution for this.
Best regards,
Otto

Re: #Define mutiline

Posted: Thu May 07, 2020 4:45 am
by nageswaragunupudi

Code: Select all

#xtranslate MYBTN <prompt> ACTION <uaction> => ;
   nOffSet := If( oBtn == nil, 5, nOffSet + 5 + oBtn:nWidth );;
   @ oDlg:nHeight - 30, nOffset BUTTON oBtn PROMPT <prompt> SIZE 80, 25 OF oDlg PIXEL ACTION <uaction>

func test

   local oDlg, nOffset, oBtn

   DEFINE DIALOG oDlg SIZE 600,100 PIXEL TRUEPIXEL

   MYBTN "ONE" ACTION MsgInfo( "One" )
   MYBTN "TWO" ACTION MsgInfo( "Two" )
   MYBTN "TEN" ACTION MsgInfo( "ten" )

   ACTIVATE DIALOG oDlg CENTERED

return nil
 
Image

Re: #Define mutiline

Posted: Thu May 07, 2020 7:14 am
by Otto
Dear Mr. Rao,
thank you. Now it is working fine.
---------------------------------------
May I ask you something else please.
If I use OOP code, how can I pass the parameters.

Code: Select all

#xtranslate NEXTBTN <prompt> ACTION <uaction> => ;
    nOffSet := If( oBtn == nil, 5, nOffSet + 5 + oBtn:nWidth );;
   oBtn := TButton():New( ( oDlg:nHeight - 30 )/2.05, nOffset, , oDlg, ,      ,   30      ,,, .F., .T., .F.,, .F.,,, .F., , .F. )
With my code all buttons have caption "Button".

Best regards,
Otto

Re: #Define mutiline

Posted: Thu May 07, 2020 10:06 am
by nageswaragunupudi

Code: Select all

#xtranslate NEXTBTN <prompt> ACTION <uAction> => ;
   nOffSet := If( oBtn == nil, 5, nOffSet + 5 + oBtn:nWidth );;
   oBtn := TButton():New( oDlg:nHeight - 50, nOffset, <prompt>, oDlg, ;
   [\{||<uAction>\}], 80, 25,,, .F., .T., .F.,, .F.,,, .F., "oBtn", .F. )

 
This works.
But I do not advise preprocessing BUTTON command.
Anyway, that is your choice.

Re: #Define mutiline

Posted: Thu May 07, 2020 12:49 pm
by Otto
Dear Mr. Rao,

It works perfectly.
I think you can tremendously simplify the source code of your programs.
Comments can be inserted in the #xtranslate files, and the reading flow in the actual program is not disturbed.

I want to show how easy it is to rearrange the switch.
You swap the lines and don't have to worry about anything.
I think even in preparation for the change of the own programs to mod Harbour this can bring something.
Maybe we find a way to exchange the #xTranslate files.

Thanks again.

Re: #Define mutiline

Posted: Thu May 07, 2020 4:15 pm
by Otto
Dear Mr. Rao,
Can you help me again, please? I would now like to assign a background color.
But the Button color of oBtn does not change.
Best regards,
Otto

Code: Select all

#xtranslate NEXTBTN <prompt> ACTION <uAction> => ;
   nOffSet := If( oBtn == nil, 5, nOffSet + 5 + oBtn:nWidth );;
   oBtn := TButton():New( oDlg:nHeight/2.05 - 50, nOffset, <prompt>, oDlg, ;
   [\{||<uAction>\}], , 25,,, .F., .T., .F.,, .F.,,, .F., "oBtn", .F. );;
   oBtn:nClrPane := CLR_GREEN
 

Re: #Define mutiline

Posted: Thu May 07, 2020 5:56 pm
by nageswaragunupudi
TButton and TButtonBmp are Windows controls. We can not set colors.

It is possible to set colors for TBtnBmp only.

Re: #Define mutiline

Posted: Thu May 07, 2020 6:33 pm
by Otto
Dear Mr. Rao,
I have seen that TButton inherit from TControl.
But I have not checked whether the paint method takes into account all the data. I will test with ButtonBmp.

I think we should extend AUTOCODE in this direction. :D

Thank you for your help and best regard
Otto

Re: #Define mutiline

Posted: Fri May 08, 2020 2:31 am
by nageswaragunupudi
Yes. TButton and all other FWH controls are derived from TControl.

TButton class creates a Windows "BUTTON" control and the button is painted by Windows only. TButton does not have its own paint method.

TButtonBmp is derived from TButton class. So this control also creates a Windows "BUTTON" control. This class has its own Paint() method. The Paint() method uses Windows to paint the button and then paints the bitmap over the button.

Therefore, in both the above cases, button is actually painted by Windows.

In contrast, TBtnBmp and TFlatBtn do not depend on any Windows control and paint the entire button themselves.