Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
500 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (1)


Using IStrings and TStringsAdapterGo to siva rama sundar devasubramaniam's websiteFormat this article printer-friendly!Bookmark function is only available for registered users!
Product:
Delphi 5.x (or higher)
Category:
COM+
Skill Level:
Scoring:
Last Update:
07/14/2002
Search Keys:
delphi delphi3000 article borland vcl code-snippet TStringsAdapter, TStringList, IStrings
Times Scored:
5
Visits:
3450
Uploader: siva rama sundar devasubramaniam
Company: Netkraft private limited
Reference: N/A
 
Question/Problem/Abstract:
A Simple, Straight forward way of using 'IStrings' interface to
pass Multiple Strings from a COM Object.
Answer:



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)
    ['{8195E30A-ADB7-459E-804A-32A97FE1A2DE}']
    function Get_UserRights(const AUserID: WideString): IStrings; safecall;
  end;

  {-- Interface Implementation --}

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

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

  function TUsers.Get_UserRights(const AUserID: WideString): IStrings;
  begin
    {--
      FUserRights : fill your TStringList with data here.
      FUserRights.Clear;
      FUserRights.Add('rt_view');
      FUserRights.Add('rt_add');
      FUserRights.Add('rt_update');
      FUserRights.Add('rt_delete');
      FUserRights.Add('rt_approve');
    --}
    Result := TStringsAdapter.Create( FUserRights ) as IStrings;
  end;

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;
var
  oUsers : IUsers;
  oUserRights : IStrings;
  iCtr : integer;
begin
  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;
end;


{-- 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.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
TStringAdapater
    Matt Harrison (Jul 17 2002 9:35AM)

Always wondered how to use them, great little article.
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
A. B. Talal
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)