[Lazarus] Stringgrid woes...

Jesus Reyes jesusrmx at yahoo.com.mx
Fri Mar 13 19:33:37 CET 2009





--- El vie 13-mar-09, Michael Van Canneyt <michael.vancanneyt at wisa.be> escribió:

> De:: Michael Van Canneyt <michael.vancanneyt at wisa.be>
> Asunto: [Lazarus] Stringgrid woes...
> A: "Lazarus mailing list" <lazarus at 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 FGrid<>nil 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/ 




More information about the Lazarus mailing list