Recent

Author Topic: Need help getting started with TValueListEditor  (Read 25070 times)

johnson29630

  • Newbie
  • Posts: 5
Need help getting started with TValueListEditor
« on: May 11, 2013, 03:35:13 pm »
First, I'm just trying to get started with Lazarus. (trying to move from VB6)

I'm trying to display some properties.

Added a TValueListEditor to my form (it seemed like a good control for the job).

I can't figure out how to add items to the control (from within a function/routine). I've tried to dig through the documentation, but I'm still lost.

Can someone provide a simple example of:
  • Adding a Key:Value to the list
  • Reading a value after a user performs an edit


Any help would be appreciated. Is there help/examples somewhere that I'm missing?


Leledumbo

  • Hero Member
  • *****
  • Posts: 8833
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Need help getting started with TValueListEditor
« Reply #1 on: May 11, 2013, 05:36:51 pm »
Quote
Adding a Key:Value to the list
  • Setting Values property, or
  • Call InsertRow
Quote
Reading a value after a user performs an edit
You can use OnValidateEntry

johnson29630

  • Newbie
  • Posts: 5
Re: Need help getting started with TValueListEditor
« Reply #2 on: May 11, 2013, 06:46:26 pm »
I had already seen InsertRow, but apparently that's not all there is to it.

Here's what I've got:

(procedure to (re)load the list)
begin
  ValueListEditor1.clear;
  ValueListEditor1.InsertRow('thisKey','thisValue',true);
end;

After it executes, I see the value grid with a single blank line.
  • How do I set the data to display in the grid?
  • How do I read data after a user edits it? (not the event, the code that returns the data)
  • How do change the column headings? ('Key', 'Name')

Any help will be appreciated. (an example would be great!)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8833
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Need help getting started with TValueListEditor
« Reply #3 on: May 11, 2013, 07:05:39 pm »
Try this:
Code: [Select]
begin
  ValueListEditor1.clear;
  ValueListEditor1.Row := 0;
  ValueListEditor1.InsertRow('thisKey','thisValue',true);
end;
Clear doesn't automatically sets Row to 0, so even if the rows have been cleared, Row still holds its previous value (which could be anything but 0) and that causes exception because the new row position would be out of bounds. I'm using a quite recent trunk which raises exception, probably yours doesn't.
Quote
How do I read data after a user edits it?
OK, provides you know the key, use Values property.
Quote
How do change the column headings? ('Key', 'Name')
Set TitleCaptions property.

johnson29630

  • Newbie
  • Posts: 5
Re: Need help getting started with TValueListEditor
« Reply #4 on: May 11, 2013, 10:53:50 pm »
OK. I'm getting a little closer...

with:
begin
  ValueListEditor1.InsertRow('a','1',true);
  ValueListEditor1.InsertRow('b','2',true);
  ValueListEditor1.InsertRow('c','3',true);
end;                   

I get:
[Key   ][Name  ]
[a     ][1     ]
[b     ][2     ]
[c     ][3     ]


Good so far... But If I try to clear and reload with:
begin
  ValueListEditor1.clear;
  ValueListEditor1.Row := 0;
  ValueListEditor1.InsertRow('a','1',true);
  ValueListEditor1.InsertRow('b','2',true);
  ValueListEditor1.InsertRow('c','3',true);
end;                   

then I get:
[b      ][2     ]
[a      ][1     ]
[c      ][3     ]


How/why did my second InsertRow() replace the column headings? I'm missing something here.

I'm struggling to find documentation to help me with the basic use of the control. Where should I be looking for documentation?

Dick, from the internet

  • Full Member
  • ***
  • Posts: 198
Re: Need help getting started with TValueListEditor
« Reply #5 on: May 12, 2013, 05:09:54 am »
Here is one way to tackle it:
Code: [Select]
procedure TForm1.Button1Click(Sender: TObject);
begin
  VList.RowCount := 1;                          //remove all rows but title row
  VList.InsertColRow(false,1);               //InsertColRow(isColumn : boolean; Index : integer)
  VList.Rows[1].CommaText := 'a,1';     //self explanatory
  VList.InsertColRow(False,2);              //repeat as necessary
  VList.Rows[2].CommaText := 'b,2';
end;

procedure TForm1.Button2Click(Sender: TObject);
  var AName, AValue : string;
begin
  AName := VList.Keys[1];
  AValue := VList.Values[AName];
  showmessage('Row1 Key  = ' + AName +#13#10 + 'Row1 Value = ' + AValue);
end;

You didn't include your Lazarus/FPC version; I'm using 1.04/2.6; but I receive
Quote
Error: Identifier idents no member ''InsertRow''

when I use
Code: [Select]
  VList.InsertRow('a','1',true);
Hope this helps you,

  regards,
    geno

Leledumbo

  • Hero Member
  • *****
  • Posts: 8833
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Need help getting started with TValueListEditor
« Reply #6 on: May 12, 2013, 07:26:09 am »
Quote
Where should I be looking for documentation?
None ATM, this component is rather new and even a bit unstable.

Bart

  • Hero Member
  • *****
  • Posts: 5649
    • Bart en Mariska's Webstek
Re: Need help getting started with TValueListEditor
« Reply #7 on: May 12, 2013, 05:38:56 pm »
Good so far... But If I try to clear and reload with:
begin
  ValueListEditor1.clear;
  ...
end;                   

You should not do that. Use ValueListEditor1.Strings.Clear instead.

Bart

Bart

  • Hero Member
  • *****
  • Posts: 5649
    • Bart en Mariska's Webstek
Re: Need help getting started with TValueListEditor
« Reply #8 on: May 12, 2013, 05:50:47 pm »

Clear doesn't automatically sets Row to 0, so even if the rows have been cleared, Row still holds its previous value (which could be anything but 0) and that causes exception because the new row position would be out of bounds. I'm using a quite recent trunk which raises exception, probably yours doesn't.

Should be fixed in r41158.

Good so far... But If I try to clear and reload with:
begin
  ValueListEditor1.clear;
  ...
end;                   

I implemented TValueListEditor.Clear to Clear the Strings, not the entire Grid in r41158.


Bart

Bart

  • Hero Member
  • *****
  • Posts: 5649
    • Bart en Mariska's Webstek
Re: Need help getting started with TValueListEditor
« Reply #9 on: May 12, 2013, 05:52:12 pm »
Quote
Error: Identifier idents no member ''InsertRow''

when I use
Code: [Select]
  VList.InsertRow('a','1',true);

You need Trunk for that.

(You can probably also simply download the Valedit unit from trunk, put it in LCL and rebuild current Lazarus, that should go fine)

Bart
« Last Edit: May 12, 2013, 05:54:00 pm by Bart »

Dick, from the internet

  • Full Member
  • ***
  • Posts: 198
Re: Need help getting started with TValueListEditor
« Reply #10 on: May 12, 2013, 06:27:44 pm »
@ bart:
Quote
You need Trunk for that.

Yes sir, you are more than likely correct, however
Code: [Select]
  VList.InsertColRow(false,1); works fine for me, I was only giving example code  as a possible solution for OP -- if .InsertRow works, that's cool too.

  regards,
    geno

JuhaManninen

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4650
  • I like bugs.
Re: Need help getting started with TValueListEditor
« Reply #11 on: May 12, 2013, 06:42:13 pm »
Quote
Where should I be looking for documentation?
None ATM, this component is rather new and even a bit unstable.

In my understanding it is now rather good. First me and then Bart improved it a lot.
I remember most improvements were backported to the latest release, but I am not sure. Bart knows better.
In any case you can use trunk which is good most of the time.

LCL is poorly documented but you can use Delphi documentation as a fall-back.
Google search with "Delphi TValueListEditor" gives many matches.
Mostly Lazarus trunk and FPC 3.2 on Manjaro Linux 64-bit.

Bart

  • Hero Member
  • *****
  • Posts: 5649
    • Bart en Mariska's Webstek
Re: Need help getting started with TValueListEditor
« Reply #12 on: May 12, 2013, 07:56:48 pm »
@ bart:
Quote
You need Trunk for that.

Yes sir, you are more than likely correct, however
Code: [Select]
  VList.InsertColRow(false,1); works fine for me

In 1.0.8 InsertcolRow probably isn't overriden yet, so it doesn't update the Strings property.

If you want to add/inserte/delete/sort/etc, it is best to use Strings property for that.

Bart

Dick, from the internet

  • Full Member
  • ***
  • Posts: 198
Re: Need help getting started with TValueListEditor
« Reply #13 on: May 12, 2013, 09:42:23 pm »
@ bart:
Quote
You need Trunk for that.

Yes sir, you are more than likely correct, however
Code: [Select]
  VList.InsertColRow(false,1); works fine for me, I was only giving example code  as a possible solution for OP -- if .InsertRow works, that's cool too.

  regards,
    geno

Just for grins, I went ahead and installed Lazarus 1.08/FPC 2.6.2, and .InsertRow does indeed work as stated; however, my original code example still works as well.  So, 6 of one; half dozen of the other!! :D


Quote
In 1.0.8 InsertcolRow probably isn't overriden yet, so it doesn't update the Strings property.

If you want to add/inserte/delete/sort/etc, it is best to use Strings property for that.

Bart

edit:
I overlooked your last post while fiddling around with the above mentioned installation/verification;  I certainly am not arguing the point, you know better than I. 



  regards,
     geno
« Last Edit: May 12, 2013, 09:48:49 pm by geno »

 

TinyPortal © 2005-2018