View Issue Details

IDProjectCategoryView StatusLast Update
0003772JEDI VCL00 JVCL Componentspublic2006-06-27 01:13
Reporteribdm-cAssigned Toobones 
PrioritynormalSeverityfeatureReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.20 
Target VersionFixed in Version3.30 
Summary0003772: Different senders in TJvCustomInspectorItem.EditKeyDown and EditKeyPress
Descriptionprocedure TJvCustomInspectorItem.EditKeyPress(Sender: TObject; var Key: Char);
begin
  if Assigned(Inspector.FOnEditorKeyPress) then
    Inspector.FOnEditorKeyPress( >>> Self <<<, Key);
...


procedure TJvCustomInspectorItem.EditKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if Assigned(Inspector.FOnEditorKeyDown) then
    Inspector.FOnEditorKeyDown( >>> Inspector <<<, Key, Shift);
Additional InformationBecause the event is assigned for the Inspector component,
it seems to bo more logical, that the sender should be
"Inspector" in both cases.

I use the key press event for input validation.
Here's an example to validate a pen number:

procedure TMainform.JvInspector1EditorKeyPress( Sender: TObject; var Key: Char);
begin
  if ( (Sender is TJvInspector)
       AND (TJvInspector(Sender).Selected <> nil)
       AND (TJvInspector(Sender).Selected = FInspItem_PenNo) ) then
  begin
    //For the input of a PenNo only accept numerals and control characters.
    //You can validate the PenRange in JvInspector1ItemValueChanging
    if (Key in [' '..'/']) OR (Ord(Key) > Ord('9')) then
      Key := #0;
  end;
end; { JvInspector1EditorKeyPress }

procedure TMainform.JvInspector1ItemValueChanging( Sender: TObject;
            Item: TJvCustomInspectorItem; var NewValue: String;
            var AllowChange: Boolean);
begin
  if (Item = FInspItem_PenNo) then
  begin
    if (NOT (hPen in [FirstPen..LastPen])) then
    begin
      //>>> Don't set AllowChange to False, this won't work.
      //>>> That means if you set AllowChange to false this
      //>>> will not prevent the set of the new value
      //>>> Is this a bug or a feature ???
      //AllowChange := False;

      //Set NewValue to the old DisplayValue instead.
      NewValue := Item.DisplayValue;
    end;
  end;
end; { JvInspector1ItemValueChanging }
TagsNo tags attached.

Activities

obones

2006-06-26 05:24

administrator   ~0009643

Well, the thing is that neither of them seem logical, passing Sender would be much more logical as OnEditorKeyUp receives the TMemo or TEdit as a value for Sender.
So to me, it would be much cleaner to use "Sender" instead of Self or Inspector.
What do you think?

ibdm-c

2006-06-26 07:35

reporter   ~0009646

Yes, it seems to be more logical to use Sender, but it doesn't help you very much. I guess there's only one TMemo/TEdit inplace editor instance and there's no property in TEdit(Sender) which would tell you which row of the JvEditor you are editing right now.
Please consider, that there's only one event for all rows in your JvInspector, but each row might have different types of data (string, int, float,..). If you have to do some input validation it would be much easier to distinguish from which kind of data the event comes. Please see my comment in "Additional Information" again and try to imagine how to do this, if there are different kind of datatypes in the JvInspector. Additionally - if you inspect multiple objects at the same time the row in which the information will be diplayed in the JvInspector might change depending on the selection of objects.

obones

2006-06-26 07:47

administrator   ~0009647

Yes, I understand your request and the usage you are doing with it, but my problem comes from the fact that sometimes it would be the inspector, then sometimes the actual TEdit or TMemo. That's the "inconsistency" that I don't like. There always is the possibility to set the events to a local procedure and change the sender in this one. However, what would be the impact in termes of code changes? I do not know.

ibdm-c

2006-06-26 08:18

reporter   ~0009648

Okay, let's assume we'll use "Sender" instead of Self or Inspector.

If I have only one JvInspector than the only question is: can I really trust the
Selected property of the JvInspector? In other word: does the Selected property points to that TJvCustomInspectorItem everytimes, that I'm just editing. If so, I have no problem with "Sender", because I can check the "Selected" property.

If I would use more than one JvInspector component on my form, and I want to use the same routines for input validating, I see no way to distinguish which Inspector component has caused the event then. Admitted, this is very very special, and not in my interest, but it might be ;-)


Another solution might be not to map the event-handler routines directly, but have special event types for this with two different "Sender" properties like "KeyStrokeSender" and "Sender" or sth. similar and eventhandler routines which will be mapped for the key-events and wich will fire the new event types.

obones

2006-06-27 01:12

administrator   ~0009649

Sender is now always Inspector, even when set to the Memo or Edit. Please see in SVN for the changes.

Issue History

Date Modified Username Field Change
2006-06-21 05:02 ibdm-c New Issue
2006-06-26 05:24 obones Note Added: 0009643
2006-06-26 05:24 obones Status new => feedback
2006-06-26 07:35 ibdm-c Note Added: 0009646
2006-06-26 07:47 obones Note Added: 0009647
2006-06-26 08:18 ibdm-c Note Added: 0009648
2006-06-27 01:12 obones Status feedback => resolved
2006-06-27 01:12 obones Resolution open => fixed
2006-06-27 01:12 obones Assigned To => obones
2006-06-27 01:12 obones Note Added: 0009649