Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4327870
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T09:35:56+00:00 2026-05-21T09:35:56+00:00

My server returns a string stream as OleVariant via a COM/DCOM call. This code

  • 0

My server returns a string stream as OleVariant via a COM/DCOM call.
This code works well for the client, but can probably be improved.
Hints are welcome.

And as a follow up, what if the server returns the OleVariant stream as UTF-8,
what is the best way for the client to convert it to unicode ?

procedure TClientToServer.GetText(       mode     : integer;
                                                 const infoText : widestring;
                                                      txt         : TStrings);
var
  size        : integer;
  dataP       : pointer;
  data        : OleVariant;
  strStream   : TStringStream;
begin
  txt.Clear;
  data:= fDComServer.GetData( mode,infoText);
  if VarIsNull(data) then Exit;
  size:= VarArrayHighBound(data,1) + 1;
  dataP:= VarArrayLock( data);
  try
    strStream:= TStringStream.Create;
    try
      strStream.Write( dataP^,size);
      strStream.Seek(0,0);
      txt.LoadFromStream( strStream);
    finally
      strStream.Free;
    end;
  finally
    VarArrayUnlock( data);
  end;
end;

Edit :
Going for UTF8 means that less bandwidth is used on the network, and I can reuse the COM/DCOM routines more or less intact when later implementing a http protocol interface based on UTF8 strings.

Thanks David for pointing me in the right direction to trim the code a little bit.

Here is the updated procedure :

procedure TClientToServer.GetText(       mode     : integer;
                                   const infoText : widestring;
                                         txt         : TStrings);
var
  size    : integer;
  dataP   : Pointer;
  data    : OleVariant;
  utf8Str : Utf8String;
begin
  txt.Clear;
  data:= fDComServer.GetData( mode,infoText);
  if VarIsNull(data) then Exit;
  size:= VarArrayHighBound(data,1) + 1;
  dataP:= VarArrayLock( data);
  try
    SetString( utf8Str, PAnsiChar(dataP), size);
    txt.Text:= utf8Str;
  finally
    VarArrayUnlock( data);
  end;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T09:35:57+00:00Added an answer on May 21, 2026 at 9:35 am

    You don’t really need the string stream. You can just call SetString() to create a Delphi string containing the contents of dataP and then assign that string to txt.Text. If you have UTF8 data then pass a UTF8 string to SetString().

    Using SetString() still involves an intermediate buffer allocation so I guess what would really be nice would be a read-only TStream descendant which you could pass a pointer and a size. You could that pass that stream to TStrings.LoadFromStream. It would be easy enough to write such a thing.

    Do you actually have performance problems though? If not then why change from your current approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is the following possible in SQL Server 2000? CREATE FUNCTION getItemType (@code varchar(18)) RETURNS
i have used following code in my c# application string verification_url = @http://site.com/posttest.php?; string
I have config.time_zone in environment.rb set to UTC, and my mySQL server returns the
I have an HTTP server that returns large bodies in response to POST requests
From one apache server file_get_contents returns the contents of a url straight away. On
On my Centos server Python's mimetypes.guess_type(mobile.3gp) returns (None, None), instead of ('video/3gpp', None). Where
Stored procs in SQL Server sometimes finish with a return code, as opposed to
I have a string that I Gzip on the server and download to a
I have set up WebDAv server on my Debian linux and this is working
I'm having a strange problem comparing strings. I send a string to my server

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.