Recent

Author Topic: TValueListEditor wont accept new Elements ...  (Read 450 times)

paule32

  • Sr. Member
  • ****
  • Posts: 404
TValueListEditor wont accept new Elements ...
« on: March 16, 2025, 08:13:40 pm »
Hello,
with the given (voodoo) Code, I get a key Exception.
But why ?

- I add a Elemente, and search for it...
- arow is an output variable...
- I add a showmessage, to cycle stop and halt the execution of Code to react...

The goal is it to add a category.

Code: Pascal  [Select][+][-]
  1.   with ValueListEditor1 do
  2.   begin
  3.     // Kategorie als Trennzeile hinzufügen
  4.     Strings.Add('[Persönliche Daten]');
  5.     showmessage('VooDoo');
  6.     FindRow ('[Persönliche Daten]', arow);
  7.     if arow <> -1 then
  8.     ItemProps[  '[Persönliche Daten]'].ReadOnly := True;
  9.  
  10.     // Normale Key-Value-Paare
  11.     Strings.Add('Name=Max Mustermann');
  12.     Strings.Add('Alter=30');
  13.   end;
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Bart

  • Hero Member
  • *****
  • Posts: 5560
    • Bart en Mariska's Webstek
Re: TValueListEditor wont accept new Elements ...
« Reply #1 on: March 16, 2025, 10:47:09 pm »
You must check the value of FindRow: in your case it will return False.
I adapted your code a little in my test suite for TValueListEditor:
Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button13Click(Sender: TObject);
  2. var
  3.   R: Integer;
  4.   FR: Boolean;
  5. begin
  6.   with ValEd do //it's the name of my TValueListEditor
  7.   begin
  8.     ValEd.Clean;
  9.     // Kategorie als Trennzeile hinzufügen
  10.     Strings.Add('[Persönliche Daten]');
  11.     //showmessage('VooDoo');
  12.     FR := FindRow ('[Persönliche Daten]', R);
  13.     writeln('FindRow=',FR);
  14.     if FR then writeln('R=',R);
  15.     if FR and (R <> -1) then
  16.     ItemProps[  '[Persönliche Daten]'].ReadOnly := True;
  17.  
  18.     // Normale Key-Value-Paare
  19.     Strings.Add('Name=Max Mustermann');
  20.     Strings.Add('Alter=30');
  21.   end;
  22. end;

It outputs: FindRow=FALSE.
The ValEd shows:
[Persönliche Daten]
NameMax Mustermann
Alter30

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5560
    • Bart en Mariska's Webstek
Re: TValueListEditor wont accept new Elements ...
« Reply #2 on: March 17, 2025, 11:10:34 pm »
FindRow searches for Key's.
Strings.Add('[Persönliche Daten]') will add a row with an empty Key and Value being '[Persönliche Daten]'.
You can either do
Strings.Add('[Persönliche Daten]=')  (looks a bit awkward) or use
ValueListEditor.Cells[0, Arow] := '[Persönliche Daten]'
This will set the Key to '[Persönliche Daten]' with an empty value.
After that FindRow will succeed, as will teh rest of the code (setting ReadOnly).

Bart

paule32

  • Sr. Member
  • ****
  • Posts: 404
Re: TValueListEditor wont accept new Elements ...
« Reply #3 on: March 18, 2025, 07:04:33 pm »
Hello Bart,

Thank you for the Informations.
I found a better way with TStringGrid.

If you would like, you can give me Feedback by this Project:

https://github.com/paule32/FreePascal
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

 

TinyPortal © 2005-2018