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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What does := mean ?

Status
Not open for further replies.

mikeo2l

Technical User
Sep 27, 2001
20
IE
Am trying to take one character at a time from one AnsiString and put it in another with an aim of creating scrolling text.

for(i = 0; i < displaylength; i++)
{
Text1[startposition] = Text2[startposition++];

if( startposition >= Text2.Length() ) {
startingposition = 0;
return;
}
}

Form1->Label1->Caption=Text1;

I got this example from the help. but although it runs it causes a small crash.

What am I doing wrong?

Mike
 
just off the top of my head

if( startposition >= (Text2.Length() - 1))

try that. you may be going off the end of the string.

or
if( startposition > Text2.Length ())

is the exception trying to access address FFFFFFF
or something similiar.

tom cruz.net
 
The error is: ERangeError

I think the problem lies in the way I am copying AnsiString to AnsiString. Text1 and Text are AnsiStrings. I must admit I'm not sure about ansistrings... never used them before but real the help files. This line below was copied from a help file but I may have misunderstood....

Text1[startposition] = Text2[startposition++];

Mike
 
Are Text1 and Text2 AnsiStrings? If so, you need to adjust your for loop.

First, AnsiStrings start at position 1 and not 0 (zero) like regular C++ strings. This means that you also have to watch out for your ending position. AnsiStrings do not have an ending character like character arrays do.

Second, I see where i is being used in your loop but I don't see where it is being used inside the loop. Also, where is startposition being set up and changed?

Also, why do you need to copy your AnsiStrings character by character?

James P. Cottingham

There's no place like 127.0.0.1.
There's no place like 127.0.0.1.
 
You'll get ERangeError if you attempt to access an element of an AnsiString that is out of range, i.e. if the AnsiString has length 10 and you try to assign the 11th element (Text1[11]), or like 2ffat said, if you try to access the 0 element (Text1[0]).

Text1.Length needs to be equal to or greater than the index you are accessing.

Also, I can't just define a AnsiString and then begin accessing it as in
Code:
AnsiString Text1;
Text1[1] = 'A';
because Text1 has no space allocated yet for the string, this will also give a ERangeError.

There's probably a better way to do what you need, Like 2ffat said:
> why do you need to copy your AnsiStrings character by character?

Maybe describe what you're trying to do & someone can help.

Good Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top