Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

ShowMessage on a memory address

bilderbikkelbilderbikkel Member Posts: 754
[b][red]This message was edited by bilderbikkel at 2005-9-17 5:35:21[/red][/b][hr]
Does anyone know how to use ShowMessage on a memory address?

E.g:

TStrings * strings = RichEdit1->Lines;
ShowMessage("Address is: " + TheMagicFunction(strings) );

In which TheMagicFunction is a VCL/CLX function? Otherwise I have to solve it the way below, which is too artificial in my taste (as it only converts an address to an integer).

Or does anyone know how to convert a std::string to an AnsiString (solves the problem below)?

Thanks, bilderbikkel




#include
#include

std::string addressToString(const void* x)
{
std::ostringstream o;
if (!(o << x)) return "ERROR";
return o.str();
}

int addressToInt(const void* x)
{
const std::string myString = addressToString(x);
return atoi(myString.c_str());
}

//Under a Button or whatever
ShowMessage(addressToInt(this));


Comments

  • bilderbikkelbilderbikkel Member Posts: 754
    Got it! See also on www.CodePedia.com/1/CppBuilder !


    #include
    #include
    std::string toString(const String& ansi)
    {
    const char * myChar = ansi.c_str();
    const std::string myString = myChar;
    return myString;
    }
    //---------------------------------------------------------------------------
    String toAnsiString(const std::string& myString)
    {
    const char * myChar = myString.c_str();
    const String myAnsi = myChar;
    return myAnsi;
    }
    //---------------------------------------------------------------------------
    std::string addressToString(const void* x)
    {
    std::ostringstream o;
    if (!(o << x)) return "ERROR";
    return o.str();
    }
    //---------------------------------------------------------------------------
    int addressToInt(const void* x)
    {
    const std::string myString = addressToString(x);
    return atoi(myString.c_str());
    }
    //---------------------------------------------------------------------------
    String addressToAnsi(const void* x)
    {
    const std::string myString = addressToString(x);
    return toAnsiString(myString.c_str());
    }
    //---------------------------------------------------------------------------
    void __fastcall TForm1::Button1Click(TObject *Sender)
    {
    ShowMessage(addressToInt(this));
    ShowMessage(addressToAnsi(this));
    }
    //---------------------------------------------------------------------------



Sign In or Register to comment.