?
Solved

Packages

Posted on 2002-06-18
13
Medium Priority
?
401 Views
Last Modified: 2010-04-04
Help please

I'm trying to use runtime packages in my app and I'm stumped on the moment. I got everything to work but the when I try to load a package the second time I get "System error Code 1400 Invalid window handle". What makes even less sence is that it doesn't make a diffirence whether I try to execute the same package twice or a different one after the first in succession I get the same error. If I restrart the main app I can again call a package once.

Please help me with this. I'm using Delphi 6 on NT workstation.

Thanx
 Fick
0
Comment
Question by:jfvd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 1

Expert Comment

by:Kristian
ID: 7088362
when using packages you need to make sure you are not referencing any visual properties, as these properties will not exist and cause you problems.

in your package the code has to be able to run in design time and run time. in design time you wont want to do anything that refers to something that is runtime only.

( usually draw methods or pop ups are most common )

as a simple get out use :

if (csDesigning in ComponentState) then

then you will know whether you are runing the package or the program. and avoid your problems accordingly..

Kristian
0
 

Author Comment

by:jfvd
ID: 7088537
By visual properties do you mean things like the caption of a button or column headers in a grid as well. Because I do set these on the form show event in the package that I'm loading.

Thanx
 Fick
0
 
LVL 1

Expert Comment

by:Kristian
ID: 7088694
you say in the form show event.
are you showing a form in design time?
if you are are you freeing any resources that you create ( packages dont like things being not free'd).

captions are ok.
columns are on a whole ok.

its mainly draw events, mouse events, click events,
any reference to a form that will only exist in runtime not designtime.

the error indicated you are referencing something that dosnt exist.

can you explain the content of your package.

Kristian
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:jfvd
ID: 7088900
Yes my package has a form that I want/need to show.

The content of my package - I've got a form with a button and a label on it. The button "close" the form to return to the calling app.

I instantiate the package with ShowModal and then right after that Free everything.

The code I'm using I got out of "Mastering Delphi 6"
Code that I use:

Button1Click event:
  var
    ItemInq : TForm;
    frmCls : TFormClass;
    AClass : TPersistentClass;
    wndHnd : HModule;
begin
  wndHnd := 0;
  wndHnd := LoadPackage('TestPack.bpl');
  if wndHnd > 0 then
  begin
    AClass := Classes.GetClass('TAboutBox');
    frmCls := TFormClass(AClass);
    if Assigned(frmCls) then
    begin
      ItemInq := frmCls.Create(Application);
      ItemInq.ShowModal;
      ItemInq.Free;
    end;
  end;
  UnloadPackage(wndHnd);
end;

Thanx
 Fick
0
 
LVL 1

Expert Comment

by:Kristian
ID: 7089183
A couple of maybe's :

1, put the UnloadPackage(wndHnd) line in the if rather that outside of it..
2, the way your using this package borders on using it like a DLL. this being the case in the package itself are you taking care of all resources ( frees/releases ETC )?
3, you could try loading your package in your initialize and unloading in your finalize sections rather that opening and closing repeatedly. ( thats relying on windows a bit to much for my liking !!! ).

Um,

Give then a go and see what you can work out from that..

Kristian
0
 

Author Comment

by:jfvd
ID: 7090292
In the show event I just set whatever up that needs to be set up for start-up. Yes I do call Free after I'm done with the form.

The content of my package - the idea is to use packages in stead of using seperate .EXE's or in stead of having a lot of forms in the main app. I'll usually want to access data in some data storage place and display it for user review/interaction.

BTW I don't know what I did different but everything just started working a while ago. If you know of any setting that could possibly cause this could you please let me know. I'll award you the points in any way, thanks for you time.

Do you perhaps know if you could call a package from a package, both being runtime intialized.

Thanx
 Fick
0
 
LVL 1

Accepted Solution

by:
Kristian earned 800 total points
ID: 7092111
Well, ive used packages quite a bit, but i have to say i dont use them the way you just have.

The way i use them is:

We have a number of components, and some central code all stored in a package ( medium size about 15 - 20 units/forms).  i have the package installed in delphi and use the components as normal, and any units from the package i want to use i have the path of the units set in my project options and access them in the normal way you access units.
using them in this way i now have 2 choices.
Either :
compile the code and i get one exe that has used the code it requires from the package,
or
I can goto my options for the project and there is a packages tab, here you can say do or do not compile the program with whatever packages you want. if here you dont compile your package into your program then it will just work and your exe will access the package as if the code was in the same exe. with packages you dont have do use them like dll's ( like you have ) there a lot cleverer than dll's, borland i think did a good job with packages.

To your other question about multiple packages yes you can have more than one package, ive only done it a couple of times before, but the only important thing you need to know is in the options for the package you will need to goto the linker tab and modify the image base property. this property says that the memory for this package starts here, you cant have 2 packages starting from the same memory point.

I know thats all fairly overview but if you have any Q's just keep the thread open for a while and just ask..
(until friday as im off for 2 weeks (happy dance)).

Kristian
0
 

Author Comment

by:jfvd
ID: 7092644
Thanx, I really appreciate it.

When specifying a different base address for a package do you know if there's some magic increment to use for the different packages.

As to the way I'm using the packages ... I really like it. I think Microsoft could take some lessons to make their stuff work easier - I've been in "DLL hell" before.

The two weeks sounds great ... guess I can dream about it.
 Fick
0
 
LVL 1

Expert Comment

by:Kristian
ID: 7092688
About the image base im not sure really,
the person that told me about it was Ray Kanopka ( or whatever his second name is ) the owner ETC of Raize components ( bit of name dropping ), he was doing some advanced package classes at DCon 2001 and he mentioned this point. he just moved the image by a thousand as i recall but as for the exact implications im afraid your on your own on this one.

As for Microsoft taking lessons i agree totally, but i think they have with this C#, the bloke that did most of the work for Delphi did C# for microsoft ( obviously offered him a wedge of money ), Must give it a go and see what Microsoft are upto, it sounds quite good, or is it all just hype?

Glad to be of help anyway.
Kristian
0
 

Author Comment

by:jfvd
ID: 7092733
I'll have a go at the addresses some time and let you know if I find anything.

I've looked at C# and it's quite ok. I just still like Java better for the job that C# is competing for really. I just don't trust MS to ever make it really platform independend as they say it would be eventually. Other than that I think it's still to "young" really to amount to to much ... not enough service packs out yet. I used to be a MS only developer, mainly VB, Access, SQL server.

Just my thoughts
Fick
0
 
LVL 1

Expert Comment

by:Kristian
ID: 7092865
What i need is a version i havn't got to pay for.
are there any evaluation versions, or like delphi Professional Versions ETC that are cheeper.
I obviously utilise what i have at work, but things like C# were not using and i aint going to pay out of my own pocket, coz they aint cheep. Got any sugestions on any avenues i could pursue?

Kristian


0
 

Author Comment

by:jfvd
ID: 7092890
As far as I know MS has something called a student program or something that allows you to play with whatever but you're not able to create stand alone apps. Everything you do only runs in the IDE. As far as C# it's part of Dev studio on the moment so you might find something there. The last I looked the student version was something like $100 or less. Who knows they might even have an eval copy on their website.

I'll see if I can come up with anything and let you know.

Fick
0
 
LVL 1

Expert Comment

by:Kristian
ID: 7092901
Cool,
I will have a look some time...

Kristian
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month9 days, 16 hours left to enroll

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