Post by Mike Collinsvoid __fastcall TForm1::StringGrid1GetEditText(TObject *Sender, int ACol,
int ARow, AnsiString &Value)
{
if (Value.Pos("&&")>0)
Value = Value.SubString(2, Value.Length()-1);
}
That code assumes that the accelerator is always at the front of the string.
But an accelerator can appear anywhere in the string. You need to take that
into account, ie:
void __fastcall TForm1::StringGrid1GetEditText(TObject *Sender, int
ACol, int ARow, AnsiString &Value)
{
int pos = Value.Pos("&&");
if( pos > 0 )
Value = Value.SubString(1, pos) + Value.SubString(pos+2,
MaxInt);
}
Or:
void __fastcall TForm1::StringGrid1GetEditText(TObject *Sender, int
ACol, int ARow, AnsiString &Value)
{
int pos = Value.Pos("&&");
if( pos > 0 )
Value.Delete(pos, 1);
}
Or:
void __fastcall TForm1::StringGrid1GetEditText(TObject *Sender, int
ACol, int ARow, AnsiString &Value)
{
Value = StringReplace(Value, "&&", "&", TReplaceFlags());
}
Post by Mike CollinsHowever, i can;t work out how you would then re-insert the
&& when the user completes their editing...
void __fastcall TForm1::StringGrid1SetEditText(TObject *Sender, int
ACol, int ARow, const AnsiString Value)
{
int pos = Value.Pos("&");
if( pos > 0 )
StringGrid1->Cells[ACol][ARow] = Value.SubString(1, pos) + "&" +
Value.SubString(pos+1, MaxInt);
}
Or:
void __fastcall TForm1::StringGrid1SetEditText(TObject *Sender, int
ACol, int ARow, const AnsiString Value)
{
int pos = Value.Pos("&");
if( pos > 0 )
{
AnsiString tmp = Value;
tmp.Insert("&", pos);
StringGrid1->Cells[ACol][ARow] = tmp;
}
}
Or:
void __fastcall TForm1::StringGrid1SetEditText(TObject *Sender, int
ACol, int ARow, const AnsiString Value)
{
StringGrid1->Cells[ACol][ARow] = StringReplace(Value, "&", "&&",
TReplaceFlags());
}
Gambit