Board index » delphi » Sharing a component?

Sharing a component?

Hello everybody!

Is it possible to share an object/class instance between main application
and a dll? Whatever approach I try I get some error messages.
Here's a simple example:

I have a TMemo instance on the main form of a calling application. A dll
function should fill this Memo1.Lines property. I pass an address of
Memo1.Lines as a pointer parameter to the dll function like this:

// this code is placed in DLL

type pStringList = ^pStringList;

procedure GetStringList(var List: pStringList);
begin
  List^.Add('some text')
  List^.Add('again some text');
  List^.Add('some more text');
end;

when I call this function from my application like this:

GetStringList(@Memo1.Lines);

The Memo1.Lines gets three more lines as supposed.

But, if I try it like this:

// this code is placed in DLL

type pStringList = ^pStringList;

procedure GetStringList(var List: pStringList);
var MyStringList: TStringList;
begin
  MyStringList := TStringList.Create;
  MyStringList.Add('some text');
  MyStringList.Add('again some text');
  MyStringList.Add('some more text');
  List^.Assign(MyStringList);
end;

I get strange EConvertError exceptions when it comes to assignment. And it
happens every time on whatever class I use.

Real problems arise when I have "big" components that are stored in DLL's
forms, like DBGrids, TreeViews and so. I could pass an address of a target
object as a pointer parameter, and then assign all the properties to the
dereferenced object in dll, but that would eat up much time writing all the
ThisProperty := ThatProperty stuff.

Is there any way that I cann assign an object from DLL to an object in EXE,
and avoid writing thousands of lines of code in DLL's?

Thanks a lot!

Vjekoslav

 

Re:Sharing a component?


Quote
In article <8891ip$h...@bornews.borland.com>, Vjekoslav Babic wrote:
> Is it possible to share an object/class instance between main application
> and a dll? Whatever approach I try I get some error messages.
> Here's a simple example:

Vjekoslav,

i answered your post in b.p.delphi.objectpascal.

Please do not post your question to several of the newsgroups at once, it is
against the forum guidelines (see http://www.borland.com/newsgroups/) and
just wastes resources (both server and human, somebody might spend time on
answering a post that has already been answered in another newsgroup).

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!

Sent using Virtual Access 5.00 - download your freeware copy now
http://www.atlantic-coast.com/downloads/vasetup.exe

Other Threads