Solved

TEdit out of scope

Posted on 2006-07-02
7
415 Views
Last Modified: 2013-11-17
keeping it short: this TEdit is obviously out of scope, how do i gain access to the elements in the TEdit??

/*
[C++ Error] Unit2.cpp(25): E2247 '_fastcall TControl::GetText()' is not accessible
[C++ Warning] Unit2.cpp(32): W8004 'testing' is assigned a value that is never used


*/
void __fastcall TEnterHandleForm::EnterHandleButtonClick(TObject *Sender)
{
   char Handle[100];
   Handle[0] = '\0';
   TEdit* testing;
   testing = EditHandle;
   Handle = testing->GetText();
}
0
Comment
Question by:crims
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
7 Comments
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 17026184
declare your TEdit variable in your class, which is in the .h or .hpp file. At the minute your variable is only accessilbe to this function
0
 
LVL 11

Expert Comment

by:Jase-Coder
ID: 17026199


your header file looks something like:


class YourProject : TForm
{
     public:
       // functions


     private:
       // declare your TEdit control/variable here
   
0
 
LVL 16

Expert Comment

by:George Tokas
ID: 17027342
>>testing = EditHandle;
>>   Handle = testing->GetText();???
You could use testing->Text; and because you are declaring as char[] you can use testing->Text.c_str();
I assume you have 2 forms with TEdits and you want to get the text from an editbox in one form to an editbox in another or something like...
Anyway:
The TEdit you want to read from in a form declared as "protected". So using Formx->TheEditBoxIWantToRead->Textyou can get the text inside the editbox. The Formx header HAS TO be included in the unit you will use the read function eigther is another form or a class....
If it is a class then declare a TEdit in the private area and a function to set in the public area like:
private:
  TEdit  *ClassEdit;

 void SetTEditBox(TEdit *FormEdit)
{
    ClassEdit = new TEdit(this);
    ClassEdit = FormEdit;
}
Don't forget to destroy the ClassEdit to your class destructor...
Assign the formedit from your main unit AFTER you create the instance of the class by calling the public function.

George Tokas.
0
 

Author Comment

by:crims
ID: 17028175
sorry if i am unclear... i don't have much experience in C++, maybe 8 months, really don't know much about classes.
what i am trying to do.. .is get the text from a EditBox when i push a button(lets call it button1) and store it in a variable.

//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TEnterHandleForm *EnterHandleForm;
//---------------------------------------------------------------------------
__fastcall TEnterHandleForm::TEnterHandleForm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TEnterHandleForm::Button1Click(TObject *Sender)
{
 // below is the code, the error is now telling me "Lvalue required"
/*   not sure if it matters, but when i click on the "EditBox" it takes me to the function for the edit box (so i can code it)
but if there's no code (hence i didn't code anything in the edit box) the function just dissapears.
*/
  char buffer[40];
  buffer[0] = '\0';
  buffer = EditBoxForPersonsHandle->Text.c_str();

}
0
 
LVL 11

Accepted Solution

by:
Jase-Coder earned 125 total points
ID: 17029171
you must do one of the following

strcpy(buffer, EditBoxForPersonsHandle->Text.c_str());

of declare buffer as AnsiString and then do the following:

Buffer = EditBoxForPersonsHandle->Text;
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from http://seleniumhq.org Go to that link and select download selenium in the right hand column That will then direct you to their download page. From that p…
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…
The viewer will learn how to use and create new code templates in NetBeans IDE 8.0 for Windows.

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question