Solved

Sending data using OLE interfaces

Posted on 1998-03-27
3
194 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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Process Javascript errors with Delphi TWebBrowser 1 132
Delphi Form ownership 4 89
find a node in VST 2 68
how can i search if string exist in array ? 3 58
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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
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 …

773 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