From my EPlus editor (from which LazEdit is derived):
procedure TEPlusForm.DoReplace(Sender: TObject);
var
Ed: TEditor;
Dlg: TReplaceDialog;
begin
Ed := NoteBook.CurrentEditor;
if Assigned(Ed) then
begin
Dlg := (Sender as TReplaceDialog);
FindOptions := [];
if not (frDown in Dlg.Options) then FindOptions := FindOptions + [ssoBackWards];
if frMatchCase in Dlg.Options then FindOptions := FindOptions + [ssoMatchCase];
if frWholeWord in Dlg.Options then FindOptions := FindOptions + [ssoWholeWord];
if frReplace in Dlg.Options then ReplaceOptions := ReplaceOptions + [ssoReplace];
if frReplaceAll in Dlg.Options then ReplaceOptions := ReplaceOptions + [ssoReplaceAll];
if frFindNext in Dlg.Options then ReplaceOptions := ReplaceOptions - [ssoReplace,ssoReplaceAll];
if Ed.SelAvail then ReplaceOptions := ReplaceOptions + [ssoSelectedOnly];
FindText := Dlg.FindText;
ReplaceText := Dlg.ReplaceText;
if Ed.SearchReplace(FindText,ReplaceText,ReplaceOptions) = 0 then
ShowError(Format(msgTextNotFound,[FindText]))
else
if (ssoReplace in ReplaceOptions) and not (ssoReplaceAll in ReplaceOptions) then
begin
ReplaceOptions := ReplaceOptions - [ssoReplace];
Ed.SearchReplace(FindText,'',ReplaceOptions); //Search and select next occurence
end;
end;
end;
NoteBook is a TEditorPageControl (derived form TPageControl) and the getter for CurrentEditor looks like this:
function TEditorPageControl.GetCurrentEditor: TEditor;
var
Pg: TTabSheet;
begin
//DebugLn('TEditorPageControl.GetCurrentEditor: PageCount = ',DbgS(PageCount),' ActivePageIndex = ',DbgS(ActivePageIndex));
Result := nil;
//ActivePageIndex = -1 when you remove the last (as in no more pages available) page
//PageCount will still be 1 at this time
if (PageCount > 0) and (ActivePageIndex >= 0) then
begin
Pg := Pages[ActivePageIndex];
Result := EditorAtPage(Pg);
end;
end;
//and
//TEditor is a derived class form TSynEdit.
function TEditorPageControl.EditorAtPage(const APage: TTabSheet): TEditor;
var
cc: Integer;
begin
Result := nil;
if not Assigned(APage) then Exit;
for cc := 0 to APage.ComponentCount - 1 do
begin
if APage.Components[cc] is TEditor then
begin
Result := TEditor(APage.Components[cc]);
Exit;
end;
end;
end;
Bart