Recent

Author Topic: [SOLVED] TStringGrid - TValueListEditor  (Read 1508 times)

egsuh

  • Hero Member
  • *****
  • Posts: 1738
[SOLVED] TStringGrid - TValueListEditor
« on: August 22, 2022, 12:46:00 pm »
I'm testing with TStringGrid and TValueListEditor.  I have a few things.

1.  with TValueListEditor, I can assign strings to it at design time. But I cannot remove them once there are a few lines. I can erase the content (texts), but cannot remove them altogether. So my program clears it during form creation.

procedure TForm1.FormCreate(Sender: TObject);
begin
   ValueListEditor1.Clear;
end;



2.  My form has three components on it --- TListview, TStringGrid and TValueListEditor.  I'd like to implement a form that can edit objects linked to each row of them (in the way of TStrings.AddObject). When any row is selected, the object linked to it should be editable. But before loading new object, previous object must be saved (if anything is opened). So I must be able to detect focus-losing row and getting-focused row. Attached sample project is to test this.


1)  Memo1.Lines.add... itself works fine. But when I change these to "ShowMessage", the selection process itself is very strange. In TStringGrid, multiple lines are selected, and just hovering over TValueListEditor calls selection.


2) with TListView, the methods are called in order. First calling deselected row and then selected row.

3) with TStringList,  meanings of BeforeSelection and AfterSelection seem exchanged. When selection moves from row1 to row3, events are called in the order of   Row 3 before selection --> Row 1 after selection.  They should be called Row 1 Before Selection --> Row 3 After Selection to keep consistency with TListView or TTreeView.

4) With TValueListEditor, 

   a. When there are only one item, clicking the value column does not call any event.
   b. But when key colums is clicked, events are called.
   c. both BeforeSelection and OnSelection gives the same row. I cannot do anything on focus-losing item.

« Last Edit: August 22, 2022, 03:10:40 pm by egsuh »

egsuh

  • Hero Member
  • *****
  • Posts: 1738
Re: TStringGrid - TValueListEditor
« Reply #1 on: August 22, 2022, 01:25:40 pm »
I can identify focus-losing row using ValueListEditor1.Row, instead of aRow, a parameter of the event handling procedure.


procedure TForm1.ValueListEditor1BeforeSelection(Sender: TObject; aCol,
  aRow: Integer);
begin
   Memo1.Lines.Add(Format('VLE - aRow %d VLE.Row %d Beforeselection', [aRow, ValueListEditor1.Row]));
   // here, aRow and ValueListEditor1.Row are different.
end;

procedure TForm1.ValueListEditor1Selection(Sender: TObject; aCol, aRow: Integer
  );
begin
   Memo1.Lines.Add(Format('VLE - aRow %d VLE.Row %d Onselection', [aRow, ValueListEditor1.Row]));
   // here,  aRow and ValueListEditor1.Row are the same.

end;

dje

  • Full Member
  • ***
  • Posts: 134
Re: TStringGrid - TValueListEditor
« Reply #2 on: August 22, 2022, 01:33:54 pm »
I'm not sure what your question is?

PascalDragon

  • Hero Member
  • *****
  • Posts: 6321
  • Compiler Developer
Re: TStringGrid - TValueListEditor
« Reply #3 on: August 22, 2022, 01:52:06 pm »
procedure TForm1.ValueListEditor1Selection(Sender: TObject; aCol, aRow: Integer
  );
begin
   Memo1.Lines.Add(Format('VLE - aRow %d VLE.Row %d Onselection', [aRow, ValueListEditor1.Row]));
   // here,  aRow and ValueListEditor1.Row are the same.

end;


As a Hero-Member you should know by now that you should use code-tags. Thank you.

Bart

  • Hero Member
  • *****
  • Posts: 5677
    • Bart en Mariska's Webstek
Re: TStringGrid - TValueListEditor
« Reply #4 on: August 22, 2022, 02:20:56 pm »
Code: Pascal  [Select][+][-]
  1. procedure TForm1.ValueListEditor1BeforeSelection(Sender: TObject; aCol,
  2.   aRow: Integer);
  3. begin
  4.    Memo1.Lines.Add(Format('VLE - aRow %d VLE.Row %d Beforeselection', [aRow, ValueListEditor1.Row]));
  5.    // here, aRow and ValueListEditor1.Row are different.
  6. end;

AFAIK this is directly inherited from it's ancestor...

Bart

egsuh

  • Hero Member
  • *****
  • Posts: 1738
Re: TStringGrid - TValueListEditor
« Reply #5 on: August 22, 2022, 03:10:13 pm »
Quote
I'm not sure what your question is?

I'm trying to say some inconsistencies or problems in programming, because of the order of occurrences of events.

Quote
As a Hero-Member you should know by now that you should use code-tags.

Yes, I know that and do that in most cases. In this case I used Tt-tags instead of Code-tags, because volume of codes is small and codes themselves are not really important.

Quote
AFAIK this is directly inherited from it's ancestor...

With further testing, I found OnBeforeSelection and OnSelection events are handled in the same way both in TStringGrid and (its descendant) TValueListEditor. In OnAfterSelection of TStringGrid, parameter aRow gives focus-losing index and TStringGrid.Riow is new index.


Now I am able to control internal objects linked to each row of TStringGrid or TValueListEditor, using these values, except for the first row of TValueListEditor. OnSelection is not called if I click the row first time (when there are no focus-losing row). If I click the first row while another row has been selected, OnSelection is called (it seems the first row is in the state of selected if users do nothing).

I can handle this problem, but it is against intuition anyway. I'd like to add explanations on these to Wiki so that others can refer, if others don't disagree.

egsuh

  • Hero Member
  • *****
  • Posts: 1738
Re: [SOLVED] TStringGrid - TValueListEditor
« Reply #6 on: August 23, 2022, 05:07:27 am »
Quote
with TValueListEditor, I can assign strings to it at design time. But I cannot remove them once there are a few lines. I can erase the content (texts), but cannot remove them altogether.

I could remove the lines by setting Rowcount=2.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6321
  • Compiler Developer
Re: TStringGrid - TValueListEditor
« Reply #7 on: August 23, 2022, 09:16:42 am »
Quote
As a Hero-Member you should know by now that you should use code-tags.

Yes, I know that and do that in most cases. In this case I used Tt-tags instead of Code-tags, because volume of codes is small and codes themselves are not really important.

That is not the point. The forum software might interpret whatever you wrote there, it won't do so with Code-tags (now or in future versions). Also even small volumes of code that aren't single expressions or statements are much easier to read in Code-tags than in TT-tags.

wp

  • Hero Member
  • *****
  • Posts: 13353
Re: TStringGrid - TValueListEditor
« Reply #8 on: August 23, 2022, 11:06:17 am »
Quote
As a Hero-Member you should know by now that you should use code-tags.

Yes, I know that and do that in most cases. In this case I used Tt-tags instead of Code-tags, because volume of codes is small and codes themselves are not really important.

That is not the point. The forum software might interpret whatever you wrote there, it won't do so with Code-tags (now or in future versions). Also even small volumes of code that aren't single expressions or statements are much easier to read in Code-tags than in TT-tags.
I agree. Having a '[ i ]' (without the spaces) inside [ tt ] tags does not prevent the forum software from printing the following text in italic and makes the '[ i ]' disappear; [ code tags ] handle this correctly:

for i := 1 to Length(s) do
begin
  s := 'x';
end;

Code: Pascal  [Select][+][-]
  1. for i := 1 to Length(s) do
  2. begin
  3.   s[i] := 'x';
  4. end;

egsuh

  • Hero Member
  • *****
  • Posts: 1738
Re: [SOLVED] TStringGrid - TValueListEditor
« Reply #9 on: August 23, 2022, 11:36:38 am »
Quote
That is not the point. The forum software might interpret whatever you wrote there, it won't do so with Code-tags (now or in future versions). Also even small volumes of code that aren't single expressions or statements are much easier to read in Code-tags than in TT-tags.

OK, I'll use Code tags for almost all codes.

 

TinyPortal © 2005-2018