Re: TListview storing pointers to Com objects?
From: Chris Cheney (cjc1_at_nospam%ucs.cam.ac.uk%no%spam%please)
Date: 02/18/04
- Next message: AlanGLLoyd: "Re: midistreamopen"
- Previous message: AlanGLLoyd: "Re: midistreamopen"
- Next in thread: Bruce Roberts: "Re: TListview storing pointers to Com objects?"
- Reply: Bruce Roberts: "Re: TListview storing pointers to Com objects?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 18 Feb 2004 11:57:24 GMT
"Savannah_Alan" <fake@email.com> wrote in
news:XMKdnQcLZ4fkua7dRVn-gQ@comcast.com:
> I have a TListview, which I am trying to get to store pointers to a com
> object. Whenever the following code is run, I can only access the very
> last object added. Anything else gives the error:
> ---------------------------
> Debugger Exception Notification
> ---------------------------
> Project raised exception class EOleException with message 'No such
> interface supported'. Process stopped. Use Step or Run to continue.
> ---------------------------
> OK Help
> ---------------------------
>
> Am I missing something really obvious here?
>
> Thanks.
>
> procedure TfrmMain.ShowMessages();
> var
> TempMessage: CSMailLib_TLB.Message;
> SearchRecord: TSearchRec;
> NewItem: TListItem;
> begin
> //This routine will populate the inbox listview with the messages
> saved lvwMessages.Clear;
> try
> if (FindFirst(AppPath() + '\Messages\' + cboAccounts.Text +
> '\*.msg',
> faAnyFile, SearchRecord))=0 then
> begin
> TempMessage:=coMessage.Create;
> TempMessage.LoadFromFile(AppPath() + '\Messages\' +
> cboAccounts.Text +
> '\' + SearchRecord.Name);
> NewItem:=lvwMessages.Items.Add;
> NewItem.Data:=Pointer(TempMessage);
By inspection (i.e. not by testing the code), I reckon the problem starts in
the above line. When Delphi assigns a COM object, it implicitly compiles in
the necessary _AddRef/_Release calls. By typecasting the RHS as Pointer, you
are telling the compiler that it is to treat the value as a Pointer, not as
a COM object.
You could, I think:
a) leave the code as it is and add the necessary _AddRef call.
or
b) typecast the LHS to CSMailLib_TLB.Message, removing the typecast from the
RHS
but, either way, you must ensure that _Release gets called when the
TListItem gets destroyed.
HTH
- Next message: AlanGLLoyd: "Re: midistreamopen"
- Previous message: AlanGLLoyd: "Re: midistreamopen"
- Next in thread: Bruce Roberts: "Re: TListview storing pointers to Com objects?"
- Reply: Bruce Roberts: "Re: TListview storing pointers to Com objects?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|