From - Mon Jan 12 12:06:23 1998
Path: newslist.borland.com!for...@borland.com
From: "Erik B. Berry" <ebe...@sync-link.com.SPAM>
Newsgroups: borland.public.delphi.vcl.components.writing
Subject: Re: TForm descendent
Date: Tue, 04 Nov 1997 09:31:50 -0800
Organization: Synchronics, Inc <http://www.sync-link.com>
Lines: 292
Message-ID: <345F5C...@sync-link.com.SPAM>
References: <01bce8fb$9fbeacc0$030000c0@mickes>
NNTP-Posting-Host: 206.28.90.130
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
X-Mailer: Mozilla 3.01 (Win95; I; 16bit)
Michael Lebert wrote:
> I tried to add a TMyForm to the object repository, but that way I can't
see
> the properties I added to TMyForm in the object inspector during design
> time instead only the properties belonging to TForm show up.
Here is the correct way to do this. You have to create a expert to
register the form as follows:
John Crouch <jcr...@mail.EXPOCARD.com> wrote in article
<64990FEABFBCD011B5CC0020AF3BE3C5F76B@NTSERVER>...
> We have created this very nice form with all sorts of nice components on
> it and nice functionality. We placed it in the Repository and our users
> (other programmers) just add it to their application by using the
> File|New command.
>
> One feature we do not have with this setup is the ability for the user
> to change some of the properties of the form in the object inspector. I
> think we have to make it a component to do this.
>
John,
In Delphi 3.0 (which I hope you are using as this information only
applies to 3.0) there is a new approach which you can use that I will
try
to briefly describe. The idea is to use a custom module to create a new
form class that has new properties etc. This can be done by registering
a
classtype with the IDE by calling RegisterCustomModule (in the expert
API).
With a custom module you can add your own new properties to forms which
will appear in the object inspector. The mechanism to get this to work
is
as follows:
- Create a unit that declares your new form class descending from
TCustomForm
- Create an expert that will generate a new instance of the above class
in
the IDE
- Install the expert in the IDE by including the expert unit below in a
new
package and simply install the package.
Once you have followed these steps you will have a new item on the Forms
page of the File|New dialog which will be your new form class.
I hope all of this isn't too confusing.
Here is the "simple" example of how to get this to work:
The new form class unit:
>>>> Begin unit <<<<<<
unit myForm;
interface
uses Messages, Windows, SysUtils, Classes, Controls, Forms;
type
TMyForm = class(TCustomForm)
private
FNewProp: String;
protected
public
published
property NewProp: String read FNewProp write FNewProp; // ex. of a
new form property
property ActiveControl;
property Align;
property AutoScroll;
property BorderStyle;
property BorderIcons;
property Caption stored True;
property ClientHeight;
property ClientWidth;
property Color;
property DragCursor;
property DragMode;
property Enabled;
property Font;
property Height stored True;
property HorzScrollBar;
property KeyPreview;
property ParentColor;
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PixelsPerInch;
property PopupMenu;
property PrintScale;
property Scaled;
property ShowHint;
property TabStop;
property VertScrollBar;
property Width stored True;
property OnActivate;
property OnClick;
property OnClose;
property OnCloseQuery;
property OnCreate;
property OnDblClick;
property OnDestroy;
property OnDeactivate;
property OnDragDrop;
property OnDragOver;
property OnHide;
property OnHelp;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnPaint;
property OnResize;
property OnShow;
end;
implementation
end.
>>>> end unit <<<<
Here is the expert necessary to create instances of this class from the
IDE:
>>>> begin expert <<<<
unit newmod;
interface
procedure Register;
implementation
uses Windows, SysUtils, Classes, Controls, Forms, ExptIntf, ToolIntf,
VirtIntf,
IStreams, DsgnIntf, MyForm;
type
TMyFormExpert = class(TIExpert)
function GetName: string; override;
function GetComment: string; override;
function GetGlyph: HICON; override;
function GetStyle: TExpertStyle; override;
function GetState: TExpertState; override;
function GetIDString: string; override;
function GetAuthor: string; override;
function GetPage: string; override;
function GetMenuText: string; override;
procedure Execute; override;
end;
{ TMyFormExpert }
function TMyFormExpert.GetName: string;
begin
Result := 'My Form';
end;
function TMyFormExpert.GetComment: string;
begin
Result := 'Custom form';
end;
function TMyFormExpert.GetGlyph: HICON;
begin
Result := LoadIcon(HInstance, '');
end;
function TMyFormExpert.GetStyle: TExpertStyle;
begin
Result := esForm;
end;
function TMyFormExpert.GetState: TExpertState;
begin
Result := [esEnabled];
end;
function TMyFormExpert.GetIDString: string;
begin
Result := 'MyForm.Expert';
end;
function TMyFormExpert.GetAuthor: string;
begin
Result := 'Borland';
end;
function TMyFormExpert.GetPage: string;
begin
Result := 'Forms';
end;
function TMyFormExpert.GetMenuText: string;
begin
Result := '';
end;
const
FormUnitSource =
'unit %0:s;'#13#10 +
#13#10 +
'interface'#13#10 +
#13#10 +
'uses Windows, SysUtils, Messages, Classes, Graphics,
Controls,'#13#10 +
' StdCtrls, ExtCtrls, MyForm;'#13#10 +
#13#10 +
'type'#13#10 +
' T%1:s = class(TMyForm)'#13#10 +
' private'#13#10 +
' { Private declarations }'#13#10 +
' public'#13#10 +
' { Public declarations }'#13#10 +
' end;'#13#10 +
#13#10 +
'var'#13#10 +
' %1:s: T%1:s;'#13#10 +
#13#10 +
'implementation'#13#10 +
#13#10 +
'{$R *.DFM}'#13#10 +
#13#10 +
'end.'#13#10;
FormDfmSource = 'object %s: T%0:s end';
procedure TMyFormExpert.Execute;
var
UnitIdent, Filename: string;
FormName: string;
CodeStream: TIStream;
DFMStream: TIStream;
DFMString, DFMVCLStream: TStream;
begin
if not ToolServices.GetNewModuleName(UnitIdent, FileName) then Exit;
FormName := 'MyForm' + Copy(UnitIdent, 5, 255);
CodeStream :=
TIStreamAdapter.Create(TStringStream.Create(Format(FormUnitSource,
[UnitIdent, FormName])), True);
try
CodeStream.AddRef;
DFMString := TStringStream.Create(Format(FormDfmSource,
[FormName]));
try
DFMVCLStream := TMemoryStream.Create;
try
ObjectTextToResource(DFMString, DFMVCLStream);
DFMVCLStream.Position := 0;
except
DFMVCLStream.Free;
end;
DFMStream := TIStreamAdapter.Create(DFMVCLStream, True);
try
DFMStream.AddRef;
ToolServices.CreateModuleEx(FileName, FormName, 'TMyForm', '',
CodeStream, DFMStream, [cmAddToProject, cmShowSource,
cmShowForm,
cmUnNamed, cmMarkModified]);
finally
DFMStream.Free;
end;
finally
DFMString.Free;
end;
finally
CodeStream.Free;
end;
end;
procedure Register;
begin
RegisterCustomModule(TMyForm, TCustomModule);
RegisterLibraryExpert(TMyFormExpert.Create);
end;
end.
>>>> end expert <<<<
To get the expert installed you have to add the unit to a package and
install the package. Once this is complete your new form class will be
available from the File|New dialog.
--
-Steve
Delphi QA
(To email me remove "-nojunkmail-" from my address)
Erik
Dov Landau wrote in message <01bd2651$5698c1a0$LocalHost@default>...
Cheerios,
Chris.