Data modules in a Package, etc. ...

I'm still totally lost when it comes to using packages.  Please tell me-

1.  When I compile all my units for a particular part of my program into a DLL, I need to declare the functions/procedures as "external" and HAVE to have "Sharemem" as my top "Uses" item.  Would this still be true if I compile all those units into a package rather than a DLL?

2.  Am I correct in assuming that if I compile my data modules into a single Package, all other parts of the program/project will have access to the data as if I'd compiled it as a part of the main program?

3.  Even if the answer to part 2 is "Yes", how do the tables, etc., get created (initialized in memory and the BDE) if I don't use some sort of OnCreate for the data module form?

>ANY< examples that would help answer these questions would be greatly appreciated, as D4's help doesn't make the differences between DLL's and Packages all that clear to me!

Thanks
Raven1155Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
RadlerConnect With a Mentor Commented:
Hi Raven;

Maybe I started this doubt to you.
To windows architeture a package is a DLL, but to compiler the things are a bit diferent.
When a package is loaded your initialization code resolves the dependecies found at Requires clause in DPK.
All references are solved internaly looking at EXE or loading a dependent package. Imagine a non database appplication that load a package that requires BDE, so VCLDB are internally loaded.
The address space when you load a package is the same so no problems are decorrent this( no ShareMem ).
The better thing using package are Multi Thread apps. I haven't experience about this, but comments are negatives.

this my main package snap
<BOF>

package Lib32;

{$R *.RES}
{$R 'lib32btn.dcr'}
{$ALIGN ON}
{$ASSERTIONS OFF}
{$BOOLEVAL OFF}
{$DEBUGINFO OFF}
{$EXTENDEDSYNTAX ON}
{$IMPORTEDDATA ON}
{$IOCHECKS ON}
{$LOCALSYMBOLS OFF}
{$LONGSTRINGS ON}
{$OPENSTRINGS ON}
{$OPTIMIZATION ON}
{$OVERFLOWCHECKS ON}
{$RANGECHECKS ON}
{$REFERENCEINFO OFF}
{$SAFEDIVIDE OFF}
{$STACKFRAMES ON}
{$TYPEDADDRESS OFF}
{$VARSTRINGCHECKS ON}
{$WRITEABLECONST ON}
{$MINENUMSIZE 1}
{$IMAGEBASE $00400000}
{$DESCRIPTION 'Super Library'}
{$IMPLICITBUILD OFF}

requires
  vcl40,
  VCLX40,
  VCLDB40,
  VCLSMP40;

contains
  About in 'About.pas' {AboutBox},
  Aboutdlg in 'Aboutdlg.pas',

  // another's unit are listed here

  CURREDT in 'CURREDT.PAS';

end.

When I'm using this package I must be loaded at Delphi before. Any Component used automatically fill the uses clauses to related unit.
Any function writed must be preceed with a uses to referent unit before.
Nothing more to do.

More comments maybe supplied later.


T++, Radler.
0
 
Raven1155Author Commented:
Radler,

I >think< you've answered my question, but as I gather you normally speak a germanic language, some of what you wrote needs clarifying before I grade the answer!

>>When a package is loaded your initialization code resolves the dependecies found at Requires clause in DPK.<<
The packages I'm talking about (e.g., the memory module, etc.) don't HAVE initialization code.  Would a simple "Cust_Data:=TCust_Data.Create()" type command work from the main program?

>>The better thing using package are Multi Thread apps. I haven't experience about this, but comments are negatives.<<
Are you saying that you've heard bad things about Multi-thread apps?

>>When I'm using this package I must be loaded at Delphi before. Any Component used automatically fill the uses clauses to related unit.
Any function writed must be preceed with a uses to referent unit before.<<
I am not writing any components that I'm putting on the palatte, I just want the code to be in Packages rather than DLLs so I can call 'em from the main program as if I'd written them as an integral part of the main program.  I am asking for confirmation that the stuff written into packages is readily accessible from the main program...

Please clear these aspects up so I can grade the answer.

Thanks a lot!
 Jim 8^}

0
 
RadlerCommented:
More details:

By your example TCust_Data.Create() is a method inside a package, so when this package is loaded( like a DLL ) the method address is resolved to future use, and this and another things is done at initialization code.

About Multi Thread the comments are negative because is dificult to programmer deal with this. Some variable are globals other locals and each thread deal with this. As I said my experience is poor, and details I stay in debt with you.

When you load a Package in Delphi, the IDE does a great job like put at uses clauses the reference to specified unit. This information is allocated inside all packages that Delphi load, so the references are filled automatically.

If you is starting now, don't make the same error that I made.
Try group correlated units at diferent packages, this make yours projects have more scalability.

I imagine that at Borland's Site there are more details information.

T++, Radler.
0
 
Raven1155Author Commented:
Thanks for the follow-up!
0
 
RadlerCommented:
Thanks Raven;

I remember that the first motivation to borland add Packages technolgies was the VB paradigm and the UML concepts.
Packages are great and whem some time availble I'll see the dinamic package load ( See LoadPackage at Delphi doc's ).

T++, Radler.
0
All Courses

From novice to tech pro — start learning today.