Hi,
How to display difference between two forms. ALL properties. I try COMPOBJ(), but no work to me.
Any suggestion or maybe FAQ number.
I use VFP 8 and I am BEGGINER in VFP.
Thanks!
Milos
It's not clear whether you want to compare the properties or the values of the properties.
Either way, you can use AMEMBERS() to get the names of the properties into an array. Do that with both the forms. Then loop through one array; for each element, scan the second array to compare the properties (or their values).
You can spin thru each form to get the objects and save them into a table. Do that for both forms and then run a SQL SELECT with a FULL JOIN. Anything with a match will be on both forms, anything on the left but NULL on the right will have a value in the first form only, and anything with a value on right but a NULL on the left will give you the objects that occur just on the second form.
* basic code for spinning thru objects. You will need to modify it to create the tables and full join SQL.
FOR EACH loTxt IN THISFORM.Objects
IF UPPER(loTxt.baseClass) = "TEXTBOX"
* do nothing - just for demonstration purposes.
ENDIF
Just to amplify on your code, I guess you'd also have to drill down into any container controls on the form. For example, if the form contains a page frame, you'd have to loop through all its pages, then loop through the controls on each page.
Perhaps we should have asked you: why do you want to do this? Comparing all the properties on two forms ... that's not something you would normally have any reason to do.
Mike,
I have two projects with equal (I think!) form. In the first is all OK in second NO. Probably one is a little modified.I can't find a difference. I'm thinking that me will this still happen. As beginner I will sure many times use this comparison.
A useful trick is to right-click in the property window -- just above the tabs -- and select 'non-default properties only'. This will show you only the properties that you have modified. That should make it easier to see the problem.
Mike,
I always use "non default properties only" when comparing two forms. I have "page frame" on these forms. It is very time dilatory. I found a program OBJINSPECTOR.PRG on the internet. Do you think it could help me, and if so, how?? The program is located on
In comlex forms it takes many hours to compare all "properties", so it would make sense to write a program that would output the differnces.
I am waiting to your response.
I am not familiar with the program you mentioned. But if you think you can write your own, that would be a good idea. If nothing else, it would be a good training exercise.
This is a crude utility, use it at your own risk. If this helps I am happy. This is an extract from my form editing tool which I am unable to share openly. So I quickly extracted only some part to make a comparison. Anyway, the form editing tool is getting obsolete after VFP8, which has all the facilities to look up parent codes easily.
********************************************************
**************************************************
** Program : GsEdit.Prg
** Author : Subramanian.G
** Utility to compare two forms.
**************************************************
** PROCEDURE gsEdit
**************************************************
** Close all tables and display a help message
gsANSI = SET("ANSI"
gsSAFETY = SET("SAFETY"
gsEXACT = SET("EXACT"
SET ANSI ON
SET SAFETY OFF
SET EXACT ON
SET DELETED ON
SET ENGINEBEHAVIOR 70
CLOSE TABLES ALL
**************************************************
** Get the first form
cForm1 = getForm("Select the first form"
IF EMPTY(cForm1)
=MESSAGEBOX("No Form Selected"
RETURN .f.
ENDIF
** Get the second form
cForm2 = getForm("Select the second form"
DO WHILE cForm1 = cForm2
=MESSAGEBOX("The first and second form chosen are the same",0)
cForm2 = getForm("Select the second form"
IF EMPTY(cForm2)
EXIT
ENDIF
ENDDO
IF EMPTY(cForm2)
=MESSAGEBOX("No Form Selected for comparison"
RETURN .f.
ENDIF
**************************************************
** Collect form1 PEMS
MODIFY FORM (cForm1) NOWAIT
IF ASELOBJ(laForm,1) < 1
=MESSAGEBOX("Cannot open Form One Selected"
RETURN .f.
ENDIF
gsoForm = laForm(1)
DO gsEdit1 WITH gsoForm
SELECT * FROM gsPEM INTO DBF gsPEM1 ORDER BY 1
CLOSE ALL
**
** Collect form2 PEMS
MODIFY FORM (cForm2) NOWAIT
IF ASELOBJ(laForm,1) < 1
=MESSAGEBOX("Cannot open Form One Selected"
RETURN .f.
ENDIF
gsoForm = laForm(1)
DO gsEdit1 WITH gsoForm
SELECT * FROM gsPEM INTO DBF gsPEM2 ORDER BY 1
CLOSE ALL
**************************************************
SELECT a.obj_ref, a.obj_pem, a.obj_val, a.obj_valC, ;
b.obj_val AS obj_val2, b.obj_valC AS obj_valc2, ;
b.obj_ref AS obj_ref2, b.obj_pem AS obj_pem2 ;
FROM gsPEM1 a FULL OUTER JOIN gsPEM2 b ;
ON a.obj_ref+a.obj_pem == b.obj_ref+b.obj_pem ;
ORDER BY a.obj_ref,a.obj_pem, b.obj_ref, b.obj_pem ;
INTO CURSOR gsPem
BROWSE FIELDS Name1 = ALLTRIM(obj_ref)+"."+ALLTRIM(obj_pem):40, ;
obj_Val:H="Form1 Value":R, ;
obj_ValC:H="Form1 Value":R, ;
obj_ValC2:H="Form2 Value":R, ;
obj_Val2:H="Form2 Value":R, ;
Name2 = ALLTRIM(obj_ref2)+"."+ALLTRIM(obj_pem2):40 ;
FONT "CourierNew",11 IN SCREEN ;
Title "Objects Comparison Listing" ;
FOR NVL(obj_val,"" # NVL(obj_val2,""
**************************************************
** Cleanup
ERASE gePem1.*
ERASE gePem2.*
**
SET ANSI &gsANSI
SET SAFETY &gsSAFETY
SET EXACT &gsEXACT
RELEASE ALL LIKE gs*
RETURN
**************************************************
** EOP
**************************************************
PROCEDURE gsEdit1
LPARAMETERS gsoForm
** Cursor to hold all the PEMs of objects
CREATE CURSOR gsPEM (obj_ref C(125), obj_pem C(25), ;
obj_type C(15), obj_name M, obj_val M, obj_valC C(15))
SCATTER MEMVAR BLANK
** get the objects PEM in a table
gsoNowObject = gsoForm
gscNowObjectParent = ""
DO getPEMs2
** Create an array to hold the objects temporarily
DIMENSION gsaObject(32500,2)
gsaObject(1,1) = gsoForm
gsaObject(1,2) = gsoForm.Name
** get the sub objects PEM in the same table as above
gsnObject = 1
gsnNextObject = 2
DO WHILE .t.
LOCAL oPage, oColumn, oButton
FOR EACH m.oThis IN gsaObject(gsnObject,1).Controls
gscNowObjectParent = gsaObject(gsnObject,2)+"."
gsoNowObject = m.oThis
DO getPEMs1
DO CASE
CASE m.oThis.BaseClass == 'Pageframe'
LOCAL oPage
gscNowObjectParent = gsaObject(gsnObject,2)+"."+oThis.Name+"."
FOR EACH oPage IN m.oThis.Pages
gsoNowObject = m.oPage
DO getPEMs1
ENDFOR
CASE m.oThis.BaseClass == 'Grid'
LOCAL oColumn
gscNowObjectParent = gsaObject(gsnObject,2)+"."+oThis.Name+"."
FOR EACH oColumn IN m.oThis.Columns
gsoNowObject = m.oColumn
DO getPEMs1
ENDFOR
CASE m.oThis.BaseClass $ 'Commandgroup,Optiongroup'
LOCAL oButton
gscNowObjectParent = gsaObject(gsnObject,2)+"."+oThis.Name+"."
FOR EACH oButton IN m.oThis.Buttons
gsoNowObject = m.oButton
DO getPEMs1
ENDFOR
ENDCASE
ENDFOR
gsnObject = gsnObject+1
IF gsnObject = gsnNextObject
EXIT
ENDIF
ENDDO
*
RETURN
*********************************************************
PROCEDURE getPEMs1
** obtain contained objects for further probe
DO getPEMs2
LOCAL gscBclass
gscBclass = UPPER(gsoNowObject.BaseClass)
IF gscBclass == "COLUMN" oR gscBclass == "CONTAINER" ;
OR gscBclass == "FORM" OR gscBclass == "PAGE" ;
OR gscBclass == "TOOLBAR" oR gscBclass == "CONTROL"
gsaObject(gsnNextObject,1) = gsoNowObject
gsaObject(gsnNextObject,2) = gscNowObjectParent+gsoNowObject.Name
gsnNextObject = gsnNextObject+1
ENDIF
RETURN
*********************************************************
PROCEDURE getPEMs2
** Get the objects members
=AMEMBERS(gsoArray,gsoNowObject,1,"C"
** Read the members and get them into a table
FOR gsnCount = 1 TO ALEN(gsoArray,1)
m.obj_ref = gscNowObjectParent+gsoNowObject.Name
m.obj_pem = gsoArray(gsnCount,1)
m.obj_type = gsoArray(gsnCount,2)
m.obj_name = m.obj_ref+"."+m.obj_pem
** get the event/method code or propety value
DO CASE
CASE UPPER(ALLTRIM(m.obj_type)) = "METHOD"
m.obj_val = GETPEM(gsoNowObject,gsoArray(gsnCount,1))
CASE UPPER(ALLTRIM(m.obj_type)) = "EVENT"
m.obj_val = GETPEM(gsoNowObject,gsoArray(gsnCount,1))
CASE UPPER(ALLTRIM(m.obj_type)) = "PROPERTY"
gsCode = GETPEM(gsoNowObject,gsoArray(gsnCount,1))
IF TYPE("gsCode" = "C"
m.obj_val = GETPEM(gsoNowObject,gsoArray(gsnCount,1))
ENDIF
IF TYPE("gsCode" $ "N"
m.obj_val = ALLTRIM(STR(GETPEM(gsoNowObject,gsoArray(gsnCount,1))))
ENDIF
IF TYPE("gsCode" $ "D"
m.obj_val = DTOC(GETPEM(gsoNowObject,gsoArray(gsnCount,1)))
ENDIF
IF TYPE("gsCode" $ "L"
IF gsCode = .t.
m.obj_val = ".t."
ELSE
m.obj_val = ".f."
ENDIF
ENDIF
m.obj_valC = m.obj_val
ENDCASE
INSERT INTO gsPEM FROM MEMVAR
ENDFOR
RETURN
*********************************************************
PROCEDURE getform
LPARAMETERS tText
IF PCOUNT() < 1
tText = "Select a Form"
ENDIF
RETURN GETFILE("SCX",tText)
*********************************************************
** EOF
*********************************************************
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.