![]() |
Fehler beim allowup
Hallo,
könnt Ihr mal einen Blick auf diesen Code werfen. Case 1 ist richtig. Aber wenn ich die Markierung wieder rausnehmen möchte, wird mir ein angehangen. Habe ich einen Logik oder Verständisfehler?
Delphi-Quellcode:
// Eigenschaften:
// allowallup -> true; // groupindex -> 1; procedure TForm1.SpeedButton1Click(Sender: TObject); begin Case SpeedButton1.GroupIndex of 1: begin RichEdit1.SelText := '[b]' + RichEdit1.SelText + '[/b]'; end; 0: begin RichEdit1.SelText := StringReplace(RichEdit1.SelText, '[b]' + RichEdit1.SelText + '[/b]', RichEdit1.SelText, [RfReplaceAll]); end; end; end; |
Re: Fehler beim allowup
Wodurch sollte sich denn der GroupIndex ändern?
|
Re: Fehler beim allowup
Wenn ich den Text markiere und den Button wieder "löse", springe ich dann nicht auf Index 0?
Das Zauberwort heisst wohl down! |
Re: Fehler beim allowup
Der Fehler liegt beim StringReplace!
|
Re: Fehler beim allowup
Mit Kanone auf Spatz geschossen - aber getroffen:
Delphi-Quellcode:
function findtextall(re: TRichEdit; sText: string; options:TSearchTypes): TIntegerdynarray;
var istart, ifound, ilength: integer; begin setlength(result, 0); istart := 0; ilength := length(re.Lines.Text); while istart < (ilength - length(stext)) do begin ifound := re.FindText(sText, istart, ilength - istart, options); if ifound = - 1 then exit; Setlength(Result, succ(length(result))); result[high(result)] := ifound; istart := ifound + length(stext); end; end; procedure TForm1.SpeedButton1Click(Sender: TObject); var x: integer; s: string; ida: TIntegerDynArray; begin If SpeedButton1.Down = true then RichEdit1.SelText := '[b]' + RichEdit1.SelText + '[/b]'; If Speedbutton1.Down = false then begin RichEdit1.SelText := StringReplace(RichEdit1.SelText,'[b]', '', [RfReplaceAll]); s := '[/b]'; ida := findtextall(RichEdit1, s, []); for x := low(ida) to high(ida) do with RichEdit1 do begin selstart := ida[x]; sellength := length(s); seltext := ''; end; RichEdit1.SetFocus; end; end; |
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:00 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz