[Lazarus] No halp entry for FindDialog ...

2014-11-07 Thread Bob B.
and my Delphi 3 code for OnFind does not work in Lazarus, at least not in Laz 
1.2.4 for Win32.  Could some kind person please offer an example that works?

Also, I wonder why the OnFind event has to be coded by the programmer in the 
first place, since all that changes is the component with the text so why 
couldn't that just be a property of the dialog component?  It would beak code 
if done in FindDialog, but it could be in a new dialog component (perhaps named 
SearchDialog) and before calling execute specify the text source - for example:
  with SearchDialog1 do begin textsource:=myMemo; execute; end;

Hey, let's not stop there.  Perhaps SearchDialog could be non-modal, such as 
FindDialog was in Delphi, so you don't have to exit to see the found text 
highlighted.  Anyone who does not want that change can just continue using 
FindDialog in Laz.

Thank you very much for your time.


Bob B.
--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] No halp entry for FindDialog ...

2014-11-07 Thread Howard Page-Clark

On 08/11/2014 00:35, Bob B. wrote:

and my Delphi 3 code for OnFind does not work in Lazarus, at least not
in Laz 1.2.4 for Win32.  Could some kind person please offer an example
that works?


Drop a TFindDialog, TMemo, TPopupMenu on the main form of a new default 
Lazarus project, and code unit1.pas thus:


unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Forms, Controls, Dialogs, StdCtrls, Menus;

type

  TForm1 = class(TForm)
FindDialog1: TFindDialog;
MTextToSearch: TMemo;
PopupMenu1: TPopupMenu;
procedure FormCreate(Sender: TObject);
  private
procedure DoSearch(Sender: TObject);
procedure DoSearchFromPopup(Sender: TObject);
function Located(const aText: string): boolean;
  end;

var
  Form1: TForm1;

implementation

{$R *.lfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  mi: TMenuItem;
begin
  mi:=TMenuItem.Create(PopupMenu1);
  mi.Caption:='Search unit1.pas';
  mi.OnClick:=@DoSearchFromPopup;
  PopupMenu1.Items.Add(mi);
  MTextToSearch.PopupMenu:=PopupMenu1;

  FindDialog1.Title:='Find text in unit1.pas';
  FindDialog1.OnFind:=@DoSearch;

  MTextToSearch.Align:=alClient;
  MTextToSearch.ScrollBars:=ssAutoBoth;
  MTextToSearch.Lines.LoadFromFile('unit1.pas');
  FindDialog1.Execute;
end;

procedure TForm1.DoSearch(Sender: TObject);
begin
  FindDialog1.CloseDialog;
  if not Located(FindDialog1.FindText) then
ShowMessageFmt('Text %s not found in 
unit1.pas',[FindDialog1.FindText]);

end;

procedure TForm1.DoSearchFromPopup(Sender: TObject);
begin
  FindDialog1.Execute;
end;

function TForm1.Located(const aText: string): boolean;
var
  p: integer;
begin
  p:=Pos(aText, MTextToSearch.Text);
  Result:=p0;
  if Result then begin
MTextToSearch.SelStart:=p-1;
MTextToSearch.SelLength:=Length(aText);
  end;
end;

end.



--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus