delphi - Why does the is operator fail to return what I expect when passed an instance from a different module? -


i work on delphi project interac many other small libraries. use fastmm4 , work complex classes passed on dll parameter.

so exemple send form dll. dll test type of parameter operator "is".

but dll operator "is" return "false"

exemple

library dll;  uses      fastmm4,      system.sysutils,      system.classes,      vcl.dialogs,      vcl.forms;  {$r *.res}  procedure complex(l : tobject);stdcall; begin      if l tform         showmessage('ok')      else         showmessage('pas ok') ;       if l tcustomframe          showmessage('ok')      else          showmessage('pas ok') end;  exports   complex;  begin end. 

and call

procedure tffsisoperator.button2click(sender: tobject); var  madll : thandle;  proc  : procedure (l : tobject); begin    try       madll := loadlibrary(pchar('dll.dll'));       @proc := getprocaddress(madll, 'complex');       proc(self);          freelibrary(madll);    end; end; 

firstly, have calling convention mis-match. must fix making calling convention same on both sides of interop boundary.

even when fix that, apparent misbehaviour of is operator expected. have 2 instances of vcl in process. 1 in host , 1 in dll. each have distinct versions of classes defined in vcl. so, dll's tform different class form tform in host. , why is evaluates false.

the traditional way handle arrange have 1 instance of rtl/vcl in process. , achieve through use of runtime packages.

if runtime packages not viable option you, , must use dll, have give passing delphi classes across dll boundary. expect unwelcome news, how is. cannot pass tobject instances across dll boundary , attempt call methods, query type identity, etc. not supported dlls. runtime packages.

so, if have use dlls need stick simple types. integers, floating point values, character types, arrays (but not dynamic arrays), records, pointers such types, interfaces. simple rule of thumb, if cannot find example of proposed interop in win32, invalid.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -