V¡®u§ 849 Posted January 8, 2012 O exemplo a seguir leva um Button, um Label e 4 Edits no Form. Quando o usuário dá um clique no botão, o programa realiza algumas conversões entre AnsiString e char[] e vice-versa: //------------------------------------------------------------- #include #pragma hdrstop #include "Unit1.h" //------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { Edit1 -> Text = "String inicial de Edit1"; } //------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { char buffer[100] = "Valor inicial de buffer"; Label1 -> Caption = buffer; Edit2 -> Text = buffer[0]; // converte Text de AnsiString para char* strcpy (buffer, Edit1->Text.c_str()); Edit3 -> Text = buffer[0]; Edit4 -> Text = (String) buffer[0]+ buffer[1] + buffer[2]; } //------------------------------------------------------------- Share this post Link to post Share on other sites