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 9138835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:18:31+00:00 2026-06-17T09:18:31+00:00

I have a map map<AnsiString, Foo*> When I try to look up values in

  • 0

I have a map

map<AnsiString, Foo*>

When I try to look up values in the map I use a string I have received from a TMemoryStream and send it to a Foo* GetFoo(AnsiString) function that in turn creates an iterator and returns the object found. This works fine in most of the cases but in ONE function it doesn’t return a value.

If I do FooID = FooID.SetLength(FooID.Length() - 1); where FooID is the AnsiString to use for the look up it works and returns the correct result. I was thinking that there might be some garbage in the stream but when I look at the AnsiStrings used in the place that works out of the box and the place that needs the hack they are identical!?

This is according to the IDE’s debug value inspector… So there might be som trickery going on there. But what in earth could be causing this???

Update:

I found the implementation of the operator>>used.

PACKAGE TStream & operator >>(TStream &Stream, AnsiString &s)
{
    int i;

    Stream.ReadBuffer(&i, sizeof(i));
    if (i<0)
    {
        WideString ws;

        i=-i;
        ws.SetLength(i);
        if (i>0)
            Stream.ReadBuffer(ws.c_bstr(), i*sizeof(wchar_t));

        s=ws;

    } else if (i>0)
    {
        s.SetLength(i);
        Stream.ReadBuffer(s.c_str(), i);

    } else
        s="";

    return Stream;
}

Stepping through it seems to handle the received strings correctly. But I seem to recall hearing that issues with WideString is not uncommon 😛

Update 2:
I actually found an instance where the string returned is 6 chars long plus the ending \0 but the size is set to 7. So I guess my solution will be in the application sending that string since it supplies the wrong size.

  • 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-06-17T09:18:32+00:00Added an answer on June 17, 2026 at 9:18 am

    They are obviously not identical, since you need to truncate an extra char to make it work correctly. So find out what that extra char actually is. Either the stream data has garbage in it to begin with, or the code that is reading the AnsiString from the stream has a logic bug in it that is introducing garbage.

    When you use the debug inspector, make sure you are taking the AnsiString’s entire length into account. By default, the inspector treats an AnsiString as a null terminated string and thus stops displaying data when it encounters the first null character it finds, so you might need to use the inspector’s “Range” option to see everything that is actually present in the AnsiString’s memory.

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

Sidebar

Related Questions

In my application, we already have Map<String, List<String>> Now we got another use-case where
I have a map that i want to update from a separate thread. Im
I have map table public static final String key1 = newKey; public static final
I have Map<String,String> in java like this : {card_switch=Master, issuing_bank=ICCI, card_Type=DebitCard} I'm using the
So lets say I have: map<pair<int, MyEnum>, string> myMap; and I add a key
I have a map like this: private Map<String, List<List<String>>> someMap; private List<List<String>> someList1; private
I have map of groups. Each groups have list of players: Map<String, List<Player>> playerByGroup
If I have: map = { 'stack':'overflow' } try: map['experts-exchange'] except: <--- What is
I have map where each key is a String. To access a value I
Sorry. a trivial question on reference map access if I have: map<int,string> *items= new

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.