Board index » cppbuilder » can't display the message box that contain a varible

can't display the message box that contain a varible

Hi All

How can i use the message box to display a message that contain a varible.

something like:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  String MBox="Message Box";
  Application->MessageBox("This is a "+MBox+" Test","Test",48);

Quote
}

Please help
Thnak a lot
 

Re:can't display the message box that contain a varible


Try this:

String sMessage, sTitel;

sMessage = "Message Box";
sTitel   = "Test";
Application->MessageBox(sMessage.c_str(), sTitel.c_str(), MB_OK +
MB_ICONINFORMATION);

Jan

Quote
"Jackie" <t...@hotmail.com> wrote in message news:3d55ee87_1@dnews...
> Hi All

> How can i use the message box to display a message that contain a varible.

> something like:

> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
>   String MBox="Message Box";
>   Application->MessageBox("This is a "+MBox+" Test","Test",48);
> }

> Please help
> Thnak a lot

Re:can't display the message box that contain a varible


MessageBox() expects a char*.  AnsiString has a c_str() method for returning
a char*:

    AnsiString MBox = "Message Box";
    Application->MessageBox(("This is a " + MBox + " Test").c_str(), "Test",
48);

Gambit

Quote
"Jackie" <t...@hotmail.com> wrote in message news:3d55ee87_1@dnews...
> How can i use the message box to display a message
> that contain a varible.

> something like:

> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
>   String MBox="Message Box";
>   Application->MessageBox("This is a "+MBox+" Test","Test",48);
> }

Re:can't display the message box that contain a varible


Quote
On Sun, 11 Aug 2002 12:54:53 +0800, Jackie wrote:
>Hi All

>How can i use the message box to display a message that contain a varible.

>something like:

>void __fastcall TForm1::Button1Click(TObject *Sender)
>{
>  String MBox="Message Box";
>  Application->MessageBox("This is a "+MBox+" Test","Test",48);
>}

MessageBox() wants char* parameters.  You could accomplish what you want in
many ways.  Here are the two simplest:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    String MBox="Message Box";

    MBox="This is a "+MBox+" Test";

    Application->MessageBox(MBox.c_str(),"Test",48);

Quote
}

or

void __fastcall TForm1::Button1Click(TObject *Sender)
{
    String MBox="Message Box";
    Application->MessageBox(("This is a "+MBox+" Test").c_str(),"Test",48);

Quote
}

Keep in mind that if you add several literal strings, you'll have to convert
them to temporary Strings to add:

String foo="Test 1 "+"Test 2 "+"Test3"; // will not work

String foo="Test 1 "+String("Test 2 ")+"Test3"; // will work

This is because there's no operator for adding char* variables.  One side or
the other has to be a String.

--
 - Mike

Remove 'spambegone.net' and reverse to send e-mail.

Re:can't display the message box that contain a varible


Thank for helping

It's Working

Many Many Thanks

"Jackie" <t...@hotmail.com> ???g??l news:3d55ee87_1@dnews...

Quote
> Hi All

> How can i use the message box to display a message that contain a varible.

> something like:

> void __fastcall TForm1::Button1Click(TObject *Sender)
> {
>   String MBox="Message Box";
>   Application->MessageBox("This is a "+MBox+" Test","Test",48);
> }

> Please help
> Thnak a lot

Other Threads