Page 1 of 2

Macro get problem

Posted: Thu Jan 28, 2021 1:50 pm
by zolifree
Hi Roger!

I found a problem when using GET for a database field with a macro.
This is sample program:

Code: Select all

#INCLUDE "dcdialog.ch"
#pragma Library("dclipx.lib")
PROC appsys
RETURN
PROCEDURE DBESYS
DbeLoad("FOXDBE")
DbeLoad("CDXDBE")
DbeBuild("FOXCDX","FOXDBE","CDXDBE")
RETURN
PROCEDURE main
LOCAL i, GetList[0], GetOptions,instdbf:={}
aadd(instdbf,{"field1","C",30,0})
aadd(instdbf,{"field2","C",30,0})
aadd(instdbf,{"field3","C",30,0})
dbcreate("testdbf.dbf",instdbf)
use testdbf new exclusive
if lastrec()=0
 append blank
endif
wget1="testdbf->field1"
wget2="testdbf->field2"
wget3="testdbf->field3"

@ 1, 1 DCSAY "Get 1" GET &wget1
@ 2, 1 DCSAY "Get 2" GET &wget2
@ 3, 1 DCSAY "Get 3" GET &wget3

DCREAD GUI addbuttons enterexit TITLE 'Macro GET Test' 

dcmsgbox field1,field2,field3
RETURN
In exp 267 it is impossible to change the data in gets, but in exp 265 works well.

I found the source of the problem in _dcgetbx.prg
In FUNCTION DC_GetAnchorCB(....

Code: Select all

        RETURN {|x,y,z|GetSetAliased(x,y,z,uVar,cAlias)}               <<<< Remove this line

/*      <<<< Remove this line

       RETURN  {|x,y,z,l| ;
                 IIF(Valtype(y)=='O' .AND. IsMemberVar(y,'DATAALIAS'), ;
                 y:dataAlias := cAlias,nil), ;
                 IIf( x==nil .OR. uVar==x, uVar, ;
                 (l:=!(cAlias)->(RecNo())$(cAlias)->(dbRLockList()), ;
                 IIF(l,(cAlias)->(dbRLock()),nil), ;
                 uVar:=x, ;
                 IIF(l,(cAlias)->(dbRUnlock()),nil)))}
*/    <<<< Remove this line
If I remove the 3 (<<<<<) lines from the code, the problem disappears.
It restore this part of the code to the exp 266 version.

I think it is not the best solution, because there was a reason why You changed it, and it can cause other problems I am not aware now.

Best regards,
Zoltan

Re: Macro get problem

Posted: Fri Jan 29, 2021 9:41 am
by rdonnay
I recently fixed a similar problem for another customer with the following code change:

Code: Select all

STATIC FUNCTION GetSetAliased( x, y, z, uVar, cAlias )

LOCAL lNeedsLock

IF Valtype(y)=='O' .AND. IsMemberVar(y,'DATAALIAS')
  y:dataAlias := cAlias
ENDIF

lNeedsLock :=!(cAlias)->(RecNo())$(cAlias)->(dbRLockList()) .AND. x # nil .AND. x # uVar
IF lNeedsLock
  (cAlias)->(dbRLock())
ENDIF

IF x==nil .OR. uVar == x
 // uVar := uVar
ELSE
  uVar := x
ENDIF
IF lNeedsLock
  (cAlias)->(dbRUnlock())
ENDIF

RETURN uVar

Re: Macro get problem

Posted: Fri Jan 29, 2021 12:57 pm
by zolifree
I tried it and not working, the result is same as before.
Try testing with my test program.

Re: Macro get problem

Posted: Fri Jan 29, 2021 2:25 pm
by rdonnay
I need a test program.

Re: Macro get problem

Posted: Fri Jan 29, 2021 4:58 pm
by zolifree
It is in my first post.
The first code part is a standalone test program.
This is it:

Code: Select all

#INCLUDE "dcdialog.ch"
#pragma Library("dclipx.lib")
PROC appsys
RETURN
PROCEDURE DBESYS
DbeLoad("FOXDBE")
DbeLoad("CDXDBE")
DbeBuild("FOXCDX","FOXDBE","CDXDBE")
RETURN
PROCEDURE main
LOCAL i, GetList[0], GetOptions,instdbf:={}
aadd(instdbf,{"field1","C",30,0})
aadd(instdbf,{"field2","C",30,0})
aadd(instdbf,{"field3","C",30,0})
if !file("testdbf.dbf")
 dbcreate("testdbf.dbf",instdbf)
endif
use testdbf new exclusive
if lastrec()=0
 append blank
endif
wget1="testdbf->field1"
wget2="testdbf->field2"
wget3="testdbf->field3"

@ 1, 1 DCSAY "Get 1" GET &wget1
@ 2, 1 DCSAY "Get 2" GET &wget2
@ 3, 1 DCSAY "Get 3" GET &wget3

DCREAD GUI addbuttons enterexit TITLE 'Macro GET Test' 

dcmsgbox field1,field2,field3
RETURN

Re: Macro get problem

Posted: Sat Jan 30, 2021 8:37 am
by rdonnay
Your sample program works fine with my current version of _DCGETBX.PRG

Re: Macro get problem

Posted: Sat Jan 30, 2021 12:14 pm
by zolifree
I tried to use this, but still not working here.
Try with the original dclipx.dll as it is after installing it.
I attached a zip file with the dclipx.dll and the test program.

When You write something in the gets, after the enter key the changes disappears in the edit box.

Re: Macro get problem

Posted: Sat Jan 30, 2021 1:36 pm
by rdonnay
This file works

Re: Macro get problem

Posted: Sat Jan 30, 2021 2:13 pm
by zolifree
Yes it is working, but I need the source code too.
A made some customizations in the source code for my needs, so I need the source to be able to make my own dclipx.dll

Re: Macro get problem

Posted: Sat Jan 30, 2021 4:20 pm
by rdonnay
Yes it is working, but I need the source code too.
I gave you the source code in a previous response to this thread. It is in _DCGETBX.PRG.

Copy it to your \exp20\source\dclipx folder and run build20.bat to rebuild dclipx.dll