Board index » delphi » Passing objects (like TTable) to COM objects

Passing objects (like TTable) to COM objects

Hi,

  Is it possible for a COM object to access a TTable or other object that
exists in the client app? If so, is there any special that needs to be done
- or is it just like passing any other object?

--
Chris.

 

Re:Passing objects (like TTable) to COM objects


As long as your COM object is running in the same process space (ie,
it is in a DLL and on the same physical machine), you can simply pass
a pointer to your Delphi Object. Be advised however, that this
practice is not approved. COM objects should only be passed
COM-approved types (Interfaces, WideString, etc).

Also, as soon as your COM object will be running out-of-process (ie,
in an executable or on another machine), BOOM!

Re:Passing objects (like TTable) to COM objects


When you use providers/clientdatasets essentially you
get the ability to communicate back and forth.Why you
want to pass a TTable to a com object ? Even if you
have any special requirements you may be better off by
passing the data in the TTable(more preferably use
a clientdataset and pass cds.data ) to the com object.
-Vijay

Re:Passing objects (like TTable) to COM objects


Hi Vijay,

  Yes, I know it sounds strange. But I do have special requirements. Nothing
would be easier than being able to pass a TDataSet - if that's possible?

  In your clientdataset scenario, would it be possible to easily get data
from a regular TDataSet into a TClientDataSet first?

Quote
> When you use providers/clientdatasets essentially you
> get the ability to communicate back and forth.Why you
> want to pass a TTable to a com object ? Even if you
> have any special requirements you may be better off by
> passing the data in the TTable(more preferably use
> a clientdataset and pass cds.data ) to the com object.
> -Vijay

--
Chris.

Re:Passing objects (like TTable) to COM objects


Can you use an ADO record set instead?  I think you could pass it to a com
object. (Someone correct me if I'm wrong).

-Andrew

Re:Passing objects (like TTable) to COM objects


Quote
>In your clientdataset scenario, would it be possible to easily get data
>from a regular TDataSet into a TClientDataSet first?

Chris,
You mean something like DataSet.Data := CDS.Data.....
You got me.....Nothing I know of except creating CDS
programmatically and assign the field values from the
dataset.You can do this in a loop but will need to execute
FieldNamesCount times RecordCount.Can improve the performance
by calling disablecontrols if any present.
-Vijay

Re:Passing objects (like TTable) to COM objects


Quote
> Can you use an ADO record set instead?  I think you could pass it to a
> com object. (Someone correct me if I'm wrong).

Yes I am passing ADO recordsets already but it would be nicer to pass
TDataSets. I have a feeling that is not possible because, from my vague
knowledge of COM, I think you have to marshal stuff you want to pass -
because it crosses process boundries.

But I always like to ask just in case.

--
Chris.

Re:Passing objects (like TTable) to COM objects


hi,

it is possible to pass allmost any object to a COM dll, but in a dirty way.

- Use runtime packages
- Make sure the object's class is located in a package that is used by your
app _and_ by your DLL
- In the exe typecast the object to an integer as you send it to the dll
- In the Dll typecast it back to the component type. The same object is now
availbale in you dll.

This works because objects are actualy pointers which have the size of a
(long) integer. The package is essential for the Delphi runtime environment
to recognize the pointer being of the same class. An absolute address is
used there, the bpl does take care of that.

This does (of course) not work with an out of process server.
Yes, very dirty and violating the idea of COM (language indepenncy). But
it's reliable...

--
Peter.van.Ooi...@Gekko-Software.nl
http://www.Gekko-Software.nl/Delphi

Quote
"Chris Jaboc" <n...@no.spam.com> wrote in message news:3bbe6cbb_2@dnews...
> Hi,

>   Is it possible for a COM object to access a TTable or other object that
> exists in the client app? If so, is there any special that needs to be
done
> - or is it just like passing any other object?

> --
> Chris.

Re:Passing objects (like TTable) to COM objects


If you want to do this, why not just use regular DLLs. It'll work like a
champ and you'll have no issues.

When you go COM, you have to think less of Delphi. For example, passing a
TTable to a VB COM class does not mean anything.

--
have fun
Binh Ly
http://www.techvanguards.com

Quote
"Chris Jaboc" <n...@no.spam.com> wrote in message news:3bbe6cbb_2@dnews...
> Hi,

>   Is it possible for a COM object to access a TTable or other object that
> exists in the client app? If so, is there any special that needs to be
done
> - or is it just like passing any other object?

Other Threads