VFI
works very well, however for it to work correctly, you need a designtime package
that includes your Form and have it registered with Delphi.
eg You always need some code like the following in a
package/expert.
TMyFormExpert = class(TIExpert)
public
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;
public
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;
procedure Register;
begin
RegisterCustomModule( TMyForm, TCustomModule);
RegisterLibraryExpert( TMyFormExpert.Create);
end;
begin
RegisterCustomModule( TMyForm, TCustomModule);
RegisterLibraryExpert( TMyFormExpert.Create);
end;
procedure TMyFormExpert.Execute;
var
UnitIdent,
Filename,
FormName : string;
CodeStream : IStream;
DFMStream : IStream;
DFMString,
DFMVCLStream: TStream;
begin
if not ToolServices.GetNewModuleAndClassName( 'MyForm', UnitIdent, FormName, FileName ) then Exit;
var
UnitIdent,
Filename,
FormName : string;
CodeStream : IStream;
DFMStream : IStream;
DFMString,
DFMVCLStream: TStream;
begin
if not ToolServices.GetNewModuleAndClassName( 'MyForm', UnitIdent, FormName, FileName ) then Exit;
CodeStream := TIStreamAdapter.Create(
TStringStream.Create(Format(FormUnitSource, [UnitIdent, FormName])), soOwned
);
DFMString := TStringStream.Create(Format(FormDfmSource, [FormName]));
try
DFMVCLStream := TMemoryStream.Create;
try
ObjectTextToResource( DFMString, DFMVCLStream);
DFMVCLStream.Position := 0;
except
DFMVCLStream.Free;
Exit;
end;
DFMStream := TIStreamAdapter.Create( DFMVCLStream, soOwned );
DFMString := TStringStream.Create(Format(FormDfmSource, [FormName]));
try
DFMVCLStream := TMemoryStream.Create;
try
ObjectTextToResource( DFMString, DFMVCLStream);
DFMVCLStream.Position := 0;
except
DFMVCLStream.Free;
Exit;
end;
DFMStream := TIStreamAdapter.Create( DFMVCLStream, soOwned );
ToolServices.CreateModuleEx(FileName, FormName,
'TMyForm', '', CodeStream, DFMStream, [cmAddToProject, cmShowSource, cmShowForm,
cmUnNamed, cmMarkModified]);
finally
DFMString.Free;
end;
end;
finally
DFMString.Free;
end;
end;
Myles
-----Original Message-----G'Day,
From: Donovan J. Edye [mailto:[EMAIL PROTECTED]
Sent: Thursday, 6 March 2003 10:43 a.m.
To: Multiple recipients of list delphi
Subject: [DUG]: [Q] Visual Form Inheritance [VFI]
I have been using visual form inheritance for a project and have a couple of
questions.
1. Why do I have to do a New... and select the base form from the "MyProject" tab?
If I have a form declared as TMyBaseForm and I do a New Form, why can't I just
change the inhertited class in the new unit? ie
TMyNewForm = class(TForm) becomes TMyNewForm = class(TMyBaseForm). If I do this
by hand then "Revert To Inherited" is not available. So what else is Delphi doing
behind the scenes?
2. A TImageList on the base form does not update on the descendant child forms when
new images are added. Why? Are certain controls not VFI supported?
3. Using DevExpress Bars for my toolbar does not reflect on the descendant children.
How are customised toolbars handled with VFI? Do children have to drag their buttons
on?
What other gotchas are there with VFI? Any comments, references etc. appreciated.-- Donovan
----------------------------------------------------------------------
Donovan J. Edye [www.edye.wattle.id.au]
Namadgi Systems [www.namsys.com.au]
Voice: +61 2 6285-3460
Fax: +61 2 6285-3459
TVisualBasic = Class(None);
Heard just before the 'Big Bang': "...Uh Oh...."
----------------------------------------------------------------------
GXExplorer [http://www.gxexplorer.org] Freeware Windows Explorer
replacement. Also includes freeware delphi windows explorer components.
----------------------------------------------------------------------
