was ist neu ¦  programmier tips ¦  indy artikel ¦  intraweb artikel ¦  informationen ¦  links ¦  interviews
 sonstiges ¦  tutorials ¦  Add&Win Gewinnspiel

Tips (1541)

Dateien (137)
Datenbanken (90)
Drucken (35)
Grafik (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Mathematik (76)
Multimedia (45)
Oberfläche (107)
Objekte/
ActiveX (51)

OpenTools API (3)
Sonstiges (126)
Strings (83)
System (266)
VCL (242)

Tips sortiert nach
Komponente


Tip suchen

Tip hinzufügen

Add&Win Gewinnspiel

Werbung

40 Visitors Online


 
...in einem TMemo mittels TFindDialog suchen?
Autor: P. Below
[ Tip ausdrucken ]  

Tip Bewertung (45):  
     


  private
    
{ Private declarations }
    
FSelPos: integer;
  public
    
{ Public declarations }
  
end;

var
  
Form1 : TForm1;

implementation

{$R *.dfm}

procedure TForm1.FindDialog1Find(Sender : TObject);
var
  
S : string;
  startpos : integer;
begin
  with 
TFindDialog(Sender) do
  begin
    
{If the stored position is 0 this cannot be a find next. }
    
if FSelPos = 0 then
      
Options := Options - [frFindNext];

     { Figure out where to start the search and get the corresponding
       text from the memo. }
    
if frfindNext in Options then
    begin
      
{ This is a find next, start after the end of the last found word. }
      
StartPos := FSelPos + Length(Findtext);
      S := Copy(Memo1.Lines.Text, StartPos, MaxInt);
    end
    else
    begin
      
{ This is a find first, start at the, well, start. }
      
S := Memo1.Lines.Text;
      StartPos := 1;
    end;
    { Perform a global case-sensitive search for FindText in S }
    
FSelPos := Pos(FindText, S);
    if FSelPos > 0 then
    begin
       
{ Found something, correct position for the location of the start
         of search. }
      
FSelPos := FSelPos + StartPos - 1;
      Memo1.SelStart := FSelPos - 1;
      Memo1.SelLength := Length(FindText);
      Memo1.SetFocus;
    end
    else
    begin
      
{ No joy, show a message. }
      
if frfindNext in Options then
        
S := Concat('There are no further occurences of "', FindText,
          '" in Memo1.')
      else
        
S := Concat('Could not find "', FindText, '" in Memo1.');
      MessageDlg(S, mtError, [mbOK], 0);
    end;
  end;
end;

// Show the FindDialog
// Den FindDialog anzeigen

procedure TForm1.Button1Click(Sender : TObject);
begin
  
FSelPos := 0;
  FindDialog1.Execute;
end;

 

Bewerten Sie diesen Tipp:

dürftig
ausgezeichnet


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners