Re: [Lazarus] Stringgrid woes...

2009-03-14 Thread Michael Van Canneyt


On Fri, 13 Mar 2009, Jesus Reyes wrote:

  
  In Delphi, Setting 
  
EditorMode:=False;
  
  Saves the data (setedittext is called again). In Lazarus,
  it is not called. 
  
 
 I'm taking notes.

Great :-)

 
  I think it would also be a good idea to have an event which
  helps to validate the data.
  
  Something like
  
  Procedure TForm1.ValidateEntry(Sender : TObject; ACol,ARow
  : Integer; Var Value : String);
  
  begin
// Do some things, possibly modify Value or raise
  exception.
  end;
  
  Which is called only once, when the data is saved finally. 
  Currently, it's hard to do proper validation in a grid.
  Well, in my opinion of course...
 
 I thought the same and that's why I introduced grid.modified which has served 
 me very well. 
 But I agree that an event to do validation would be best, I will try to do 
 something about it.

I'll be glad to test, if  you want.

Michael.
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Stringgrid woes...

2009-03-14 Thread Michael Van Canneyt


On Sat, 14 Mar 2009, Sergei Gorelkin wrote:

 Michael Van Canneyt wrote:
  
  Not in delphi 7, I tested ?
  
  However, it is called when you set EditorMode explicitly to false. 
  But never by itself.
  
 Yep, I was wrong, details tend to become forgotten with time :( But only 
 partially.
 It is called when you finish editing by pressing Enter, or by moving 
 current cell with the keyboard, or by activating another control. It is 
 not called when you finish editing by mouse click elsewhere in the grid.

.. or click directly on the 'OK' button which is supposed to save all data in 
the
grid, which is what most of our clients seem to do... 

Michael.
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Stringgrid woes...

2009-03-13 Thread Michael Van Canneyt

Hello,

The stringgrid editor does the following:

procedure TStringCellEditor.Change;
begin
  inherited Change;
  if FGridnil then begin
FGrid.SetEditText(FCol, FRow, Text);
  end;
end;

procedure TStringCellEditor.EditingDone;
begin
  inherited EditingDone;
  if FGridnil then
FGrid.EditingDone;
end;

This makes it completely impossible to do any checking of the entered
values, because the SetEditText() event has no way of knowing when the
editing ends. In my opinion, the SetEditText() should only be called
when the editing is done, i.e. it should be like this:

procedure TStringCellEditor.Change;
begin
  inherited Change;
end;

procedure TStringCellEditor.EditingDone;
begin
  inherited EditingDone;
  if FGridnil then
begin
FGrid.SetEditText(FCol, FRow, Text);
FGrid.EditingDone;
end;
end;

Imagine a stringgrid where you want to allow only real numbers in a
cell. In that case you normally do 2 things:
- Only allow numerals and  decimal points in the OnKeyPress event
- Only save the edit text when a valid number is entered, and give 
  an error message if it is not valid.

With the current situation, this is simply impossible, because of the
following:
1. User types 1 - Settext receives 1 - all is well.
2. User types . - settext received 1. - error, because 1. is not a valid 
number.

In other words, there is no way of knowing when you have received the final
text that the user has entered. 

Is there a reason for the current behaviour, and can it be changed ?

Michael.
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Stringgrid woes...

2009-03-13 Thread Sergei Gorelkin
Michael Van Canneyt wrote:

 ...
 Is there a reason for the current behaviour, and can it be changed ?
 
With Delphi, I used to check the grid.EditorMode property in 
OnSetEditText handler, and skip all validations when EditorMode=true.
Didn't check this with LCL, but there's a good chance it works.

Regards,
Sergei
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Stringgrid woes...

2009-03-13 Thread Michael Van Canneyt


On Fri, 13 Mar 2009, Sergei Gorelkin wrote:

 Michael Van Canneyt wrote:
 
  ...
  Is there a reason for the current behaviour, and can it be changed ?
  
 With Delphi, I used to check the grid.EditorMode property in 
 OnSetEditText handler, and skip all validations when EditorMode=true.
 Didn't check this with LCL, but there's a good chance it works.

It doesn't, because Editormode is alwaus true in the OnSetEditText handler.
I tested that. Also, during testing I discovered that setting 
  EditorMode:=False;
doesn't save the value, while IMHO it should.

Apart from any workarounds around supposed bugs, calling SetText on each 
keystroke is IMHO also simply very inefficient (not to mention unnecessary)

Michael.
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Stringgrid woes...

2009-03-13 Thread Jesus Reyes




--- El vie 13-mar-09, Michael Van Canneyt michael.vancann...@wisa.be escribió:

 De:: Michael Van Canneyt michael.vancann...@wisa.be
 Asunto: [Lazarus] Stringgrid woes...
 A: Lazarus mailing list lazarus@lazarus.freepascal.org
 Fecha: viernes, 13 marzo, 2009, 10:03 am
 Hello,

[...]

 
 This makes it completely impossible to do any checking of
 the entered
 values, because the SetEditText() event has no way of
 knowing when the
 editing ends. In my opinion, the SetEditText() should only
 be called
 when the editing is done, i.e. it should be like this:
 
 procedure TStringCellEditor.Change;
 begin
   inherited Change;
 end;
 
 procedure TStringCellEditor.EditingDone;
 begin
   inherited EditingDone;
   if FGridnil then
 begin
 FGrid.SetEditText(FCol, FRow, Text);
 FGrid.EditingDone;
 end;
 end;

This suggest that there should not be distinction between grid's OnSetEditText 
and OnEditingDone so why do we need both?.

 
 Imagine a stringgrid where you want to allow only real
 numbers in a
 cell. In that case you normally do 2 things:
 - Only allow numerals and  decimal points in the OnKeyPress
 event
 - Only save the edit text when a valid number is entered,
 and give 
   an error message if it is not valid.
 
 With the current situation, this is simply impossible,
 because of the
 following:
 1. User types 1 - Settext receives 1 - all is well.
 2. User types . - settext received 1. - error,
 because 1. is not a valid number.
 
 In other words, there is no way of knowing when you have
 received the final
 text that the user has entered. 
 
 Is there a reason for the current behaviour, and can it be
 changed ?

The grid behaves that way for the same reason there is a TEdit.OnChange event, 
I'm afraid there is no way to know that final text has been entered using this 
event.

Is this different on Delphi? I would like to improve compatibility if it's not. 
If OnSetEditText is enough in Delphi to know when editing is finished then I 
think we should do it also.

Currently the assumed way to know when the final text is entered is using 
OnEditingDone no OnSetEditText, maybe this is not working but I was aware that 
OnEditingDone was triggered for several causes not necesarily only when user 
ended editing, for this reason I usually do following on OnEditingDone of grid 
cells that need validation.

  if grid.Modified then begin
[Do validation on col,row cell. Revert changes if not validated, etc]
grid.Modified := false;
  end;

this works only on StringGrid actually.

 
 Michael.


__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.yahoo.com.mx/ 

___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Stringgrid woes...

2009-03-13 Thread Sergei Gorelkin
Jesus Reyes wrote:
 
 Is this different on Delphi? I would like to improve compatibility if it's 
 not. If OnSetEditText is enough in Delphi to know when editing is finished 
 then I think we should do it also.
 
It appears to be different then. In Delphi, OnSetEditText is called 
multiple times during editing (with grid.EditorMode=True), and when the 
editing is complete, it is called once with grid.EditorMode=False.

Sergei
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Stringgrid woes...

2009-03-13 Thread Michael Van Canneyt


On Fri, 13 Mar 2009, Jesus Reyes wrote:

  This makes it completely impossible to do any checking of
  the entered
  values, because the SetEditText() event has no way of
  knowing when the
  editing ends. In my opinion, the SetEditText() should only
  be called
  when the editing is done, i.e. it should be like this:
  
  procedure TStringCellEditor.Change;
  begin
inherited Change;
  end;
  
  procedure TStringCellEditor.EditingDone;
  begin
inherited EditingDone;
if FGridnil then
  begin
  FGrid.SetEditText(FCol, FRow, Text);
  FGrid.EditingDone;
  end;
  end;
 
 This suggest that there should not be distinction between grid's 
 OnSetEditText and OnEditingDone so why do we need both?.
 
  
  Imagine a stringgrid where you want to allow only real
  numbers in a
  cell. In that case you normally do 2 things:
  - Only allow numerals and  decimal points in the OnKeyPress
  event
  - Only save the edit text when a valid number is entered,
  and give 
an error message if it is not valid.
  
  With the current situation, this is simply impossible,
  because of the
  following:
  1. User types 1 - Settext receives 1 - all is well.
  2. User types . - settext received 1. - error,
  because 1. is not a valid number.
  
  In other words, there is no way of knowing when you have
  received the final
  text that the user has entered. 
  
  Is there a reason for the current behaviour, and can it be
  changed ?
 
 The grid behaves that way for the same reason there is a TEdit.OnChange 
 event, 
 I'm afraid there is no way to know that final text has been entered using 
 this event.
 
 Is this different on Delphi? I would like to improve compatibility if it's 
 not. 
 If OnSetEditText is enough in Delphi to know when editing is finished then I 
 think we should do it also.

Hm. 
Did some checking in delphi. It behaves the same. So better leave it as it is.
Bad :(

Oh well, now I know again why I don't want to use grids for editing. 
But customers disagree, unfortunately :(

 Currently the assumed way to know when the final text is entered is using 
 OnEditingDone no OnSetEditText, 
 maybe this is not working but I was aware that OnEditingDone was triggered 
 for several causes not necesarily 
 only when user ended editing, for this reason I usually do following on 
 OnEditingDone of grid cells that need 
 validation.
 
   if grid.Modified then begin
 [Do validation on col,row cell. Revert changes if not validated, etc]
 grid.Modified := false;
   end;

The problem is that the actual data is not in the grid cells, so reverting it 
would not be that easy.
Is there a way to force the grid to save the data ? That would help, actually...

In Delphi, Setting 

  EditorMode:=False;

Saves the data (setedittext is called again). In Lazarus, it is not called. 

I think it would also be a good idea to have an event which helps to validate 
the data.

Something like

Procedure TForm1.ValidateEntry(Sender : TObject; ACol,ARow : Integer; Var Value 
: String);

begin
  // Do some things, possibly modify Value or raise exception.
end;

Which is called only once, when the data is saved finally. 
Currently, it's hard to do proper validation in a grid. Well, in my opinion of 
course...

Michael.
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Stringgrid woes...

2009-03-13 Thread Michael Van Canneyt


On Fri, 13 Mar 2009, Sergei Gorelkin wrote:

 Jesus Reyes wrote:
  
  Is this different on Delphi? I would like to improve compatibility if it's 
  not. If OnSetEditText is enough in Delphi to know when editing is finished 
  then I think we should do it also.
  
 It appears to be different then. In Delphi, OnSetEditText is called 
 multiple times during editing (with grid.EditorMode=True), and when the 
 editing is complete, it is called once with grid.EditorMode=False.

Not in delphi 7, I tested ?

However, it is called when you set EditorMode explicitly to false. 
But never by itself.

Michael.
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Stringgrid woes...

2009-03-13 Thread Jesus Reyes




--- El vie 13-mar-09, Michael Van Canneyt mich...@freepascal.org escribió:
if grid.Modified then begin
  [Do validation on col,row cell. Revert changes if
 not validated, etc]
  grid.Modified := false;
end;
 
 The problem is that the actual data is not in the grid
 cells, so reverting it would not be that easy.
 Is there a way to force the grid to save the data ? That
 would help, actually...

if grid.Modified=true when OnEditingDone triggers, then the cell has been
modified and the data is in cell (ok, that it could be any other cell which was 
modified it's true but that is a problem of program) and grid.cell[aCol,aRow] 
has the value.

the only problem is that grid.Modified needs to be reset to false manually, 
other way the grid doesn't know when the is appropiated to set modified := true.

 
 In Delphi, Setting 
 
   EditorMode:=False;
 
 Saves the data (setedittext is called again). In Lazarus,
 it is not called. 
 

I'm taking notes.

 I think it would also be a good idea to have an event which
 helps to validate the data.
 
 Something like
 
 Procedure TForm1.ValidateEntry(Sender : TObject; ACol,ARow
 : Integer; Var Value : String);
 
 begin
   // Do some things, possibly modify Value or raise
 exception.
 end;
 
 Which is called only once, when the data is saved finally. 
 Currently, it's hard to do proper validation in a grid.
 Well, in my opinion of course...

I thought the same and that's why I introduced grid.modified which has served 
me very well. But I agree that an event to do validation would be best, I will 
try to do something about it.

 
 Michael.

Jesus Reyes A.

__
Correo Yahoo!
Espacio para todos tus mensajes, antivirus y antispam ¡gratis! 
Regístrate ya - http://correo.yahoo.com.mx/ 

___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Stringgrid woes...

2009-03-13 Thread Sergei Gorelkin
Michael Van Canneyt wrote:
 
 Not in delphi 7, I tested ?
 
 However, it is called when you set EditorMode explicitly to false. 
 But never by itself.
 
Yep, I was wrong, details tend to become forgotten with time :( But only 
partially.
It is called when you finish editing by pressing Enter, or by moving 
current cell with the keyboard, or by activating another control. It is 
not called when you finish editing by mouse click elsewhere in the grid.

Sergei
___
Lazarus mailing list
Lazarus@lazarus.freepascal.org
http://www.lazarus.freepascal.org/mailman/listinfo/lazarus