Page 1 of 1

Can't focus a disabled window

Posted: Wed Mar 23, 2011 8:01 pm
by charles.lambert
Hi,

I'm creating a form with ScaleRichView and when I save the content of my ScaleRichViewEdit, I want to protect everything in it. I make every paragraphs protected but, for all the controls I added in it the only way to "protect" them is to disable them.

The problem is, when my controls are disabled and I click on them, I get the error: 'Cannot focus a disabled or invisible window'.

I'd like to know how to prevent this as I can't set the controls property CanFocus to False at runtime. Maybe you have a better solution than to disable every controls.

Thanks,

- Charles

Posted: Thu Mar 24, 2011 7:36 am
by Sergey Tkachenko
Can you create a simple project reproducing this problem?

Posted: Thu Mar 24, 2011 1:16 pm
by charles.lambert
Hi,

this is a simple example that recreates the problem.

You just have to click on the button Add Checkbox, then Protect All.

The control will then be disabled but, if you try to click on it you'll get the error: 'Cannot focus a disabled or invisible window'.

Code: Select all


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, SclRView, RichView, SRVControl, SRVCheckBox, StdCtrls, RVFuncs, SclRVRuler,
  RVStyle;

type
  TForm1 = class(TForm)
    SRichViewEdit1: TSRichViewEdit;
    Button1: TButton;
    RVStyle1: TRVStyle;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
     c : TSRVCheckBox;
begin
  c := TSRVCheckBox.Create(nil);
  c.Parent := SRichViewEdit1.RichViewEdit;
  c.Name := 'SRVCheckBox';
  c.Caption := 'SRVCheckBox';
  c.Color:=clWhite;
  SRichViewEdit1.RichViewEdit.InsertControl('teste', c, rvvaMiddle);
end;

procedure TForm1.Button2Click(Sender: TObject);
var
   iNbItem, INbControl: Integer;
begin
   for iNbItem := 0 to RVStyle1.TextStyles.Count - 1 do
   begin
      SRichViewEdit1.RichViewEdit.Style.TextStyles.Items[iNbItem].Protection :=  [rvprStyleProtect, rvprStyleSplitProtect, rvprModifyProtect,
         rvprDeleteProtect, rvprConcateProtect, rvprRVFInsertProtect, rvprDoNotAutoSwitch, rvprParaStartProtect,
         rvprSticking, rvprSticking2, rvprSticking3, rvprStickToTop, rvprStickToBottom];
   end;

   for iNbControl := 0 to SRichViewEdit1.RichViewEdit.ControlCount - 1 do
   begin
      SRichViewEdit1.RichViewEdit.Controls[iNbControl].Enabled := False;
   end;
end;

end.

Posted: Thu Mar 24, 2011 5:44 pm
by Sergey Tkachenko
Confirmed. It will be fixed in the next update for registered users.

Posted: Thu Mar 24, 2011 6:01 pm
by charles.lambert
Allright! Thanks.