We help IT Professionals succeed at work.

Com programming

hulken
hulken asked
on
I have three classes.

1: Header looks something like this:

type THeader =class(Tobject)
  s : string
  container : TObject;
end.

type TPart = class(TObject)
  sl : TStringList;
  idList : TList;
end

and one class TProduct (looks almost like Tpart).

What I like to do is to convert this to Com objects.
But I can't fild out what to use instead of the TStringList,TList  and TObject when I use interfaces instead.

I have one procedure

GetHeaderList(Var HeaderList : TList)

that goes thorugh a database and creates a list of header's

(Each header.Container contains a TPart or TProduct)

How do I implement this using Com objects. (what I mean is what should I use instead of TList, and TStringList (and TObject)
And how do I implement this when working with interfaces.

Comment
Watch Question

DMN

Commented:
Provide 2 methods instead:

GetHeaderCount(out integer)
GetHeader(in integer,out iHeader)

Or smth like.

Author

Commented:
I still don't have an idea how to work with those interfaces?
Commented:
It's fairly easy to create COM object wrappers around VCL objects like TStringList, simply by delegating calls to a private object like this:


//----------------- BOF Code Snippet ---------------------
IStringList = interface
  ['{23043-349099-343434-340839487}']  //or whatever GUID
  procedure Add(NewString: WideString); safecall;
  procedure Delete(Idx: Integer); safecall;
  function IndexOf(IdxString: WideString): integer; safecall;
  //and all the other string list methods (except object ones)
end;

TMyStringList = class(TComObject, IStringList)
private
  slist: TStringList;
public
  procedure Initialize; override;
  //IStringList methods
  procedure Add(NewString: WideString); safecall;
  procedure Delete(Idx: Integer); safecall;
  function IndexOf(IdxString: WideString): integer; safecall;
end;

procedure TMyStringList.Initialize;
begin
  slist := TStringList.create;
end;

procedure TMyStringList.Add(NewString: WideString);
begin
  slist.Add(NewString);  //might need conversion here (?)
end;

//----------------- EOF Code Snippet ---------------------

The problem arises with TList, because you CANNOT use Delphi pointers across COM interfaces - it just won't work.
You COM wrapper around the TList object will need to return
OleVariants or something.

Author

Commented:
OK if I ue your example abowe I dont have the Items
how can I get something from the
IStringList ?
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if they are still open in 14 days.  Experts, please post closing recommendations before that time.

Below are your open questions as of today.  Questions which have been inactive for 21 days or longer are considered to be abandoned and for those, your options are:
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you, but may help others. You must tell the participants why you wish to do this, and allow for Expert response.  This choice will include a refund to you, and will move this question to our PAQ (Previously Asked Question) database.  If you found information outside this question thread, please add it.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for expert of your intention to delete and why
   --> YOU CANNOT DELETE A QUESTION with comments; special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the URL (question QID/link) that it regards with details.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this link for Help Desk, Guidelines/Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Click you Member Profile to view your question history and please keep them updated. If you are a KnowledgePro user, use the Power Search option to find them.  

Questions which are LOCKED with a Proposed Answer but do not help you, should be rejected with comments added.  When you grade the question less than an A, please comment as to why.  This helps all involved, as well as others who may access this item in the future.  PLEASE DO NOT AWARD POINTS TO ME.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.20102072.html
http://www.experts-exchange.com/questions/Q.20103849.html
http://www.experts-exchange.com/questions/Q.20145561.html
http://www.experts-exchange.com/questions/Q.20169449.html
http://www.experts-exchange.com/questions/Q.20169478.html
http://www.experts-exchange.com/questions/Q.20172645.html
http://www.experts-exchange.com/questions/Q.20177672.html
http://www.experts-exchange.com/questions/Q.20180896.html
http://www.experts-exchange.com/questions/Q.20189306.html
http://www.experts-exchange.com/questions/Q.20192697.html
http://www.experts-exchange.com/questions/Q.20193626.html
http://www.experts-exchange.com/questions/Q.20195237.html
http://www.experts-exchange.com/questions/Q.20244812.html
http://www.experts-exchange.com/questions/Q.20246719.html
http://www.experts-exchange.com/questions/Q.20261121.html
http://www.experts-exchange.com/questions/Q.20261146.html
http://www.experts-exchange.com/questions/Q.20269349.html
http://www.experts-exchange.com/questions/Q.20274432.html
http://www.experts-exchange.com/questions/Q.20289956.html

To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20181754.html
http://www.experts-exchange.com/questions/Q.20245940.html
http://www.experts-exchange.com/questions/Q.20253492.html

*****  E X P E R T S    P L E A S E  ******  Leave your closing recommendations.
If you are interested in the cleanup effort, please click this link
http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643 
POINTS FOR EXPERTS awaiting comments are listed in the link below
http://www.experts-exchange.com/commspt/Q.20277028.html
 
Moderators will finalize this question if in @14 days Asker has not responded.  This will be moved to the PAQ (Previously Asked Questions) at zero points, deleted or awarded.
 
Thanks everyone.
Moondancer
Moderator @ Experts Exchange

Explore More ContentExplore courses, solutions, and other research materials related to this topic.