unit ayudaMod;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, StdCtrls, ComCtrls, Buttons, Menus;

type
  TFormaAyudaLinea = class(TForm)
    Panel3: TPanel;
    Bevel18: TBevel;
    Bevel19: TBevel;
    Bevel20: TBevel;
    Label8: TLabel;
    Panel4: TPanel;
    Shape1: TShape;
    Texto: TRichEdit;
    Panel1: TPanel;
    SpeedButton1: TSpeedButton;
    BotonAbrir: TBitBtn;
    BotonImprimir: TButton;
    BotonSalir: TButton;
    SpeedButton2: TSpeedButton;
    BotonBusca: TBitBtn;
    Label1: TLabel;
    procedure Panel4Click(Sender: TObject);
    procedure Panel3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure BotonBuscaClick(Sender: TObject);
    procedure BotonAbrirClick(Sender: TObject);
    procedure BotonImprimirClick(Sender: TObject);
    procedure BotonSalirClick(Sender: TObject);
    procedure SpeedButton1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure SpeedButton2MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure TextoKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure FormCreate(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Label1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FormaAyudaLinea: TFormaAyudaLinea;
  posicion:longInt;

procedure PoneAyuda(archivo:String;indice:integer);
implementation

uses buscar;


{$R *.DFM}

function buscapalabra(posi:longInt;palabra:string):LongInt;

begin
with FormaAyudaLinea do
begin

with Texto do
  begin


{  FindText(palabra,posi,length(palabra),WholeWord, stMatchCase):

(stWholeWord, stMatchCase)
 }
  if posi= 0 then
  SelStart := 0
  else
  SelStart := posi;
    posi := Pos(palabra, Text) - 1;

    if (posi <> 0) then
    begin
      SetFocus;
      SelStart := posi;
      SelLength := Length(palabra);
    end;
  end;

  buscapalabra:=posi;
end;
end;

procedure botonesvisibles(uno,dos,tres:boolean);
begin
with FormaAyudaLinea do
begin
if uno then BotonAbrir.Visible:=True else BotonAbrir.Visible:=False;
if dos then BotonImprimir.Visible:=True else BotonImprimir.Visible:=False;
if tres then BotonSalir.Visible:=True else BotonSalir.Visible:=False;
end;
end;

procedure PoneAyuda(archivo:String;indice:integer);
begin
FormaAyudaLinea:=TFormaAyudaLinea.Create(Application);
with FormaAyudaLinea do
begin

if FileExists(archivo) then
begin
Texto.Lines.LoadFromFile(archivo);

end;
ShowModal;
end;

FormaAyudaLinea.Free;
end;

procedure TFormaAyudaLinea.Panel4Click(Sender: TObject);
begin
Close;
end;

procedure TFormaAyudaLinea.Panel3MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(FormaAyudaLinea.Handle, WM_SYSCOMMAND, $F012, 0);
end;




procedure TFormaAyudaLinea.SpeedButton1Click(Sender: TObject);
begin
botonesvisibles(True,True,True);
end;

procedure TFormaAyudaLinea.SpeedButton2Click(Sender: TObject);
begin
botonesvisibles(False,False,False);
BotonBusca.Visible:=True;
end;



procedure TFormaAyudaLinea.BotonBuscaClick(Sender: TObject);
begin
FormaBusqueda:=TFormaBusqueda.Create(Application);
BotonBusca.Visible:=False;
FormaBusqueda.ShowModal;
posicion:=buscapalabra(0,FormaBusqueda.CajaBuscar.Text);
FormaBusqueda.Free;
end;

procedure TFormaAyudaLinea.BotonAbrirClick(Sender: TObject);
begin
botonesvisibles(False,False,False);
end;

procedure TFormaAyudaLinea.BotonImprimirClick(Sender: TObject);
begin
botonesvisibles(False,False,False);
end;

procedure TFormaAyudaLinea.BotonSalirClick(Sender: TObject);
begin
botonesvisibles(False,False,False);
Close;
end;

procedure TFormaAyudaLinea.SpeedButton1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
botonesvisibles(True,True,True);
BotonBusca.Visible:=False;
end;

procedure TFormaAyudaLinea.SpeedButton2MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
begin
botonesvisibles(False,False,False);
BotonBusca.Visible:=True;
end;

procedure TFormaAyudaLinea.TextoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
{ShowMessaGE('GUEY');}
if key=114 then
begin
ShowMessaGE('posicion '+IntToStr(posicion)+' '+FormaBusqueda.Cajabuscar.Text);

posicion:=buscapalabra(posicion+Length(FormaBusqueda.Cajabuscar.Text),FormaBusqueda.Cajabuscar.Text);

end;
end;

procedure TFormaAyudaLinea.FormCreate(Sender: TObject);
begin
posicion:=0;
end;

procedure TFormaAyudaLinea.FormActivate(Sender: TObject);
begin
{Posicion:=0;}
end;

procedure TFormaAyudaLinea.Label1MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
SendMessage(FormaAyudaLinea.Handle, WM_SYSCOMMAND, $F012, 0);
end;

end.
