?
Solved

Using IDataObject

Posted on 1998-04-23
13
Medium Priority
?
449 Views
Last Modified: 2010-04-06
I want to use IDataObject to pass data across a COM interface.  How do I do this.  My COM server is an in-process activeX server with an interface decended from IDispatch using the type library editor.

BigMadDrongo
0
Comment
Question by:BigMadDrongo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 6
13 Comments
 
LVL 4

Expert Comment

by:d003303
ID: 1336651
Yo,
where do you want the data to go today ;-) The IDataObject interface is quite open, so you may have to supply a LOt of different data formats in that object. If you want to exchange data only between COM objects written by yourself you could declare your own format, but I think you will not use IDataObject then.
I guess you want to use IDataObject to communicate with the shell. Do you want to READ data from IDataObject or WRITE data through a IDataObject ?

Slash/d003303
0
 

Author Comment

by:BigMadDrongo
ID: 1336652
What we have is two COM in-process servers which need to share a large amount of data.  This data is stored in a class derived from TComponent, which contains various standard data types and a collection.  Each item in the collection contains various standard data types as well as 3 other collections.  Because there are collections of collections, I can't stream the data into a memory stream and copy that memory stream across the interface  as a variant array because only the first level of collections is stored in the stream using the WriteComponent method.  IDataObject has been recomended to me as a means of sharing this data, but I have no idea how to use it.  I tried to comprehend Kraig Brockschmidt's Understanding Ole, but couldn't, having no knowledge of C++.  If you know hoe to use it, any help will be appreciated, or if you can suggest an alternative method, then I'm all ears.

Cheers

BigMadDrongo
0
 
LVL 4

Expert Comment

by:d003303
ID: 1336653
OK,
it does not matter what interface you use. IDataObject is a standard interface to the OLE world. But very complex to use.
So your goal is to stream private data over a COM interface between private COM objects. So we should first focus on the data itself.
It will be best to use the internal streaming system of Delphi. Let's take a look at your object structure :

MyComponent
-MyProperty1
-MyProperty2
-MyCollection1
 -MyCollectionItem1.1
  -MyCollection2
   -MyCollectionItem2.1
   -MyCollectionItem2.2
 -MyCollectionItem1.2
  -MyCollection2
   -MyCollectionItem2.1
   -MyCollectionItem2.2
 -MyCollectionItem1.3
  -MyCollection2
   -MyCollectionItem2.1
   -MyCollectionItem2.2

Most important is that all collections get saved. That is the main thing, not the interface it is streamed over.
To get all your data saved, you will have to override the DefineProperties method of MyCollection1 that each collection item can stream its containing collections. You will need to design a read and write method for the first level of the collections. I'll take a look how to do this in detail.
Again, the interface is not important. If you can use a stream to get your data saved and read again, you've got it !

Slash/d003303
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:BigMadDrongo
ID: 1336654
Where might I find the basic structure for the define properties method?  What code will I need to put in it when I override it.  Unfortunately I've taught myself Delphi from books and although I have overridden some simple functions, I wouldn't know where to start with overriding Define Properties.  Any guidance would be greatly appreciated!

BigMadDrongo
0
 
LVL 4

Expert Comment

by:d003303
ID: 1336655
Yo,
the DefineProperties method defines how your component stores its data. The method

procedure MyComponent.DefineProperties(Filer: TFiler);
begin
  Filer.DefineBinaryProperty('AProperty', ReadAProperty, WriteAProperty, ShallWeWrite);
end;

would notify the Filer object that it should use the ReadAProperty and WriteAProperty to read/write the AProperty property in binary and checks with the ShallWeWrite method if the property shall be written or not. Check the online help on the DefineBinaryProperty and DefineProperty methods.
If you were using only components and not collections, everything would be saved automatically, because every component writes its contained components. So you must close this gap that your collection will write all collections of the containing collection items.
More clearer or more confused now ? I'll give a small example later on.

Slash/d003303
0
 

Author Comment

by:BigMadDrongo
ID: 1336656
It's a bit clearer now.  I take it I need to define ReadAProperty and WriteAProperty as procedures which store components into a stream, and the components are of the type passed in as the 'AProperty' string.  How do I go about writing these procedures?  I've looked up TStreamProc in the help files and in the Delphi source, but with no luck.  If you have an example, it would be appreciated.

BigMadDrongo
0
 
LVL 4

Expert Comment

by:d003303
ID: 1336657
OK, i'll prepare an example.

Slash/d003303
0
 

Author Comment

by:BigMadDrongo
ID: 1336658
Slash/d003303

Thanks very much.  If it is easier, you can contact me by e-mail on

James_R_Bennett@SBPHRD.COM

Cheers

BigMadDrongo
0
 

Author Comment

by:BigMadDrongo
ID: 1336659
I found some info in the Delphi Developers Handbook about the define properties method, and I think I have the hang of it.  What I do is the following:

procedure TRxnScheme.DefineProperties(Filer: TFiler);
begin
  Filer.DefineProperty('fNumberOfCompounds', ReadCompounds, WriteCompounds, True);
  Filer.DefineProperty('fNumberOfAssociations', ReadAssociations, WriteAssociations, True);
end;

procedure TRxnScheme.ReadCompounds(Reader: TReader);
begin
  fNumberOfCompounds := Reader.ReadInteger;
end;

procedure TRxnScheme.WriteCompounds(Writer: TWriter);
begin
  Writer.WriteInteger(fNumberOfCompounds);
end;

procedure TRxnScheme.ReadAssociations(Reader: TReader);
begin
  fNumberOfAssociations := Reader.ReadInteger;
end;

I can stream this into a file, and it stores the relevant bits.  One problem I do have is that some of my properties are variants and enumerated types, and there are no methods in TReader or TWriter to read and write these two types.  How do I read/write them?

Cheers

BigMadDrongo
0
 
LVL 4

Expert Comment

by:d003303
ID: 1336660
Yo,
you will have to write an algorithm that covers the reading/writing process. So e.g. the first thing to save in a variant is the variant type, then depenging on the type its content. Reading is the same thing vice-versa. Enumerations can be saved/read as a set.

Slash/d003303
0
 

Author Comment

by:BigMadDrongo
ID: 1336661
Slash/d003303

I've managed to get it all working, streaming to a file and back quite successfully.  If you want the points for your help, just post an answer, and they're yours!

Cheers for your help.

BigMadDrongo
0
 
LVL 4

Accepted Solution

by:
d003303 earned 800 total points
ID: 1336662
Yo BigMadDrongo,
nice that it all works !

Slash/d003303
0
 

Author Comment

by:BigMadDrongo
ID: 1336663
Cheers for all your help!

BigMadDrongo
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question