[Original] That IS A DLL. (But Not All Dlls Are BPLS.)> But I Still Found Some Different, Such As That I Can Create A> Object from The Host EXE AND THAT TO A BPL AND modify it safely, but> if I do same to a dll, I can not modify any referenced property of the object. When you use packages, there is only ever one copy of any unit in memory. One copy of Forms, one copy of SysUtils, one copy of System (well, most of it), one copy of StdCtrls, etc. All class-related operations, such as the "is" and "as" operators, rely on class references. class references are actually just addresses . They point to definitions for the layouts of the classes' internals (They point to what's called the virtual-method table, the VMT.) Two classes are the same if they point to the same VMT -. if the addresses are equal. WHEN You HAVE OF STDCTRLS AND THE SAME CLASS Defined in A DLL'S COPY OF STDCTRLS, Those Classes Will Really Have Different Addresses. The "IS" and "as" Operators Won't work with cross-module clases. But when use packages, there is only one copy of the class, kept in vcl70.bpl, so all modules trians, So All modules, single class definition. Another factor is the memory manager in System. All string allocations ultimately call GetMem and FreeMem. If the EXE allocates a string, it uses its own GetMem. It then passes the string to a DLL, and the DLL might try to free It. The DLL WILL CALL ITS OWN COPY OF FreeMem, Which Won't have access to the estu the exe's memory-manager structures, and you '
ll get errors With packages, everything will use the same memory manager from rtl70.bpl (This can also be solved by using a shared memory manager between the EXE and the DLL;.. ShareMem is one example That will not solve the class. -comparison problem, though.) Above, I said the major difference between bPLs and DLLs is the number of exported functions. With a DLL, the only things exported are what appear in the "exports" clause that you write yourself. With a BPL , everything from all the units' "interface" sections gets exported, including global variables and class definitions. Also exported are the addresses of the "initialization" and "finalization" sections. and, internally, that is indeed the major difference. A BPL exports the functions necessary for the RTL to recognize the file as being a BPL and not just a generic DLL. If you call LoadPackage, i will call LoadLibrary to load it like a normal DLL, and then it will call all the package's units' initialization Sections and do a feo The BPL is DLL, but not all DLLs are BPLs. > But I still found some different, for example,> I can create an object in the primary application, pass it to the BPL, then> I can safely modify it. But if I use a DLL, I can't modify and> reference the properties of this object. When using Packages, each unit, each form, each sysutils, each system, etc. have only one copy,
All operators that act on classes, such as IS and AS, depending on the class reference, the reference to the class is actually a (limited) pointer, pointing to the definition of the class (that is, the virtual function table VMT) If the two reference points to the same VMT, then they are references to the same class.
If you use the same as the same in STDCtrs in EXE and DLL, the VMT of these two classes has different addresses, IS and AS operators do not work correctly in different modules. But if you use a package, there is only one copy of the class in memory, saved in VCL70.bpl, then all the modules that reference the package share the same class. Another factor is the memory manager in the System cell. All string allocations are finally called getMem and FreeMem. If EXE assigns a string, it uses its own GetMem function copy, if it passes the string to the DLL, go to Free in the DLL. Then this DLL will call the copy of its own FreeMem function, and this FreeMem function cannot access memory manager in EXE, which will generate errors. And if you use packages, they use the memory manager in RTL70.bpl. (This problem can also be solved by sharing a memory manager between EXE and DLL, shared memory is just an example. But still can't solve the problem between classes.) In the above, I think the main difference between BPLS and DLLs is The number of output functions. The only thing that is output with DLL is those specified by the exports keyword. With BPL, all units of Interfaces defined in all units, including global variables and class definitions, address of the INITIALIZATION, and Finalization portions are also output. In addition, there is indeed very different inside the DLL and BPL. BPL Output All functions required for RTI recognition a file is BPL instead of a DLL file. If you call LoadPackage, I can also call LoadLibrary as a normal DLL to Load, then it will call all units of all units in Packages and do some other Housekeeping? Operation. The assembly code generated when the function in the package is called and the assembly code generated in the DLL is the same. The first translation article, many local translations are not good. I think this article is very good, I hope that the master has time to re-translate once, thank you.