|
Dans mon précédent message, j'avais oublié de
copier la fonction en question.
La voici :
Function correctedGetString(theCursor As Object) As
String
' La méthode XTextRange.getString() fonctionne
incorrectement si elle doit lire
' une chaîne d'au moins 10240 caractères (elle ajoute un caractère NULL à la fin, ' et fait peut-être pis dans certains cas). ' La présente fonction est un palliatif. Dim ourText As Object
Dim leftExtr As Object Dim rightExtr As Object Dim ourCursor As Object Dim ourString As String Dim stringToBeAdded As String ourText = theCursor.getText() ' Always defined, even for a view cursor ??? If ourText.compareRegionEnds(theCursor.getStart(), theCursor.getEnd()) < 0 Then leftExtr = theCursor.getEnd() rightExtr = theCursor.getStart() Else leftExtr = theCursor.getStart() rightExtr = theCursor.getEnd() End If ourCursor =
ourText.createTextCursorByRange(leftExtr)
ourString = "" ourCursor.goRight(5119, True) ' On ne met
pas 10239, parce qu'une position peut correspondre à deux
' caractères (Chr(13) & Chr(10). Do While
ourText.compareRegionEnds(ourCursor, rightExtr) >= 0 ' ourCursor is on the
left of rightExtr, or
' coincides with it. stringToBeAdded =
ourCursor.getString()
If Len(ourString) +
Len(stringToBeAdded) > 65535 Then
MsgBox "La fonction correctedGetString() a été appelée avec un paramètre curseur qui couvre plus de 65535 caractères de chaîne." Stop End If ourString = ourString & ourCursor.getString() ourCursor.collapseToEnd() ourCursor.goRight(5119, True) Loop ' ourCursor.goToRange(rightExtr, True) ' J'aurais cru que cela "désélectionnerait", comme un retour ' de souris, mais cela ne semble pas être le cas. ' Je mets donc les deux commandes suivantes : ourCursor.collapseToStart()
ourCursor.goToRange(rightExtr, True) stringToBeAdded = ourCursor.getString() If Len(ourString) + Len(stringToBeAdded)
> 65535 Then
MsgBox "La fonction correctedGetString() a été appelée avec un paramètre curseur qui couvre plus de 65535 caractères de chaîne." Stop End If correctedGetString = ourString &
ourCursor.getString()
End Function |
- [prog] Palliatif pour XTextRange.getString() Adrien Delcour
- [prog] Palliatif pour XTextRange.getString() Adrien Delcour
- [prog] Palliatif pour XTextRange.getString() Adrien Delcour
