Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Detail Overflows to new page
Message
De
03/09/2003 00:47:43
Vladimir Zhuravlev
Institute of the Physics of Earth,Russia
Moscow Region, Russie
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Divers
Thread ID:
00825172
Message ID:
00825541
Vues:
21
>>I just did this task for Korney
>>There are 2 functions, one for calculatimg current string on the report and other for group , which always print on new page and makes pages breakes
>>I shall ask Korney, if he agree, I mail you the code and sample
>>Best wishes, Vladimir
>
>Is it the problem you discussed on nsvisual/fox2 before the recent sad >events with the site? Did you solve it? Congrats! I guess, if Korney (is it >a person's name?) gives you permission, you better publish the solution here.

Yes, Nadia. We solved it with Korney Wott, who needed it for his client.
I am ready to publish the solution, limitations and future improvment.
Now we assume, that memo is at the same line in details band with regular fields. The details band is tight to memmo and other filelds
Other assumption is, we know in advance, how many regular lines without memo can be printed at first page and other pages. Now it is set to 20-21 lines constant. Limitations are not serious and we already work on removing it.
I like to remind the goal, to prevent memo from splitting between pages.
Here is the code of the main program
Best wishes, Vladimir Zhuravlev
______
	PUBLIC nSumNotBroken, nListPageN, nListPage1
	nSumNotBroken	= 0
	nListPage1		=  10
	nListPageN		=  20


&&  here your path	
*	CD C:\Projekte\Erfahrung\TOword\rep_newpage3   


	frx=NEWOBJECT('frx','frx')
	frx.getfrx('desk','tst.frx')
	SET PROCEDURE TO modul.prg
	set CLASSLIB to frx.vcx

	IF USED('_Nord')
		USE IN _Nord
	ENDIF 
	CREATE CURSOR _Nord(_nRec n(3), _nMemoLine n(3) )
    INDEX ON _nRec TAG _nRec 
	IF !USED('tst')
		USE tst IN 0
	ENDIF 
	SELECT tst

	SCAN 
	IF RECNO()=7
	    SET STEP ON 
	    memstr_wladimir(tst.desk)
	endif
		INSERT INTO _Nord (_nRec,_nMemoLine) VALUES (RECNO('tst'), memstr_wladimir(tst.desk)) 
	ENDSCAN 
	GO TOP IN _Nord 
	GO top
  SELECT _nord
brow
	REPORT ALL form tst.frx PREVIEW NOCONSOLE
---------------------
Function memstr_vladimir reads records with memo and calculates, how many lines it will take for each record.
Report name is called tst.frx, desc is name of the memo field.
Class frx reads report file and look the length of the memo in pixels, fontname, fontsize etc
Here we shall add later also page size, height, available for details band.
The code for frx, getfrx method is
Lparameter _exp,_rep
oldal=Alias()

If File(_rep)
	Use (_rep) In 0 Alias rep
	Select rep
	Go Top
	Locate For objtype=9 And objcode=0
	If Found()
		This.Title=Height
	Endif
	Go Top
	Locate For objtype=9 And objcode=1
	If Found()
		This.pagehead=Height
	ENDIF
	GO top
	Locate For (Upper(Alltrim(Expr)))='"'+(Upper(Alltrim(_exp)))+'"'
	If Found()
		This.Width =Width
		This.FontName=fontface
		This.FontSize=FontSize
	Endif
	If Not Empty(m.oldal)
		Select (m.oldal)
	Endif
	Use In rep
	Return
Endif
___________________________-
So now we know in advance, how many lines we have for each record.
In the report we make variable-_ln, which sums numbers of lines at page till current line and reset it to 0 at the end of the page. The variable stores
the result of makestr function
. We also do some program group, wich makes page brakes.
The option to start group at new page is set in the report.
It is done by other function make_broken .
It looks for next record in _nord cursor, makes sum of _ln and future numbers of lines, If it sees, we have no more free space, it change group at 1.
Here is the code of modul.prg
Procedure makestr   &&  make_broken(RECNO('tst'),_PAGENO)

Lparameters nRec
If Seek(nRec,'_nord','_nRec')	
	Return _Nord._nMemoLine
Else
	Return 0
Endif
Endproc
Procedure make_broken   &&  make_broken(RECNO('tst'),_PAGENO)

Lparameters nRec, _nPage
*	GO nRec IN _Nord
*	SKIP IN _Nord
If Seek(nRec+1,'_nord','_nRec') AND NOT EOF('tst')
    IF _Nord._nMemoLine >= nListPageN
**    the memo is so big that always be splitted 
    Return nSumNotBroken
    endif
	If _ln + _Nord._nMemoLine > nListPageN && IIF(_nPage>1, nListPageN, nListPage1 )
		nSumNotBroken = nSumNotBroken + 1
	Endif

	Return nSumNotBroken
Else
	Return nSumNotBroken
Endif
Endproc

Procedure _TXTWIDTH
Lparameters _str, _fontname, _fontsize
Return Txtwidth(Alltrim(_str ),_fontname,_fontsize)* Fontmetric(6,_fontname,_fontsize)
ENDPROC

PROCEDURE memstr_new
Lparameters _txt
ii=1
jj=0
m.strr= Mline(_txt, ii)      && Display each line
If Empty(m.strr)
	Return 0
Endif
Do While Not Empty(m.strr)
	jj=jj+1
	m.rt=Int(_TXTWIDTH(m.strr,frx.FontName,frx.FontSize)/frx.Width)
	jj=jj+m.rt
	ii=ii+1
	m.strr= Mline(_txt, ii)
Enddo
Return jj 
ENDPROC 

**  von mir
Procedure memstr_korney
Lparameters _mem   &&  kommt memo tst.desk
_Enter=Chr(13)
_strCount = 0
m.fontname=frx.FontName
m.fontsize=frx.FontSize
 
m.width=frx.Width/166.6650
*	m.width=frx.Width* 0.0096      ??
*   nPixels = Pixel2Frx * 0.0096   ??
*m.width=200   				   ??

_nCountEnter = Occurs(_Enter,_mem)

If _nCountEnter > 0

	j = 1
	For i = 1 To _nCountEnter
		_nEnterLoc = At(_Enter,_mem,i)
		_str = Substr(_mem, j, _nEnterLoc - j )
*		WAIT WINDOW _str + _Enter + STR( Thisform._TXTWIDTH(_str,this.fontname,this.fontsize) )
		j = _nEnterLoc + 1

		_strCount = _strCount + 1 + Int(_TXTWIDTH(_str,m.fontname,m.fontsize)/m.width)

	Endfor
	_str = Substr(_mem, j )
*	WAIT WINDOW _str + _Enter + STR( Thisform._TXTWIDTH(_str,this.fontname,this.fontsize) )
	_strCount = _strCount + 1 + Int(_TXTWIDTH(_str,m.fontname,m.fontsize)/m.width)

Else

	_ganz =  _TXTWIDTH(_mem,m.fontname,m.fontsize)
*	WAIT WINDOW _mem + _Enter + STR( _ganz) + _Enter + STR( INT(_ganz/m.Width+1))
	_strCount =  Int(_ganz/m.width) + 1

Endif

Return  _strCount

Endproc




**   WLADIMIR

Procedure memstr_wladimir
Lparameters _txt

m.fontname=frx.FontName
m.fontsize=frx.FontSize
*m.fontitalic=frx.FontItalic
m.fontitalic=.F.
m.fontbold=frx.FontBold
m.width=frx.Width/166.665
m.title=frx.Title
m.pagehead=frx.pagehead
cText= Allt(_txt)
Local ;
	aText(1) ,;
	cCurSimbol,;
	cCurString,;
	cFontStyle,;
	nDim ,;
	nLenCurString,;
	nMaxLenString,;
	nPosLastSB
cCurSimbol=''
cCurString=''
cFontStyle=Iif(m.fontbold ,'B','')+Iif(m.fontitalic,'I','')
cFontStyle=Iif(Empt(cFontStyle),'N',cFontStyle)
nDim=0
nLenCurString=0
nMaxLenString=m.width
nPosLastSB=0
For i1727 = 1 To Len(cText)
	cCurSimbol=Subs(cText,i1727,1)
	Do Case
	Case cCurSimbol==Chr(13)
		nDim=nDim + 1
		Dime aText(nDim)
		aText(nDim)=cCurString
		nPosLastSB=0
		cCurString=''
		Loop
	Case cCurSimbol==Chr(32)
		cCurString=cCurString + cCurSimbol
		nPosLastSB=Len(cCurString)
		nLast= i1727
	Othe
		cCurString=cCurString + cCurSimbol
	Endcase
	If Txtwidth(cCurString,m.fontname,m.fontsize)*Fontmetric(6,m.fontname,m.fontsize)>=nMaxLenString
		nDim= nDim + 1
		Dime aText(nDim)
		If nPosLastSB=0
			nDelta=Iif(Txtwidth(cCurString,m.fontname,m.fontsize)*Fontmetric(6,m.fontname,m.fontsize)=nMaxLenString,0,1)
			aText(nDim)=Subs(cCurString,1,Len(cCurString)- nDelta)
			i1727=i1727 - nDelta
		Else
			aText(nDim)=Subs(cCurString,1, nPosLastSB - 1)
			i1727=Iif(cCurSimbol==Chr(32),i1727,nLast)
		Endi
		nPosLastSB=0
		cCurString=''
		Loop
	Endi
Endf

If!Empt(cCurString)
	nDim=nDim + 1
	Dime aText(nDim)
	aText(nDim)=cCurString
Endi
Retu nDim

Endproc
MVP-2006-2011, PHD in Math and Physics ,
host of www.foxclub.ru,
VFP lector at Interface and Microinform companies
Head science researcher of VNIIA Rosatom.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform