Jump to content
Javier Tarí

Need help finding the IDesigner

Recommended Posts

Short: At design time, How can I get the IDesigner interface for a given form?

 

Long:

I have a VCL DBGrid-kind component developed for D5 and working fine all the way up to D10.4.1, except for one thing

At design time, when I clic on a column header, it should select on the Object Inspector the TCollectionItem descendant for that column

In D5, it was as easy as finding the form owning the DBGrid-kind, and then using FDesigner.SelectComponent(TheColumn);

But now the form has IDesigner: IDesignFormHook, so I don't know how to do a SelectComponent

 

Thanks in advance

Share this post


Link to post

I'm not sure I understand correctly what you are trying to do here but the Open Tools API can provide you access to the IDesigner from INTAFormEditor.GetFormDesigner. You can get the INTAFormEditor by querying the IOTAModule interface for the form.

  • Like 1

Share this post


Link to post
1 hour ago, David Hoyle said:

I'm not sure I understand correctly what you are trying to do here but the Open Tools API can provide you access to the IDesigner from INTAFormEditor.GetFormDesigner. You can get the INTAFormEditor by querying the IOTAModule interface for the form.


Don't thik I understood you.. Do you mean something as this?

((Form as IOTAmodule) as INTAFormEditor).GetFormDesigner

 

Share this post


Link to post

No. What is the context under which you are trying to do what you are attempting.

To do what I've described you need to write an Open Tools API BPL or DLL and add it to the IDE. This will then give you access to the designer once you have an IOTAModule reference to your form.

Share this post


Link to post

Thank you; finally understood it

Ofcourse, it is a BPL registering the components and some property editors, all of them working

 

Following your advice, I've solved it this way:

var
  ModuleServices: IOTAModuleServices;
  FFormEditor: IOTAFormEditor;
  NTAFormEditor: INTAFormEditor;
  FormModule: IOTAModule;
  aFormDesigner: IDesigner;
begin
  aFormDesigner:=nil;
  ModuleServices := BorlandIDEServices as IOTAModuleServices;
  if Assigned(ModuleServices) then begin
    FormModule := ModuleServices.FindFormModule(Self.Owner.Name);
    if assigned(FormModule) then begin
      FFormEditor := FormModule.GetModuleFileEditor(FormModule.GetModuleFileCount - 1) as IOTAFormEditor;
      if Supports(FFormEditor, INTAFormEditor, NTAFormEditor) then
        aFormDesigner:=NTAFormEditor.GetFormDesigner;
    end;
  end;
  //Now you just select the column, i.e.:
  if Assigned(aFormDesigner) then
    aFormDesigner.SelectComponent(Column(ACol))
end;

Next one also works, but I'm not sure if it should work, so will keep the first one

var
  aFormDesigner: IDesigner;
  aForm: TCustomForm;
begin
  AForm:=GetParentForm(Self);
  If not Supports(aForm.Designer,IDesigner,aFormDesigner) Then
    aFormDesigner:=nil;
  if Assigned(aFormDesigner) then begin
    aFormDesigner.SelectComponent(Column(ACol));
end;

 

Share this post


Link to post

It can be done much simpler:

 

1) Use FindRootDesigner function defined in Classes.pas.

2) Just cast the return value to IDesigner.

 

dsnr := FindRootDesigner(AComponent) as IDesigner;

 

  • Thanks 1

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×