PDOX9: Searching a memo field 
Author Message
 PDOX9: Searching a memo field

Hi, all. I spent all day trying to do something that seems very simple.
I have a formatted memo field in a form. Interactively, I can enter
right click in the memo field, select "Find and Replace", enter the
criteria ("Section 1" for example), and the cursor finds "Section 1" and
moves there. Does anyone know how to do this with OPAL? I'd like to
assign the criteria and do the find in the Open Event so it goes right
to the "Section 1" when the form opens. TIA.
--
Jeff Beres

"People live in their interpretations."


http://www.***.com/ ~beres/horror.htm



Fri, 06 Sep 2002 03:00:00 GMT
 PDOX9: Searching a memo field

Hello jeff,

You have to do that with a TextStream ! Not directly the memo.
There is no strings methods attaching on the memo type.

Do it this way :
Var
   MyMemo       Memo
   FileTxt      TextStream
   aLine        string
endVar  
MyMemo.WriteToFile(":PRIV:TheMemo.txt")
FileTxt.open(":PRIV:TheMemo.txt","w")
While not FileTxt.eof()
   aLine = FileTxt.readLine()
   ...
endWhile
FileTxt.close()

If you want to do a Find and replace proc, then the quickest way is
to copy the TextStream to another while modifying it...

Here is the complete code :

method FindAndReplaceMEMO(var MyMemo memo, find string, replace string,
caseSensitive logical) logical
Var
   CaseBefore   logical
   FileMemo     TextStream
   FileNewMemo  TextStream
   aLine        string
   position     longint
   lengthFind   longint
   fs           fileSystem
endVar
ErrorTrapOnWarnings(Yes)
CaseBefore = isIgnoreCaseInStringCompares()
ignoreCaseInStringCompares(CaseSensitive)
TRY
   lengthFind = find.size()
; copy the memo to a temporary file
        MyMemo.WriteToFile(":PRIV:TheMemo.txt")
        FileMemo.open(":PRIV:TheMemo.txt","r")
; create a new file for the modified memo
        FileNewMemo.create(":PRIV:TheMemo2.txt")
; reading the memo line by line
        While not FileMemo.eof()
; reading a line
        FileMemo.readLine(aLine)
; searching the text to find
      While aLine.search(find) <> 0
         position = aLine.search(find)
; giving the position a the find text
         SWITCH
; position in head
         CASE position = 1 :
            aLine = replace +
                    aLine.subStr(lengthFind + 1, aLine.size() -
lengthFind)
; position in queue
         CASE position = aLine.size() - LengthFind + 1 :
            aLine = aLine.subStr(1, position - 1) + replace
; position between head and queue
         OTHERWISE :
            aLine = aLine.subStr(1, position - 1) + replace +
                    aLine.subStr(position + lengthFind,
                    aLine.size() - position - lengthFind + 1)
         ENDSWITCH
      endWhile
; writing the modified or not modified line to the new file
      FileNewMemo.writeLine(aLine)
        endWhile
; closing and commiting the modified text file
        FileMemo.close()
        FileNewMemo.commit()
   FileNewMemo.close()
; reading the modified file to the memo
   MyMemo.readFromFile(":PRIV:TheMemo2.txt")
; deleting the temporary files
   fs.delete(":PRIV:TheMemo2.txt")
   fs.delete(":PRIV:TheMemo.txt")
ONFAIL
; what to do in error case
  errorShow()
  ErrorTrapOnWarnings(No)
  ignoreCaseInStringCompares(CaseBefore)
  if FileMemo.isAssigned()
  then
     FileMemo.close()
  endif
  fs.delete(":PRIV:TheMemo.txt")
  if FileNewMemo.isAssigned()
  then
     FileNewMemo.close()
  endif
  fs.delete(":PRIV:TheMemo.txt")
  return false
ENDTRY
; everything is ok ! GOOD JOB !!!
ErrorTrapOnWarnings(No)
ignoreCaseInStringCompares(CaseBefore)
Return true
endMethod

NOW : HOW TO USE IT :

method pushButton(var eventInfo Event)
var
  m     memo
endVar
m = MemoField.value
if FindAndReplaceMEMO(m, "dog", "animal", yes)
then
   MemoField.value = m
endif

endMethod

Please, visit :
http://perso.club-internet.fr/brouardf/Paradox_SQL.html

Frederic BROUARD - AMARIS SA Ile de France
Paradox - Delphi - SGBDR / RDBMS - SQL
http://perso.club-internet.fr/brouardf

Jeff Beres a crit :

Quote:

> Hi, all. I spent all day trying to do something that seems very simple.
> I have a formatted memo field in a form. Interactively, I can enter
> right click in the memo field, select "Find and Replace", enter the
> criteria ("Section 1" for example), and the cursor finds "Section 1" and
> moves there. Does anyone know how to do this with OPAL? I'd like to
> assign the criteria and do the find in the Open Event so it goes right
> to the "Section 1" when the form opens. TIA.
> --
> Jeff Beres

> "People live in their interpretations."


> http://www.tcnj.edu/~beres/horror.htm



Sat, 07 Sep 2002 03:00:00 GMT
 
 [ 2 post ] 

 Relevant Pages 

1. searching MEMO fields - optimization question

2. searching MEMO fields - optimization question

3. Search in memo field

4. Searching a memo field

5. Searching data in MEMO fields.

6. Searching a Paradox 7 memo field

7. search for a component DBMemo working with formated memo field

8. Delphi 2 and searching in MEMO-Fields

9. Searching in String and Memo-field

10. String search in memo field?

11. Searching Memo Fields

12. Searching in a Memo Field


 
Powered by phpBB® Forum Software