Solved

How to create a form that is in a runtime package.

Posted on 2002-07-03
13
171 Views
Last Modified: 2010-04-04
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.
0
Comment
Question by:loucks
  • 7
  • 4
  • 2
13 Comments
 
LVL 8

Expert Comment

by:TOndrej
ID: 7127046
Do you load the package dynamically with LoadPackage?
Your description is unclear. I don't understand what the question you're asking is.
0
 

Author Comment

by:loucks
ID: 7127118
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).Create(Application)
        as TCustomForm do
      begin
        ShowModal;
        Free;
      end;

    UnloadPackage(PackageModule);
  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.
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 7127147
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
0
 

Author Comment

by:loucks
ID: 7127231
Yes, it is a button on the main form.

The code is
with TfAppt.Create(Self) do
  begin
  try

  end


0
 

Author Comment

by:loucks
ID: 7127234
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.
0
 
LVL 8

Expert Comment

by:TOndrej
ID: 7127286
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.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

Author Comment

by:loucks
ID: 7127402
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
0
 
LVL 8

Accepted Solution

by:
TOndrej earned 200 total points
ID: 7127423
Do you also call GetClass for the other form?
Is the other form's class registered?
Is the button's OnClick handler assigned correctly (loaded from the package's .dfm stream)?
You can check it by writing a very simple

procedure TfACNAppts.MyButtonClick(Sender: TObject);
begin
  ShowMessage('click...');
  ... your code to show the other form here
end;

Or maybe it's a totally different problem you can find out by debugging. Sorry I have no more ideas at this point.
0
 

Author Comment

by:loucks
ID: 7127445
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
0
 

Author Comment

by:loucks
ID: 7131823
The problem was I didn't call the getclass of the other form.  
0
 

Expert Comment

by:galaxius
ID: 8165782
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?
0
 

Author Comment

by:loucks
ID: 8166298
Other than triple-checking to make sure that you didn't misspell anything, I don't have any ideas for you...
0
 

Expert Comment

by:galaxius
ID: 8171767
Ok,
I was too fast and forgot to compile with runtime-packages. Problem is therfore solved now.

Thanks
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now