if frDown in FindDialog1.Options then
 begin
   //down  find code
 end else begin
   //up find code
 end

解决方案 »

  1.   

    if frDown in FindDialog1.Options then
     begin
      FoundAt := RichEdit1.FindText(FindDialog1.FindText, StartPos,
                          ToEnd, [stMatchCase])
     end 
    else begin
      FoundAt := RichEdit1.FindText(FindDialog1.FindText, StartPos,
                          ToEnd, [stMatchCase])
     end我这样写并没有作用,RichEdit1.FindText的参数没有选择是否向上或者是
    向下的参数,我该怎么写??请指点,谢谢~~~
      

  2.   

    http://edu.yn.cninfo.net/T_examination/news/14/01-4-6/news_4710_0.shtml
      

  3.   

    不明白,我想用TFindDialog控件实现向上查找的功能。
    我没有解决,请帮忙~~
      

  4.   

    unit Search;
    interface
    uses WinProcs, SysUtils, StdCtrls, Dialogs;
    const
       WordDelimiters: set of Char = [#0..#255] - ['a'..'z','A'..'Z','1'..'9','0'];
    function SearchMemo(Memo: TCustomEdit;
            const SearchString: String;Options: TFindOptions): Boolean;
    function SearchBuf(Buf: PChar; BufLen: Integer;SelStart, SelLength: Integer;
            SearchString: String;Options: TFindOptions): PChar;implementationfunction SearchMemo(Memo: TCustomEdit;const SearchString: String;
                                              Options: TFindOptions): Boolean;
    var
      Buffer, P: PChar;
      Size: Word;
    begin
      Result := False;
      if (Length(SearchString) = 0) then Exit;
      Size := Memo.GetTextLen;
      if (Size = 0) then Exit;
      Buffer := StrAlloc(Size + 1);
      try
         Memo.GetTextBuf(Buffer, Size + 1);
         P := SearchBuf(Buffer, Size, Memo.SelStart,Memo.SelLength,SearchString, Options);
         if P <> nil then
         begin
           Memo.SelStart := P - Buffer;
           Memo.SelLength := Length(SearchString);
           Result := True;
         end;
      finally
         StrDispose(Buffer);
      end;
    end;function SearchBuf(Buf: PChar; BufLen: Integer;SelStart, SelLength: Integer;
        SearchString: String;Options: TFindOptions): PChar;
    var
      SearchCount, I: Integer;
      C: Char;
      Direction: Shortint;
      CharMap: array [Char] of Char;function FindNextWordStart(var BufPtr: PChar): Boolean;
    begin { (True XOR N) is equivalent to (not N) }
     // Result := False; { (False XOR N) is equivalent to (N) }
      { When Direction is forward (1), skip nondelimiters, then skip delimiters. }
      { When Direction is backward (-1), skip delims, then skip non delims }
      while (SearchCount > 0) and ((Direction = 1) xor (BufPtr^ in WordDelimiters)) do
      begin
        Inc(BufPtr, Direction);
        Dec(SearchCount);
      end;
      while (SearchCount > 0) and ((Direction = -1) xor (BufPtr^ in WordDelimiters)) do
      begin
        Inc(BufPtr, Direction);
        Dec(SearchCount);
      end;
      Result := SearchCount > 0;
      if Direction = -1 then
      begin { back up one char, to leave ptr on first nondelim }
        Dec(BufPtr, Direction);
        Inc(SearchCount);
      end;
    end;begin
      Result := nil;
      if BufLen <= 0 then Exit;
      if frDown in Options then
      begin
        Direction := 1;
        Inc(SelStart, SelLength); { start search past end of selection }
        SearchCount := BufLen - SelStart - Length(SearchString);
        if SearchCount < 0 then Exit;
        if Longint(SelStart) + SearchCount > BufLen then
           Exit;
      end else
      begin
        Direction := -1;
        Dec(SelStart, Length(SearchString));
        SearchCount := SelStart;
      end;
      if (SelStart < 0) or (SelStart > BufLen) then Exit;
      Result := @Buf[SelStart];
      { Using a Char map array is faster than calling AnsiUpper on every character }
      for C := Low(CharMap) to High(CharMap) do
         CharMap[C] := C;
      if not (frMatchCase in Options) then
      begin
        AnsiUpperBuff(PChar(@CharMap), sizeof(CharMap));
        AnsiUpperBuff(@SearchString[1],Length(SearchString));
      end;
      while SearchCount > 0 do
      begin
        if frWholeWord in Options then
          if not FindNextWordStart(Result) then Break;
          I := 0;
          while (CharMap[Result[I]] = SearchString[I+1]) do
          begin
            Inc(I);
            if I >= Length(SearchString) then
            begin
              if (not (frWholeWord in Options)) or (SearchCount = 0) or
                (Result[I] in WordDelimiters) then
                   Exit;
              Break;
            end;
          end;
          Inc(Result, Direction);
          Dec(SearchCount);
      end;
      Result := nil;
    end;end.