Autor Beitrag
MeistaBene
Hält's aus hier
Beiträge: 4



BeitragVerfasst: Di 10.10.06 21:04 
Hi leutz,

habe ein großes Problem, dass ich nicht schaffe alleine zu lösen. Es ist schnell erklärt:

Ich habe ein Stringgrid mit 1-10 Zeilen und 3 - 22 Spalten in das nur Zahlen und ',' eingegeben werden soll.

Die Eingabebeschränkung an sich ist kein thema, aber wie verhindere ich das zweimal das ',' auftaucht?? muss ich jede einzelne Zelle abchecken und wenn ja wie?? Wer kann mir helfen
Marc.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1876
Erhaltene Danke: 129

Win 8.1, Xubuntu 15.10

BeitragVerfasst: Di 10.10.06 21:31 
Eine vllt. nicht sehr schöne Lösung, aber immerhin eine Lösung wäre das ganze über globale Variablen zu lösen:
Mithilfe der GlobalenVarialben prüft du, ob in der selektierten Zelle bereits ein Komma vorkommt oder nicht. ;)
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
var
  Form1: TForm1;
  x,y: integer;  
implementation

{$R *.dfm}

procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
 If key = ',' then
 If Pos(',', StringGrid1.Cells[x,y]) > 0 then
  key := #0;
end;

procedure TForm1.StringGrid1SelectCell(Sender: TObject; ACol,
  ARow: Integer; var CanSelect: Boolean);
begin
 x := ACol;
 y := ARow;
end;


Gruß,
Marc
jasocul
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 6395
Erhaltene Danke: 149

Windows 7 + Windows 10
Sydney Prof + CE
BeitragVerfasst: Mi 11.10.06 07:26 
Das geht auch ohne globale Variablen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
procedure TForm1.StringGrid1KeyPress(Sender: TObject; var Key: Char);
begin
 If key = ',' then
 If Pos(',', StringGrid1.Cells[StringGrid1.col,StringGrid1.row]) > 0 then
  key := #0;
end;