Solved

Streaming Data between COM Objects

Posted on 2000-04-14
13
464 Views
Last Modified: 2012-05-04
I need to stream data from one COM Object to another over a COM interface. The objects will be executables which could be running on separate machines. How do I declare and connect the streams within the objects ?? I have had a look at TOLEStream in Delphi5 , but the help gives little or no info.

Cheers,
Ben
******************
Hello all, thanks for the responses.
I need to state that the data I will be streaming is not intented to be used for the rebuilding of an object or component.

The data is captured from a serial port in Application1 and streamed to memory or file.

Application 2 connects to Application 1 and requests that the data be "streamed" to it , where it will be processed.
0
Comment
Question by:bfjvr
  • 3
  • 3
  • 2
  • +4
13 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2715940
listening...
0
 

Expert Comment

by:jonnyfive
ID: 2716247
Hi Ben...

are you dealing with an in or out of process server? If it's an in process server you could simply pass the a pointer to your stream object. I'm not too sure with an out of process server, but I think the only way there is to write your own marshaling mechanism (though there might be another way which I don't know).

Hope that helps... Jonny...
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2716288
That's why I'm only listening here. I'm writing a control (a virtual treeview to be precise) which supports OLE drag'n drop. But I haven't got dragging between applications to work because of the expensive marshalling mechanism. For system stuff this is already there, so at least this is usable...

Ciao, Mike
0
 
LVL 2

Expert Comment

by:kubeerja
ID: 2716381
what about using variant array of type varByte and send data check this function:

function VarArrayLoadFile(const FileName: string): Variant;
var
 F: file;
 Size: Integer;
 Data: PChar;
begin
 AssignFile(F, FileName);
 Reset(F, 1);
 try
   Size := FileSize(F);
   Result := VarArrayCreate([0, Size - 1], varByte);
   Data := VarArrayLock(Result);
   try
     BlockRead(F, Data^, Size);
   finally
     VarArrayUnlock(Result);
   end;
 finally
   CloseFile(F);
 end;
end;
0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2717722
Ben, do you have any COM/DCOM experience?
0
 

Expert Comment

by:mathought
ID: 2718746
listening...
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Expert Comment

by:xsoft
ID: 2720754
Hi Ben,

I would also think that using variant array of type varByte as kubeerja said should be able to do everything you would need. I even saw a sample of how you could write a component to a MemoryStream, stuff it into a VarArray and then on the other computer unpack the VarArray back to a MemoryStream and recreate the component from that stream.
In that example the component first executed some work on computer 1, was then marshalled to computer 2 and all the results produced on computer 1 wre available on computer 2.

Thomas

P.S. To Lischke:

Mike,

maybe this could help you:

Drag and Drop Component Suite by Angus Johnson, Anders Melander , freeware full source at http://www.melander.dk

0
 
LVL 10

Expert Comment

by:Lischke
ID: 2720829
Hi Thomas,

thank you for the link. Actually, I know the work of Anders because it was one of the sources I consulted when I implemented my own stuff. It is really good for standard stuff of the system, although it seems as would it have been created to provide as much as possible instead of as easy as possible.

Unfortunately, we are talking here about the really difficult stuff. Have you ever tried to pass your own interface along between different applications? Without marshalling you can't even get an interface which is derived from a standard interface. I, for instance, tried to extend IDragSource with an additional method. Through the default marshalling I got always only the normal IDragSource interface never my derived interface.

Ciao, Mike
0
 
LVL 1

Expert Comment

by:xsoft
ID: 2720972
Hi Mike,

I don't see where the problem is for passing interfaces between applications.
I did not try to pass my own interfaces between apps so far but at the moment I am writing some COM servers which I call from MS-Office apps by VBA.
In the last week I made a small test:
In my COM-server I Included an OLEVariant parameter to a method and in a macro which I call from word I created an instance of my server and passed a Variant which was actually a WordDocument Interface to my server.
In my server I was able to cast the OLEVariant back to the Document-Interface and access it completely via early binding. (Of course I had to include the Word.TLB in my code)
Shouldn't something simular work for you too?

Thomas
0
 

Author Comment

by:bfjvr
ID: 2721711
Edited text of question.
0
 
LVL 2

Accepted Solution

by:
kubeerja earned 300 total points
ID: 2722754
as I mentioned before you can send it as variant array and in the other side converted back to buffer and write it into a memory stream or file as here in this code :

procedure VarArraySaveFile(const FileName: string ; varData : Variant);
var
 F: file;
 Size: Integer;
 Data: PChar;
begin
 if not VarIsArray(varData) then
 begin
  messagedlg('Wrong Variant format',mtError,[mbOK],0) ;
  exit ;
 end ;
 AssignFile(F, FileName);
 ReWrite(F, 1);
 size:=VarArrayHighBound(varData,1)+1 ;
 try
   Data := VarArrayLock(varData);
   try
     BlockWrite(F, Data^, size);
   finally
     VarArrayUnlock(varData);
   end;
 finally
   CloseFile(F);
 end;
end ;
0
 
LVL 1

Expert Comment

by:xsoft
ID: 2724119
function MemoryStream2Var(Const MStream:TMemoryStream):OleVariant;
var P:Pointer;
begin
    Result:=VarArrayCreate([0,MStream.Size-1],varByte);
    P:=VarArrayLock(Result);
    try
      Move(MStream.Memory^,P^,MStream.Size);
    finally
      VarArrayUnlock(Result);
    end;
end;

HTH,

Thomas
0
 

Author Comment

by:bfjvr
ID: 2725531
Seems like a variant array is the way to go then.

Thanks to all.

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now