Здравствуйте участники клуба
Вот так я создаю динамически компоненты TLabeledEdit.
Вопрос: Как можно сделать подсветку текста в документе Word когда LabeledEdit находится в фокусе.Вернее как узнать какой компонент LabeledEdit находится в фокусе
Если можно то с кодом.
Заранее всем спасибо
Код:
unit AutoDok;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ComObj;
type
TForm1 = class(TForm)
OpenBut: TButton;
OpenDialog1: TOpenDialog;
PrintBut: TButton;
Panel1: TPanel;
procedure OpenButClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure PrintButClick(Sender: TObject);
private
procedure Find;
{ Private declarations }
public
i,t,t1,ch,ch1,bt,bt1,n,k : integer;
W : Variant;
ReadList: TStringList;
EditList: TStringList;
WriteList : TStringList;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
i := 0;
t := 25;
ch := 58;
bt := 16;
t1 := 25;
ch1 := 58;
bt1 := 16;
Form1.ClientHeight := 58;
Panel1.Height := 58;
PrintBut.Enabled := False;
ReadList := TStringList.Create;
EditList := TStringList.Create;
WriteList := TStringList.Create;
end;
procedure TForm1.Find;
var
x: TLabeledEdit;
begin
if W.Selection.Find.Execute('$##') then
begin
n := W.Selection.Start;
end;
if W.Selection.Find.Execute('^?##') then
begin
k := W.Selection.End;
i := i + 1;
if odd(i) then
begin
ReadList.Add(W.ActiveDocument.Range(n, k).Text);
x:=TLabeledEdit.create(self);
x.parent:=Panel1;
x.name := 'edit' + IntToStr(i);
EditList.Add('edit' + IntToStr(i));
x.EditLabel.Caption:= W.ActiveDocument.Range(n+3, k-2).Text;
x.EditLabel.Font.Size := 11;
x.Text := '';
x.left:=10;
x.top:=t;
x.Width:=250;
t := t + 50;
bt := bt + 50;
OpenBut.Top := bt;
PrintBut.Top := bt;
Form1.ClientHeight := ch + t - 30;
Panel1.Height := ch + t - 30;
end
else
begin
ReadList.Add(W.ActiveDocument.Range(n, k).Text);
x := TLabeledEdit.create(self);
x.parent :=Panel1;
x.name := 'edit' + IntToStr(i);
EditList.Add('edit' + IntToStr(i));
x.EditLabel.Caption := W.ActiveDocument.Range(n+3, k-2).Text;
x.EditLabel.Font.Size := 11;
x.Text := '';
x.left:=280;
x.top := t1;
x.Width:=250;
t1 := t1 + 50;
bt1 := bt1 + 50;
OpenBut.Top := bt1;
PrintBut.Top := bt1;
Form1.ClientHeight := ch1 + t1 - 30;
Panel1.Height := ch1 + t1 - 30;
end;
W.Selection.Start := k;
end;
end;
procedure TForm1.OpenButClick(Sender: TObject);
var
q:integer;
a:String;
begin
if not OpenDialog1.Execute then
exit
else
begin
Form1.Visible := false;
W := CreateOleObject('Word.Application');
W.Visible := False;
W.Documents.Add(OpenDialog1.FileName);
a := W.Application.ActiveWindow.Caption;
for q:=1 to W.ActiveDocument.Words.count do
begin
Find;
end;
OpenBut.Enabled := False;
PrintBut.Enabled := True;
Form1.Constraints.MaxWidth := 567;
Form1.Constraints.MinWidth := 567;
if Panel1.Height <= 560 then
begin
Form1.Constraints.MaxHeight := Panel1.Height+34;
Form1.Constraints.MinHeight := Panel1.Height+34;
Form1.Constraints.MaxWidth := 550;
Form1.Constraints.MinWidth := 550;
end
else
begin
Form1.Constraints.MaxHeight := 600;
Form1.Constraints.MinHeight := 600;
end;
SetWindowPos(Form1.Handle,HWND_TOP,round((screen.Width/2)-(form1.Width/2)),0,0,0,SWP_nosize);
Form1.Visible := True;
SetWindowPos(FindWindow(nil,PChar(a + ' - Microsoft Word')),HWND_TOP,0,(Form1.Height),0,0,SWP_nosize);
W.Visible := True;
end;
end;