In short, in delphi I check what is written in stringgrid.cells and, if necessary, delete the characters. I do this immediately when you enter text. When editing, I first insert the text into a variable, which I later work with, and at the end I insert the removable variable into the stringgrig. The problem is that when pressed, the entire text is highlighted and when pressed again it is replaced, which is not gud. That is, after each character you have to press the arrow to the right, for example. How to make it not beat? Is it possible to somehow initialize pressing the same arrow to the right automatically?

procedure TForm1.StringGrid1SetEditText(Sender: TObject; ACol, ARow: Integer; const Value: String); var i, d:integer; s:string; begin s:=stringgrid1.cells[acol,arow]; d:=length(s); if (acol=2) and (d>0) then begin if s[d]='.' then s[d]:=','; if (ord(s[d])<48) or (ord(s[d])>57) then delete(s,d,1); stringgrid1.cells[acol,arow]:=s; end; end; 
  • 2
    Show the code. - Dex
  • @drakka, I had to edit my question. - Dex
  • and how is Value used here? s: = stringgrid1.cells [acol, arow]; // you can use the Value value. I only get if (aCol = 1) and (aRow = 1) then Value: = '00000; 1; '; - user31328
  • If you have a new question, please ask it by clicking the " Ask a Question " button. Give a link to this question if it provides the necessary context. - BOPOH

1 answer 1

And this method will not suit you, for example:

 procedure TForm1.StringGrid1GetEditMask(Sender: TObject; ACol, ARow: Integer; var Value: String); begin if ACol = 2 then Value:='!0.00;1;'; end; 

As for your method, I can't think of anything sensible, but I can tell you that instead of

 s:=stringgrid1.cells[acol,arow]; //можно использовать значение `Value`. 

Instead of

 if (ord(s[d])<48) or (ord(s[d])>57) then 

you should use

 if ((ord(s[d])<48) or (ord(s[d])>57)) and (ord(s[d])<>44) then //так как запятую тоже нужно учитывать