Board index » cppbuilder » How to reverse the lines in a Memo ??

How to reverse the lines in a Memo ??


2003-09-15 06:49:38 AM
cppbuilder38
hi dear builders,
can someone tell me how I can reverse the lines in a Memo ??
I use the below code to insert line-numbers..
/******************************************************/
void __fastcall TfrmStringDetails::cmdLine_NumbersClick(TObject *Sender)
{
for(int i = 0; i < Memo1->Lines->Count; i++)
{
Memo1->Lines->Strings[i] = String(i + 1) + ".) " +
Memo1->Lines->Strings[i];
int LineCount = Memo1->Lines->Count;
Memo1->Lines->Strings[i] = Memo1->Lines->Strings[i] + "\r\n";
if(Memo1->Lines->Count>LineCount)
Memo1->Lines->Delete(i + 1);
}
}
/******************************************************/
now I just have to reverse the lines...(the last line should be the first
line and so on..)
Someone told me the STL has a reverse-function for that, but how can I use
it for the Memo ??
Have someone a idea ??
Oren
 
 

Re:How to reverse the lines in a Memo ??

"Oren (Halvani.de)" < XXXX@XXXXX.COM >wrote in message
Quote
void __fastcall TfrmStringDetails::cmdLine_NumbersClick(TObject *Sender)
{
for(int i = 0; i < Memo1->Lines->Count; i++)
{
Memo1->Lines->Strings[i] = String(i + 1) + ".) " +
Memo1->Lines->Strings[i];
int LineCount = Memo1->Lines->Count;
Memo1->Lines->Strings[i] = Memo1->Lines->Strings[i] + "\r\n";
if(Memo1->Lines->Count>LineCount)
Memo1->Lines->Delete(i + 1);
}
}
I can understand altering the Strings[] to insert a "#.)" string in the
beginning of each line, but what exactly are you trying to accomplish with
the rest of that code?
Quote
now I just have to reverse the lines...(the last line should be
the first line and so on..)
TStrings has an Exchange() method you can use for that:
int lineCount = Memo1->Lines->Count;
int numTimes = (lineCount / 2);
for(int x = 0; x < numTimes; ++x)
Memo1->Lines->Exchange(x, lineCount-x-1)
Gambit
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (www.grisoft.com).
Version: 6.0.515 / Virus Database: 313 - Release Date: 9/1/03
 

Re:How to reverse the lines in a Memo ??

On Mon, 15 Sep 2003 00:49:38 +0200, Oren (Halvani.de) wrote:
Quote
Someone told me the STL has a reverse-function for that, but how can I use
it for the Memo ??
You can convert the AnsiString to std::string, perform the appropriate
manipulations (check reverse() in algorithms) ?and then convert back:
std::string SS;
AnsiString AS;
SS= AS.c_str();
// do stuff
AS = SS.
--
liz
 

{smallsort}