I am making my own kind of "Forms" which are derived from TComponent.
The component hierarchy is ready now, I can create forms runtime from
manually written DFM files. Now I start working on next task from the
list - making a designer for that form. After few days of reading
documentation and ToolsAPI.pas, looking examples on the net, googling,
post in forums.embarcadero.com... etc. , I still dont have good
picture how to make my own form designer. I need to develop something
like TDataModule designer, which is also TComponent descendant as my
forms.
I found few comments in DesignIntf.pas about "Custom Module Types". So
for now I am trying to make some implementations of ICustomDesignForm
and class inherited from TCustomModule. I use CreateDesignerForm
method of ICustomDesignForm to create my own implementation of
IHostForm. But there is input parameter of CreateDesignerForm method
of time IDesigner, and till now I cant wind where I can create my own
instance of my own IDesigner implementation. I cant use the already
created IDesigner from Delphi IDE. I think I need my own IDesigner
implementation - but where I can tell to Delphi IDE to create it?
Any ideas? any links? ... while googling I found few articles, but all
of these are very outdated and they are talking about Delphi 3-5, but
nothing more recent about "Custom Module Types" and designers for
these custom modules.
Thanks in advance,
The book says the key step in creating your own form designer in Delphi is
the RegisterCustomModule registration procedure:
procedure RegisterCustomModule( ComponentBaseClass : TComponentClass;
CustomModuleClass : TCustomModuleClass );
It also mentions RegisterLibraryExpert( .. )
Why you want to create your own form designer ;) ?
Bye,
Skybuck =D
Yes, I come to conclusion reading comments in Delphi source code that
I have to make my own TCustomModule:
TMyFormCustomModule = class(TCustomModule, ICustomDesignForm80)
protected
procedure CreateDesignerForm(const Designer: IDesigner; Root:
TComponent;
out DesignForm: IHostForm; out ComponentContainer: TWinControl);
end;
In that method CreateDesignerForm I create my own IHostForm where I
suppose I have to place my design time view of my form.
But as you can see - the first parameter of that method is already
created instance of IDesigner implementation. Looking at methods in
IDesgner I think that I have to implement it by myself and Delphi IDE
to use my implementation for my forms, but till now - cant find where
I can tell to Delphi IDE that is have to use my own implementation.
I found also that event type in DesignIntf.pas:
TGetDesignerEvent = procedure(Sender: TObject; out ADesigner:
IDesigner) of object;
but looks like no one on Earth is using it or know why that one
exists :) ... or at least Google dont know anything about it.
> procedure RegisterCustomModule( ComponentBaseClass : TComponentClass;
> CustomModuleClass : TCustomModuleClass );
>
> It also mentions RegisterLibraryExpert( .. )
>
> Why you want to create your own form designer ;) ?
>
Because my forms are descendant from TComponent (as TDataModule for
example), not from TCustomForm or TWinControl, not even from TControl
- so I am pretty sure standard Delphi form designer cant handle my
forms - I actually try that and the IDE open them using TDataModule
designer, but that designer isnt working for me because mine forms are
true visual forms, not just component containers (as TDataModule) and
I want to be able to WYSIWYG editing of my forms.
Cheers,
AFAIK there is only one Designer. And You can access designer only by
its interface.
And, as You can see IDesigner works only with TCustomForm.
> I found also that event type in DesignIntf.pas:
>
> TGetDesignerEvent = procedure(Sender: TObject; out ADesigner:
> IDesigner) of object;
>
> but looks like no one on Earth is using it or know why that one
> exists :) ... or at least Google dont know anything about it.
>
>> procedure RegisterCustomModule( ComponentBaseClass : TComponentClass;
>> CustomModuleClass : TCustomModuleClass );
>>
>> It also mentions RegisterLibraryExpert( .. )
>>
>> Why you want to create your own form designer ;) ?
>>
>
> Because my forms are descendant from TComponent (as TDataModule for
> example), not from TCustomForm or TWinControl, not even from TControl
> - so I am pretty sure standard Delphi form designer cant handle my
> forms - I actually try that and the IDE open them using TDataModule
> designer, but that designer isnt working for me because mine forms are
> true visual forms, not just component containers (as TDataModule) and
> I want to be able to WYSIWYG editing of my forms.
You need to have some TCustomForm "container" for Your very custom forms.
For designing, put Your pseudo-TForm on this container.
Do not use TCustomForm.Create(), but TCustomForm.CreateNew() in this
container, to skip reading DFM, then You manually create Your
pseudo-TForm and read its DFM.
--
Arivald
Yes, I have such TCustomForm container which implement IHostForm as
required by CreateDesignerForm method of ICustomDesignForm. And I am
creating my custom type form inside that container. And your idea is
that I have to use methods of created from Delphi IDE IDesigner
instance. For example when user select a child control inside my form
I have to call SelectComponent method of given IDesigner so that
control properties to be displayed in Objects Inspector.
Interesting... that will be first approach to try tomorrow. Thanks for
that idea.
(TCustomModule) seems to be missing so code doesn't compile...
There is a ICustomModule... I am not sure what some things changed
to I instead of T.
The book mentioned something about a compounded design editor...
it would use a Tpanel and display some form but it wouldn't be saved etc.
My Delphi environment is currently malfunctioning... it can't open units at
file cursor
kinda weird... so I am gonna try a reboot to see if that helps...
For now here is some code from the book's cd:
uses
Classes, Forms, Windows, Dialogs, ExptIntf, ToolIntf,
FileCtrl, SysUtils, EditIntf, DesignIntf;
type
TPanelEditExpert = class (TIExpert)
public
function GetStyle: TExpertStyle; override;
function GetName: string; override;
function GetAuthor: string; override;
function GetComment: string; override;
function GetPage: string; override;
function GetGlyph: HICON; override;
function GetState: TExpertState; override;
function GetIDString: string; override;
function GetMenuText: string; override;
procedure Execute; override;
end;
// custom module for the panel
type
TPanelModule = class (TCustomModule)
public
procedure ExecuteVerb(Index: Integer); override;
function GetVerb(Index: Integer): string; override;
function GetVerbCount: Integer; override;
procedure ValidateComponent(Component: TComponent); override;
end;
procedure TPanelEditExpert.Execute;
var
ModuleName, FormName, FileName: string;
ModIntf: TIModuleInterface;
begin
ToolServices.GetNewModuleAndClassName (
'Panel', ModuleName, FormName, FileName);
ModIntf := ToolServices.CreateModuleEx (FileName, FormName,
'Panel', '', nil, nil,
[cmNewForm, cmAddToProject, cmUnNamed]);
ModIntf.ShowSource;
ModIntf.ShowForm;
ModIntf.Release;
end;
procedure Register;
begin
RegisterCustomModule (TPanel, TPanelModule);
RegisterLibraryExpert(TPanelEditExpert.Create);
end;
Bye,
Skybuck.
Does anyone knows some good explanation of IDesigner methods? It even
doesnt have comments in DesignIntf.pas
Thanks,
The full link to IDesigner is:
http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/!!MEMBEROVERVIEW_DesignIntf_IDesigner.html
Strange that this is not included in Help installed with Delphi IDE.