Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newbie ? - How do I get a sting's length? 1

Status
Not open for further replies.

Trope

Programmer
May 14, 2001
110
US
I have a TEdit contol named userName on my form. When a button is pressed I am brought here:

void __fastcall TForm1::btnLoginClick(TObject *Sender)
{


}
//---------------------------------------------------------

I have tried the following (after many searches Google and this forum )

// Get the length of the username
string str = userName->text;
string::size_type len; \\ What is this anyways?
len = str.length();

anyways, that was the latest. I just want to see if userName > 8 charcaters. So frustrating...

Thanks,
Trope


PS. Also, I would really appreciate a quick explanation of this FASTCALL stuff if anyone would not mind.... thanks again
 
string str = userName->text; // The string is filled
string::size_type len; // This declares a variable with the name 'len'
len = str.length(); // The 'len' is set to the length of 'str'

You could also do:
if(userName->text.length() > 8)
{
// More than 8 char's in userName->text!
}
else
{
// Less than 9 char's in userName->text!
}

__fastcall is a declaration which defines a certain way of transfering parameters by the use of registers in stead of at memory stack.

Totte
Keep making it perfect and it will end up broken.
 
I am getting this error:

'text' is not a member of TEdit

Any suggestions?

Trope

 
I changed text to Text

ok still not working, now I am getting:

unable to convert ansistring to char *

I CANNOT believe I cant figure this out.

Trope
 
Somewhere you use the ANSIstring as a c-string.

To do that you must do:
userName->Text.c_str() // now it's a null-terminated standart c-string

Totte
Keep making it perfect and it will end up broken.
 
i don't get if you are using Edit control why you wanna go through converting AnsiString to string ;)
any ways, this could be inside your login btnLoginClick

(userName is your Edit control name)

if(userName->Text.Length()>8)
{
//do whatever you want here
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top