You are correctly assigning the Value
parameter in the OnGetEditMask
event (assuming your regional settings use decimal comma and not decimal point), repeated here for completeness:
procedure TForm1.StringGrid1GetEditMask(Sender: TObject; ACol, ARow: Integer;
var Value: string);
begin
if (ACol = 0) or (ACol = 1) then
Value := '99,9%';
end;
Then, to convert the string content of the cell to a double
, you need to remove the percent sign from the string before you pass it to, e.g. StrToFloatDef()
:
For example:
procedure TForm1.Button1Click(Sender: TObject);
var
s: string;
d: double;
b: boolean;
begin
b := False;
s := StringGrid1.Cells[1, 1];
if s <> '' then
begin
if s[Length(s)] = '%' then
begin
s := copy(s, 1, Length(s)-1);
b := true;
end;
d := StrToFloatDef(s, 0.0);
if b then d := d / 100;
end;
ShowMessage(FloatToStr(d));
end;
begin if (ACol = 0) or (Acol=1) then Value := '99,9%' ; end;
I did it this way but it still does not work as expected – Manzini