Solved

Sending data using OLE interfaces

Posted on 1998-03-27
3
199 Views
Last Modified: 2010-04-06
I'm writing an ActiveX DLL and I need to send a data structure consisting of a number of classes in a linked list through it's interfaces.  How can I convert this into a data type that OLE can understand?
0
Comment
Question by:BigMadDrongo
3 Comments
 
LVL 4

Expert Comment

by:d003303
ID: 1360964
Yo,
implement the IEnum interface and enumerate through the linked list. The classes you want to pass over should be COM objects with a type library. This as an ultra-short comment. If you have questions, just ask.

Slash/d003303
0
 
LVL 3

Accepted Solution

by:
williams2 earned 200 total points
ID: 1360965
Delphi OLE has a strange understanding of arrays (linked lists). To assign an array to a OleVariant, you need to insert the elements into a TSafeArray. It's a generel suggestion due to the complex handling of variants. (please look up SafeArrays or TSafeArray in the Delphi Help index list). To send special objects, you can first build a record with all simple attributes and send them through the interface as a TSafeArray of Bytes (length = SizeOf(Record) ) and then reassemble the structure. Another approach is to use the class'es .SaveToStream/.LoadFromStream' methods which provides all necessary data in one structure. You could also use the .WriteComponent and .ReadComponent method.
Handling Objects with OLE is not trivial, and the solution generelly depends on which system you want do develop.

Regards
Williams
0
 

Author Comment

by:BigMadDrongo
ID: 1360966
First you have to simplify a datastructure, so you will be able to trace your data's. Stringlists can be saved as one nullterminated string (use the getText function). Try putting all data's you have into one record. I can help you with these routines. I have tested them, and they work fine.

The Addr is the address pointer to the record. (Like ^Record).

  Function RecToOleVariant(Addr: Pointer; Const RSize: Word): OleVariant;
  var
    p: PByteArray;
    i: Integer;
  Begin
    Result:= VarArrayCreate([0, RSize-1], varByte);
    p:= Addr;
    For i:= 0 to RSize-1 do Result[i]:= p[i];
  End;

  Procedure OleVariantToRec(Data: OleVariant; addr: Pointer; RSize: Word);
  var
    p: PByteArray;
    i: Integer;
  Begin
    p:= addr;
    For i:= 0 to RSize-1 do p[i]:= Data[i];
  End;

When you use linked lists (chained lists), you should consider a record ID (Identifing a class) and build up your data by some recursive method.

If like to know more, please leave a comment.

Regards
Williams
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

829 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