loucks
asked on
How to create a form that is in a runtime package.
Here is my problem. I have an application that many people use. A few need more features, but I don't want to bloat the app with the extra code that will be used RARELY...
I investigated packages, and that seemed to do it. I created a package with three forms, and I can call the main form and it (mostly) works.
I need to know how to be able to create the other two forms from the first form in the package.
Basically, I want to do something like:
with TfAppt.Create(Self) do
from within my main package. Each form has an initialization and finalization portion the registers its class, but I am on unfamiliar territory here and would appreciate some help.
I investigated packages, and that seemed to do it. I created a package with three forms, and I can call the main form and it (mostly) works.
I need to know how to be able to create the other two forms from the first form in the package.
Basically, I want to do something like:
with TfAppt.Create(Self) do
from within my main package. Each form has an initialization and finalization portion the registers its class, but I am on unfamiliar territory here and would appreciate some help.
ASKER
Yes, I load the package dynamically... Here is the code I stole from community.borland.com:
var
PackageModule: HModule;
AClass: TPersistentClass;
begin
PackageModule := LoadPackage('AcnAppts.bpl' );
if PackageModule <> 0 then
begin
AClass := GetClass('TfACNAppts');
if AClass <> nil then
with TComponentClass(AClass).Cr eate(Appli cation)
as TCustomForm do
begin
ShowModal;
Free;
end;
UnloadPackage(PackageModul e);
end;
And now from within the showmodal of TfACNAppts, I want to create another form contained in the package and show it.
I don't get any error messages, it just doesn't work and I don't know how to debug packages yet.
var
PackageModule: HModule;
AClass: TPersistentClass;
begin
PackageModule := LoadPackage('AcnAppts.bpl'
if PackageModule <> 0 then
begin
AClass := GetClass('TfACNAppts');
if AClass <> nil then
with TComponentClass(AClass).Cr
as TCustomForm do
begin
ShowModal;
Free;
end;
UnloadPackage(PackageModul
end;
And now from within the showmodal of TfACNAppts, I want to create another form contained in the package and show it.
I don't get any error messages, it just doesn't work and I don't know how to debug packages yet.
I assume that on the first form you have some user interface element which should execute code to show the second form; e.g. a button.
What do you mean by "it just doesn't work"? The second form is not shown? Is the second form contained in the same runtime package? Can you post the code that attempts to show the second form?
You can debug even dynamically loaded runtime packages, although sometimes the IDE gets messed up.
I've done this some time before and I've found these notes I've written down at that time:
Debugging runtime packages
Runtime packages designed to be loaded dynamically at runtime can be debugged in the following way, supposed you have the "main" executable project in the project group with the runtime package projects:
Make sure the main executable project is compiled so that next time you select "Run" it won't start recompiling.
Activate the runtime package project you wish to debug and recompile it. Set your breakpoints.
Activate the main executable project again and run it. You will see that the breakpoints in the runtime package project get disabled but they will be re-enabled when the main executable actually loads the runtime package.
HTH
TOndrej
What do you mean by "it just doesn't work"? The second form is not shown? Is the second form contained in the same runtime package? Can you post the code that attempts to show the second form?
You can debug even dynamically loaded runtime packages, although sometimes the IDE gets messed up.
I've done this some time before and I've found these notes I've written down at that time:
Debugging runtime packages
Runtime packages designed to be loaded dynamically at runtime can be debugged in the following way, supposed you have the "main" executable project in the project group with the runtime package projects:
Make sure the main executable project is compiled so that next time you select "Run" it won't start recompiling.
Activate the runtime package project you wish to debug and recompile it. Set your breakpoints.
Activate the main executable project again and run it. You will see that the breakpoints in the runtime package project get disabled but they will be re-enabled when the main executable actually loads the runtime package.
HTH
TOndrej
ASKER
Yes, it is a button on the main form.
The code is
with TfAppt.Create(Self) do
begin
try
end
The code is
with TfAppt.Create(Self) do
begin
try
end
ASKER
Hmmm. hit the wrong button let's try that again
The code is
with TfAppt.Create(Self) do
begin
try
ShowModal;
finally
Free;
end;
end;
It doesn't raise any errors, but it also doesn't show the form.
The code is
with TfAppt.Create(Self) do
begin
try
ShowModal;
finally
Free;
end;
end;
It doesn't raise any errors, but it also doesn't show the form.
A button on the main form? But the main form is not within a package, is it?
ShowModal (by definition) will block your application until the modal form is closed.
Sorry I can't help you unless you take care to describe your problem in detail or post the relevant code.
Just one additional note: if you do
with ...Create() do
try
ShowModal;
finally
Free;
end;
then you don't need to pass any Owner. Passing nil will do fine since you're freeing the form yourself and don't need an Owner to do that automatically for you.
ShowModal (by definition) will block your application until the modal form is closed.
Sorry I can't help you unless you take care to describe your problem in detail or post the relevant code.
Just one additional note: if you do
with ...Create() do
try
ShowModal;
finally
Free;
end;
then you don't need to pass any Owner. Passing nil will do fine since you're freeing the form yourself and don't need an Owner to do that automatically for you.
ASKER
I'm sorry, I wasn't clear because I was in a hurry. I meant the main form of the package. So the package has 3 forms
the "main" one of the package is: TfACNAppts
and that is created and shown fine. But in the button event of the first package form is where I want to create the second package form and that is the part that doesn't seem to work. I haven't debugged it yet though. I will also try passing in nil as the owner.
If you need more points just let me know.
--Jason
the "main" one of the package is: TfACNAppts
and that is created and shown fine. But in the button event of the first package form is where I want to create the second package form and that is the part that doesn't seem to work. I haven't debugged it yet though. I will also try passing in nil as the owner.
If you need more points just let me know.
--Jason
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hmmm... No, I didn't call the GetClass for the other form... I will put that in, probably sometime tomorrow morning and let you know how it goes.
--Jason
--Jason
ASKER
The problem was I didn't call the getclass of the other form.
Hi,
retyping this example from Borland.com, I always fail with GetClass for th main form of the package.
The MainForm of the package is registered in then initialization part. But GetClass always returns nil. Any ideas?
retyping this example from Borland.com, I always fail with GetClass for th main form of the package.
The MainForm of the package is registered in then initialization part. But GetClass always returns nil. Any ideas?
ASKER
Other than triple-checking to make sure that you didn't misspell anything, I don't have any ideas for you...
Ok,
I was too fast and forgot to compile with runtime-packages. Problem is therfore solved now.
Thanks
I was too fast and forgot to compile with runtime-packages. Problem is therfore solved now.
Thanks
Your description is unclear. I don't understand what the question you're asking is.