Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Compare two Classes
Message
De
25/04/2000 11:58:39
 
 
À
25/04/2000 10:08:18
Information générale
Forum:
Visual FoxPro
Catégorie:
Classes - VCX
Divers
Thread ID:
00363127
Message ID:
00363183
Vues:
12
Hi John,

>Is there a way to compare two classes to see the differences in code. Like when you get several copies of a class and want to figure out which is the one you want?
>

My partner wrote the following program do do what you are asking. I hoe it formats properly. If not, let me know and I will send an e-mail attachment.

Hope this helps, Ken



LPARAMETERS fpmodpath1,fpmodpath2,fpClass
* fpModPath1 : Required. Path and file name(including extension) of first vcx file
* fpModPath2 : Required. Path and file name(including extension) of second vcx file
* fpClass : Optional. Name of Class to compare. If omitted, program will check all classes in the libraries

* Make sure library 1 exists
IF NOT FILE(fpmodpath1)
WAIT WINDOW NOWAIT 'Module not found: '+fpmodpath1
RETURN .f.
ENDIF

* Make sure library 2 exists
IF NOT FILE(fpmodpath2)
WAIT WINDOW NOWAIT 'Module not found: '+fpmodpath2
RETURN .f.
ENDIF

* Check to see if we compare just one class
IF NOT EMPTY(fpClass)
lcClass=ALLTRIM(UPPER(fpClass))
ELSE
lcClass=''
ENDIF

* Open library1 as a table
IF USED('MODFILE1')
USE IN MODFILE1
ENDIF
USE (fpModpath1) ALIAS MODFILE1 AGAIN IN 0 NOUPDATE SHARED

* Open library2 as a table
IF USED('MODFILE2')
USE IN MODFILE2
ENDIF
USE (fpModpath2) ALIAS MODFILE2 AGAIN IN 0 NOUPDATE SHARED


* Use a select statement to match up the classes and objects in the two libraries.
* Any rows with NULLs
SELECT ;
NVL(MF1.Platform,SPACE(7)) AS Platform1,;
NVL(MF1.Class,'') AS Class1,;
NVL(MF1.BaseClass,'') AS BaseClass1,;
NVL(MF1.Objname,'') AS ObjName1,;
NVL(MF1.Parent,'') AS Parent1,;
NVL(MF1.Properties,'') AS Props1,;
NVL(MF1.Methods,'') AS Methods1,;
NVL(MF2.Platform,SPACE(7)) AS Platform2,;
NVL(MF2.Class,'') AS Class2,;
NVL(MF2.BaseClass,'') AS BaseClass2,;
NVL(MF2.Objname,'') AS ObjName2,;
NVL(MF2.Parent,'') AS Parent2,;
NVL(MF2.Properties,'') AS Props2,;
NVL(MF2.Methods,'') AS Methods2;
FROM ModFile1 MF1;
FULL OUTER JOIN ModFile2 MF2 ON;
MF2.platform==mf1.platform AND;
MF2.class==mf1.class AND;
MF2.baseclass==mf1.baseclass and;
mf2.objname==mf1.objname and;
mf2.parent==mf1.parent;
INTO CURSOR cCompare

CREATE CURSOR cResults;
(cClass c(20),;
cObjName c(20),;
cParent c(40),;
cResult M,;
cProps1 M,;
cMethods1 M,;
cProps2 M,;
cMethods2 M)

SELECT cCompare
IF NOT EMPTY(lcClass)
LOCATE FOR (UPPER(ALLTRIM(ObjName1))==lcClass AND EMPTY(parent1)) OR;
(UPPER(ALLTRIM(ObjName2))==lcClass AND EMPTY(parent2))
ELSE
GO TOP
ENDIF
lcCR=CHR(13)
llNew=.t.
llDone=.f.
SCAN REST WHILE NOT EOF() AND NOT llDone
IF cCompare.Platform1='COMMENT' OR cCompare.PlatForm2='COMMENT'
llNew=.t.
lcCurrClass=''
IF NOT EMPTY(lcClass)
llDone=.t.
ENDIF
LOOP
ENDIF
IF llNew
llNew=.f.
IF NOT EMPTY(cCompare.ObjName1)
lcCurrClass=ALLTRIM(cCompare.ObjName1)
ELSE
lcCurrClass=ALLTRIM(cCompare.ObjName2)
ENDIF
WAIT WINDOW NOWAIT 'Checking class: ['+lcCurrClass+']'
ENDIF
DO CASE
CASE EMPTY(cCompare.PlatForm1)
* This row is not in module 1
IF EMPTY(cCompare.Parent2)
lcResult='Class ('+lcCurrClass+') is not in Library 1 ('+fpModPath1+')'
ELSE
lcResult='Object ('+ALLTRIM(cCompare.Parent2)+'.'+ALLTRIM(cCompare.ObjName2)+') is not in Library 1 ('+fpModPath1+')'
ENDIF
INSERT INTO cResults;
(cClass,cObjName,cParent,cResult,cProps2,cMethods2);
VALUES;
(lcCurrClass,cCompare.ObjName2,cCompare.Parent2,lcResult,cCompare.Props2,cCompare.Methods2)
CASE EMPTY(cCompare.PlatForm2)
* This row is not in module 2
IF EMPTY(cCompare.Parent1)
lcResult='Class ('+lcCurrClass+') is not in Library 2 ('+fpModPath2+')'
ELSE
lcResult='Object ('+ALLTRIM(cCompare.Parent1)+'.'+ALLTRIM(cCompare.ObjName1)+') is not in Library 2 ('+fpModPath2+')'
ENDIF
INSERT INTO cResults;
(cClass,cObjName,cParent,cResult,cProps1,cMethods1);
VALUES;
(lcCurrClass,cCompare.ObjName1,cCompare.Parent1,lcResult,cCompare.Props1,cCompare.Methods1)
OTHERWISE
lcResult=""
lcPropResult=""
IF NOT ALLTRIM(cCompare.Props1)==ALLTRIM(cCompare.Props2)
*lcResult=lcResult+',Properties'
lnP1=ALINES(laPT1,cCompare.Props1)
DECLARE laP1[lnP1,2]
FOR i=1 TO lnP1
laP1[i,1]=laPT1[i]
laP1[i,2]=.f.
ENDFOR
lnP2=ALINES(laPT2,cCompare.Props2)
DECLARE laP2[lnP2,2]
FOR i=1 TO lnP2
laP2[i,1]=laPT2[i]
laP2[i,2]=.f.
ENDFOR
lcPropResult=''
FOR i = 1 TO lnP1
lcProperty=LEFT(laP1[i,1],AT('=',laP1[i,1])-1)
lnElement=ASCAN(laP2,lcProperty+'=')
IF lnElement=0
lnPropRow=0
ELSE
lnPropRow=ASUBSCRIPT(laP2,lnElement,1)
ENDIF
IF lnPropRow=0
lcVal1=SUBSTR(laP1[i,1],AT('=',laP1[i,1])+1)
IF EMPTY(lcVal1)
lcVal1=' .Null.'
ENDIF
lcPropResult=lcPropResult+PADR(lcProperty,24)+SPACE(1)+PADR(lcVal1,31)+SPACE(1)+PADR('N/A',30)+lcCR
laP1[i,2]=.t.
ELSE
IF NOT laP1[i,1]==laP2[lnPropRow,1]
lcVal1=SUBSTR(laP1[i,1],AT("=",laP1[i,1])+1)
lcVal2=SUBSTR(laP2[lnPropRow,1],AT("=",laP2[lnPropRow,1])+1)
IF EMPTY(lcVal2)
lcVal2='.Null.'
ENDIF
IF EMPTY(lcVal1)
lcVal1='.Null.'
ENDIF
lcPropResult=lcPropResult+PADR(lcProperty,24)+SPACE(1)+PADR(lcVal1,30)+SPACE(1)+PADR(lcVal2,30)+lcCR
ENDIF
laP1[i,2]=.t.
laP2[lnPropRow,2]=.t.
ENDIF
ENDFOR
FOR i = 1 TO lnP2
IF laP2[i,2]
LOOP
ENDIF
lcProperty=LEFT(laP2[i,1],AT('=',laP2[i,1])-1)
lnElement=ASCAN(laP1,lcProperty+'=')
IF lnElement=0
lnPropRow=0
ELSE
lnPropRow=ASUBSCRIPT(laP1,lnElement,1)
ENDIF
IF lnPropRow=0
lcVal2=SUBSTR(laP2[i,1],AT('=',laP2[i,1])+1)
IF EMPTY(lcVal2)
lcVal2='.Null.'
ENDIF
lcPropResult=lcPropResult+PADR(lcProperty,25)+SPACE(1)+PADR('N/A',29)+SPACE(1)+PADR(lcVal2,30)+lcCR
laP2[i,2]=.t.
ELSE
IF NOT laP2[i,1]==laP1[lnPropRow,1]
lcVal2=SUBSTR(laP2[i,1],AT("=",laP2[i,1])+1)
lcVal1=SUBSTR(laP1[lnPropRow,1],AT("=",laP1[lnPropRow,1])+1)
IF EMPTY(lcVal2)
lcVal2='.Null.'
ENDIF
IF EMPTY(lcVal1)
lcVal1='.Null.'
ENDIF
lcPropResult=lcPropResult+PADR(lcProperty,24)+SPACE(1)+PADR(lcVal1,30)+SPACE(1)+PADR(lcVal2,30)+lcCR
ENDIF
laP2[i,2]=.t.
laP1[lnPropRow,2]=.t.
ENDIF
ENDFOR
lcPropResult= 'PROPERTIES'+SPACE(16)+'VALUES-LIBRARY 1'+SPACE(15)+'VALUES-LIBRARY 2'+lcCR+;
REPLICATE('=',25)+SPACE(1)+REPLICATE('=',30)+SPACE(1)+REPLICATE('=',30)+lcCR+lcPropResult+lcCR+lcCR
ENDIF

lcMethResult=''
IF NOT ALLTRIM(cCompare.Methods1)==ALLTRIM(cCompare.Methods2)
lnM1=ALINE(laMT1,cCompare.Methods1)
lnM2=ALINE(laMT2,cCompare.Methods2)
DECLARE laM1[lnM1,2]
FOR i = 1 TO lnM1
laM1[i,1]=laMT1[i]
laM1[i,2]=.f.
ENDFOR
DECLARE laM2[lnM2,2]
FOR i = 1 TO lnM2
laM2[i,1]=laMT2[i]
laM2[i,2]=.f.
ENDFOR
llChanged=.f.
lcTmpMeth=''
lcMeth1=''
lcMeth2=''
lcMeths=''
FOR i = 1 TO lnM1
IF laM1[i,1]='PROCEDURE '
* Start of a new procedure
IF laM1[i,2]
llSkip=.t.
LOOP
ENDIF
lcTmpMeth = ALLTRIM(SUBSTR(laM1[i,1],AT('PROCEDURE ',laM1[i,1])+10))
lnElement=ASCAN(laMT2,laM1[i,1])
IF lnElement=0
llSKip=.t.
lcMeth1=lcMeth1+SPACE(2)+lcTmpMeth+lcCR
laM1[i,2]=.t.
ELSE
lnOffset=i-lnElement
llSkip=.f.
laM1[i,2]=.t.
laM2[i-lnOffSet,2]=.t.
ENDIF
LOOP
ENDIF
IF llSkip
LOOP
ENDIF
* Here, check the current method line by line.
IF NOT BETWEEN(i-lnOffSet,1,lnM2) OR NOT laM1[i,1]==laM2[i-lnOffset,1]
lcMeths=lcMeths+SPACE(2)+lcTmpMeth+lcCR
llSkip=.t.
ENDIF
ENDFOR

FOR i = 1 TO lnM2
IF laM2[i,1]='PROCEDURE '
* Start of a new procedure
IF laM2[i,2]
llSkip=.t.
LOOP
ENDIF
lcTmpMeth = ALLTRIM(SUBSTR(laM2[i,1],AT('PROCEDURE ',laM2[i,1])+10))
lnElement=ASCAN(laMT1,laM2[i,1])
IF lnElement=0
llSKip=.t.
lcMeth2=lcMeth2+SPACE(2)+lcTmpMeth+lcCR
laM2[i,2]=.t.
ELSE
lnOffset=i-lnElement
llSkip=.f.
laM2[i,2]=.t.
laM1[i-lnOffSet,2]=.t.
ENDIF
LOOP
ENDIF
IF llSkip
LOOP
ENDIF
* Here, check the current method line by line.
IF NOT BETWEEN(i-lnOffSet,1,lnM1) OR NOT laM2[i,1]==laM1[i-lnOffset,1]
lcMeths=lcMeths+SPACE(2)+lcTmpMeth+lcCR
llSkip=.t.
ENDIF
ENDFOR
IF NOT EMPTY(lcMeth1)
lcMeth1='Methods that are in Library 1 ('+fpModPath1+') but not in Library 2 ('+fpModPath2+')'+lcCR+lcMeth1+lcCR
ENDIF
IF NOT EMPTY(lcMeth2)
lcMeth2='Methods that are in Library 2 ('+fpModPath2+') but not in Library 1 ('+fpModPath1+')'+lcCR+lcMeth2+lcCR
ENDIF
IF NOT EMPTY(lcMeths)
lcMeths='Methods that are in both libraries but are not the same'+lcCR+lcMeths
ENDIF
lcMethResult=lcMeth1+lcMeth2+lcMeths
If NOT EMPTY(lcMethResult)
lcMethResult='METHODS'+lcCR+REPLICATE('=',7)+lcCR+lcMethResult
ENDIF
ENDIF

IF NOT EMPTY(lcResult) OR NOT EMPTY(lcPropResult) OR NOT EMPTY(lcMethResult)
IF UPPER(ALLTRIM(lcCurrClass))=UPPER(ALLTRIM(cCompare.objName1)) OR lcCurrClass=UPPER(ALLTRIM(cCompare.ObjName2))
lcResult='Class '+lcCurrClass+lcCR+lcCR+'Library 1 : '+fpModPath1+lcCR+'Library 2 : '+fpModPath2+lcCR+lcCR+lcPropResult+lcMethResult
ELSE
IF EMPTY(cCompare.Parent1)
lcResult='Object '+ALLTRIM(cCompare.Parent2)+'.'+ALLTRIM(cCompare.ObjName2)+lcCR+lcCR+'Library 1 : '+fpModPath1+lcCR+'Library 2 : '+fpModPath2+lcCR+lcCR+lcPropResult+lcMethResult
ELSE
lcResult='Object '+ALLTRIM(cCompare.Parent1)+'.'+ALLTRIM(cCompare.ObjName1)+lcCR+lcCR+'Library 1 : '+fpModPath1+lcCR+'Library 2 : '+fpModPath2+lcCR+lcCR+lcPropResult+lcMethResult
ENDIF
ENDIF

INSERT INTO cResults;
(cClass,cObjName,cParent,cResult,cProps1,cMethods1,cProps2,cMethods2);
VALUES;
(lcCurrClass,cCompare.ObjName1,cCompare.Parent1,lcResult,cCompare.Props1,cCompare.Methods1,cCompare.Props2,cCompare.Methods2)
ENDIF
ENDCASE
ENDSCAN

SELECT cResults
GO TOP
BROWSE LAST NOWAIT
IF USED('MODFILE1')
USE IN ModFile1
ENDIF
IF USED('MODFILE2')
USE IN ModFile2
ENDIF
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform