Author Topic: Inserting into TValueListEditor  (Read 244 times)


  • Hero Member
  • *****
  • Posts: 1002
Inserting into TValueListEditor
« on: August 17, 2022, 08:15:42 am »

Hi, I'm testing following codes. The rows are added or inserted on runtime.
But following method is not called when the first row is inserted.
And sIndex and tIndex are always the same, with total number of rows, even when I selected a row and insert a new row before the selected row. Are these intended, or a kind of bug?

Code: Pascal  [Select][+][-]
  1. procedure TfrUDF.ValueListEditor1ColRowInserted(Sender: TObject;
  2.   IsColumn: Boolean; sIndex, tIndex: Integer);
  3. begin
  4.    if not IsColumn then
  5.       ShowMessageFmt('sIndex=%d, tIndex=%d', [sIndex, tIndex]);
  6. end;


  • Full Member
  • ***
  • Posts: 108
Re: Inserting into TValueListEditor
« Reply #1 on: August 17, 2022, 10:02:22 am »
I can confirm this behavior. Technically, its correct. Since a TValueListEditor is based on TCustomStringGrid, which always requires at lease one row.
InsertRow() checks to see if there is an empty row available, and if so, it simply replaces the values. So, "Technically", no new row had been inserted.

I can't see this behavior being changed since it is defined in TCustomDrawGrid, so a change in behavior would effect all components derived from TCustomDrawGrid.

I'd say you have a couple of choices:  Write a utility function to add items, which would detect when a new row is added, but the RowCount doesn't change.
Code: Pascal  [Select][+][-]
  1. procedure ValueListEditorAppendRow(AValueListEditor: TValueListEditor; const AName, AValue: string);
  2. var
  3.   LRowCount: integer;
  4. begin
  5.   LRowCount := AValueListEditor.RowCount;
  6.   AValueListEditor.InsertRow(AName, AValue, True);
  7.   if Assigned(AValueListEditor.OnColRowInserted) and (LRowCount = AValueListEditor.RowCount) then begin
  8.     AValueListEditor.OnColRowInserted(AValueListEditor, False, 1, 1); // Manually trigger notification event
  9.   end;
  10. end;

A quick look at the Delphi docs, show OnColRowInserted is not supported.

Which means, there is most likely a better way to handle your requirements. Maybe: OnStringsChanging?

OnValidateEntry seems to work on first inserts.
« Last Edit: August 17, 2022, 10:08:09 am by derek.john.evans »


  • Hero Member
  • *****
  • Posts: 1002
Re: Inserting into TValueListEditor
« Reply #2 on: August 17, 2022, 06:10:44 pm »
Which means, there is most likely a better way to handle your requirements.

Well, of course there are many ways to solve my requirements. But it's a little bit annoying that I have to test every event handling behavior. Hope that there exist more content-based event handling, rather than user-action based event-handling. Of course I understand probably this is the heritage from event-driven operating systems.
« Last Edit: August 17, 2022, 06:14:15 pm by egsuh »


TinyPortal © 2005-2018