这是我在Borland官方论坛上得到的解答。其它同仁如果遇到类似问题可以参考:Newsgroups: borland.public.delphi.objectpascal
Subject: Re: Why does IS operator fail to recognise the control's type which passed from the main .EXE into the .DLL?
From: "Peter Below (TeamB)" <[email protected]>In article <3ac16ab1_2@dnews>, George Wei wrote:
> I have written a DLL which exports the following procedure:
> The executing result is: DoSomething alwayse shows 'Other'!!! As my 
> debugging result, I can get Sender's ClassType or ClassName correctly 
> inside the procedure DoSomething, but IS operator alwayse returns false. Build both projects with run-time packages.The reason it failed without packages is this: Delphi identifies a class at 
run-time by the address of the classes virtual message table, which in turn is 
part of a larger class record. This method of class identification is used by 
the Is and As operators, for instance.
Without packages each module of the application has its own set of the VCL 
code, each module will have a class record for TForm, for instance, all with 
different addresses, of course. So if some VCL code does a test like
 
 If control Is TForm then...
 
and the control (which in fact is a TForm descendent) was created in another 
module, then the test will fail. You may even get cryptic exceptions from 
TPersistent.Assign like "Cannot assign a TFont to a TFont." This happens 
because the two TFonts in question were created in differen modules.
 
With packages you only have one common set of the VCL code (in the Delphi base 
packages like VCL40.BPL), only one class record per class for all your 
modules, so the problem is gone.Peter Below (TeamB)  [email protected])
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.