Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.

ID: 18331, Using IStrings and TStringsAdapter

by siva rama d. Sundar Email: Anonymous

A Simple, Straight forward way of using 'IStrings' interface to
pass Multiple Strings from a COM Object.
Download Details
FTP  download also available 0 bytes
CDN Login Required to Download. (You will be redirected to the login page if you click on the Download Link)
To download this, you must have registered:
A free membership

For Delphi, Version 5.0  to 6.0 12 downloads
Copyright: No significant restrictions

Size: 0 bytes
Updated on Sun, 14 Jul 2002 13:36:20 GMT
Originally uploaded on Sun, 14 Jul 2002 13:34:36 GMT
The VCL Contains great amount of reusable code and Helper Objects implementing many standard COM interfaces. Particularly when in comes to the implementation of COM & related stuff, life has been made a lot easy.

One such demonstration of these beautiful helper objects is the Implementation of 'IStrings' interface via the 'TStringsAdapter' Class.

In this article we will take a sneak peak about how we can utilise this class effectively.

Assume this situation :

You are creating a loosely coupled, (COM based) business object.
you got to return a list of strings as result of a method call.
the options are many.

for ex. you may choose to return it as:
1. as a Variant Array.
2. as a huge string, seperated by delimeters
3. as an IStream
and more...

well, here is a much simpler option. most effective and faster to implement.

1. We create a TStringList object
2. fill it with strings
3. create a TStringsAdapter
4. pass the TStringList to the Adapter
5. retrieve an IStrings interface from the Adapter.

here is the code (COM Server) :

{-- Interface Declaration --}

IUsers = interface(IDispatch)
function Get_UserRights(const AUserID: WideString): IStrings; safecall;

{-- Interface Implementation --}

TUsers = class(TAutoObject, IUsers)
FUserRights : TStringList;
{Constructor, Destructor.... }

function Get_UserRights(const AUserID: WideString): IStrings; safecall;

function TUsers.Get_UserRights(const AUserID: WideString): IStrings;
FUserRights : fill your TStringList with data here.
Result := TStringsAdapter.Create( FUserRights ) as IStrings;

and at the Client Side,

1. Declare a variable of type IStrings
2. Create your COM Object
3. Call Get_UserRights and assign the result to the IStrings variable

procedure DisplayUserRights;
oUsers : IUsers;
oUserRights : IStrings;
iCtr : integer;
oUsers := COUsers.Create;
oUserRights := oUsers.Get_UserRights('');
{-- Access the individual strings as oUserRights.Item[0]... --}
{-- or you can copy it to a local TStringlist --}
oUserRights := nil;
oUsers := nil;

{-- Dependencies, Deployment Considerations --}
You got to include 'StdVcl' unit in your uses clause and
stdvcl40.dll while deploying.
(stdvcl40.dll has to be registered.)

That's All Folks.
Hope it is useful.

   Latest Comments  View All Add New

Move mouse over comment to see the full text

Could not retrieve comments. Please try again later.

Server Response from: ETNACDC03