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
Solved

Streaming Data between COM Objects

Posted on 2000-04-14
13
470 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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
 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
delphi exception 7 68
Comparing dates in Delphi. Greater than/ Less than 3 210
When I am typing into a TEdit last word repeats 7 145
update joined tables 2 55
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

792 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