Recent

Author Topic: ValueListEditor.LoadFromCsvFile  (Read 1783 times)

kitjackson

  • Newbie
  • Posts: 1
ValueListEditor.LoadFromCsvFile
« on: June 07, 2021, 04:32:35 am »
Lazarus 2.0.12
Fpc 3.2.2

There seems to be a problem with ValueListEditor.LoadFromCsvFile.

When ValueListEditor is the first component in tab order (or the only component on the form which can take the focus) the first value in the key, value pair is lost during LoadFromCsvFile.  See project below.

The workaround is to put another component on the form which can take the focus and set the new component to have TabOrder 0 or set property TabStop to false on the ValueListEditor.

Is this a feature or a bug?

Code: Pascal  [Select][+][-]
  1. object Form1: TForm1
  2.   Left = 251
  3.   Height = 240
  4.   Top = 132
  5.   Width = 320
  6.   Caption = 'Form1'
  7.   ClientHeight = 240
  8.   ClientWidth = 320
  9.   LCLVersion = '2.0.12.0'
  10.   object SpeedButton1: TSpeedButton
  11.     Left = 57
  12.     Height = 22
  13.     Top = 29
  14.     Width = 33
  15.     Caption = 'Save'
  16.     OnClick = SpeedButton1Click
  17.   end
  18.   object SpeedButton2: TSpeedButton
  19.     Left = 154
  20.     Height = 22
  21.     Top = 26
  22.     Width = 33
  23.     Caption = 'Open'
  24.     OnClick = SpeedButton2Click
  25.   end
  26.   object ValueListEditor1: TValueListEditor
  27.     Left = 60
  28.     Height = 100
  29.     Top = 72
  30.     Width = 200
  31.     FixedCols = 0
  32.     RowCount = 4
  33.     TabOrder = 0
  34.     Strings.Strings = (
  35.       'One='
  36.       'Two='
  37.       'Three='
  38.     )
  39.     ColWidths = (
  40.       64
  41.       132
  42.     )
  43.   end
  44. end
  45.  
  46. unit Unit1;
  47.  
  48. {$mode objfpc}{$H+}
  49.  
  50. interface
  51.  
  52. uses
  53.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, Buttons, ValEdit;
  54.  
  55. type
  56.  
  57.   { TForm1 }
  58.  
  59.   TForm1 = class(TForm)
  60.     SpeedButton1: TSpeedButton;
  61.     SpeedButton2: TSpeedButton;
  62.     ValueListEditor1: TValueListEditor;
  63.     procedure SpeedButton1Click(Sender: TObject);
  64.     procedure SpeedButton2Click(Sender: TObject);
  65.   private
  66.  
  67.   public
  68.  
  69.   end;
  70.  
  71. var
  72.   Form1: TForm1;
  73.  
  74. implementation
  75.  
  76. {$R *.lfm}
  77.  
  78. { TForm1 }
  79.  
  80. procedure TForm1.SpeedButton1Click(Sender: TObject);
  81. begin
  82.   ValueListEditor1.SaveToCsvFile('test.csv');
  83. end;
  84.  
  85. procedure TForm1.SpeedButton2Click(Sender: TObject);
  86. begin
  87.   ValueListEditor1.LoadFromCsvFile('test.csv');
  88. end;
  89.  
  90. end.


[Edited to add code tags - please see How to use the Forums.]
« Last Edit: June 07, 2021, 04:42:18 am by trev »

Bart

  • Hero Member
  • *****
  • Posts: 4413
    • Bart en Mariska's Webstek
Re: ValueListEditor.LoadFromCsvFile
« Reply #1 on: June 07, 2021, 11:20:13 am »
Most likely a bug.
Another workaroud is to remove goEdit (?) form the ValuListEditor's Options property.
The problem is the fact tha an active Editor is shown, and this plays havoc with the ValueListEditor.

If you study it's code you can see multiple attempts to fix that.
Apparently not all is covered (sigh).

Please rettest with trunk before you file a bugreport.
Also, if you file a bugreport, attach a minimal test case, so strip everything away that does not have any influence on the bug in quenstion.

Bart

wp

  • Hero Member
  • *****
  • Posts: 8731
Re: ValueListEditor.LoadFromCsvFile
« Reply #2 on: June 07, 2021, 12:24:41 pm »
I think it does not make sense to have editing ON during csv import because the cell which is edited may not exist any more after the import. Therefore I added
Code: Pascal  [Select][+][-]
  1.   EditorMode := false;
immediately after the "begin" of "TCustomStringGrid.LoadFromCSVStream", and this fixed the issue for me.

P.S.
I am attaching the code of the first post in compilable form.
« Last Edit: June 07, 2021, 12:27:53 pm by wp »
Mainly Lazarus trunk / fpc 3.2.0 / all 32-bit on Win-10, but many more...

 

TinyPortal © 2005-2018