Recent

Author Topic: add picklist to tvaluelisteditor value  (Read 1312 times)

babycode

  • New Member
  • *
  • Posts: 38
add picklist to tvaluelisteditor value
« on: May 16, 2024, 09:39:24 pm »
Good afternoon, I'm loading boolean fields from my database into TValueListEditor to manipulate some system permissions. Using the code:

Code: Pascal  [Select][+][-]
  1. procedure TfrmUser.LoadPermissions;
  2. var
  3.   i: Integer;
  4. begin
  5.   vlePermissions.Strings.BeginUpdate;
  6.   try
  7.     vlePermissions.Strings.Clear;
  8.     for i := 0 to dsProfiles.DataSet.FieldCount - 1 do
  9.     begin
  10.       if dsProfiles.DataSet.Fields[i].DataType = ftBoolean then
  11.       begin
  12.         vlePermissoes.InsertRow(dsProfiles.DataSet.Fields[i].FieldName, BoolToStr(dsProfiles.DataSet.Fields[i].AsBoolean, True), True);
  13.         with vlePermissions.ItemProps[dsProfiles.DataSet.Fields[i].FieldName] do
  14.         begin
  15.           EditStyle := esPickList;
  16.           ReadOnly := True;
  17.           PickList.Add('True');
  18.           PickList.Add('False');
  19.         end;
  20.        end;
  21.     end;
  22.   finally
  23.     vlePermissions.Strings.EndUpdate;
  24.   end;
  25. end;

The compiler displays this warning

uuser.pas(1163,76) Note: Call to subroutine "operator :=(const source:ShortString):Variant;" marked as inline is not inlined

When I try to call the procedure to load the data it shows an exception and terminates.

To save the change in the bank I am using:

Code: Pascal  [Select][+][-]
  1. procedure TfrmUser.vlePermissionsSetEditText(Sender: TObject; ACol,
  2.                 ARow: Integer; const Value: string);
  3. var
  4.   Field: TField;
  5. begin
  6.   if dsProfiles.DataSet.State in [dsEdit, dsInsert] then
  7.   begin
  8.     Field := dsProfiles.DataSet.FieldByName(vlePermissions.Keys[ARow]);
  9.     if Assigned(Field) and (Field.DataType = ftBoolean) then
  10.       Field.AsBoolean := StrToBoolDef(Value, True);
  11.   end;
  12. end;
  13.  


Has anyone done something similar and can give me a solution?

dseligo

  • Hero Member
  • *****
  • Posts: 1494
Re: add picklist to tvaluelisteditor value
« Reply #1 on: May 16, 2024, 10:06:19 pm »
The compiler displays this warning

uuser.pas(1163,76) Note: Call to subroutine "operator :=(const source:ShortString):Variant;" marked as inline is not inlined

This is not a warning, it's a note, and it has nothing to do with your problem.
What exception do you get?
Can you make small complete demo (that can be compiled) that shows your problem? In case nobody picks error in snippets you posted.

babycode

  • New Member
  • *
  • Posts: 38
Re: add picklist to tvaluelisteditor value
« Reply #2 on: May 16, 2024, 10:12:33 pm »
It displays this error when calling the data loading procedure. I'm going to build a mini demo, but I'm using postgre database, so you'll need it.

babycode

  • New Member
  • *
  • Posts: 38
Re: add picklist to tvaluelisteditor value
« Reply #3 on: May 16, 2024, 10:38:27 pm »
A little demonstration of what I'm trying to do. When clicking the load button, the data from the permissions table must be loaded into the valuelisteditor, and the user can change the value of the fields. But I wanted to add a pick list so that the user could only select true or false.

jamie

  • Hero Member
  • *****
  • Posts: 6867
Re: add picklist to tvaluelisteditor value
« Reply #4 on: May 17, 2024, 12:03:23 am »
its your  xxx.Strings.BeginUpdate and xxx.Strings.EndUpdate.

You are locking your strings.

use the outer update..


MyValueListEditor.BeginUpdate;
.....

MyValueListEditor.EndUpdate.


The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 12754
Re: add picklist to tvaluelisteditor value
« Reply #5 on: May 17, 2024, 12:20:44 am »
A little demonstration of what I'm trying to do. When clicking the load button, the data from the permissions table must be loaded into the valuelisteditor, and the user can change the value of the fields. But I wanted to add a pick list so that the user could only select true or false.
Could you please rewrite the demo to use a more standard database system? I don't have a running version of PostgreSQL, and I don't want to spend the time to set it up correctly "just for a forum post". SQLite3 or even a file-based database such as TBufDataset would be perfect.

babycode

  • New Member
  • *
  • Posts: 38
Re: add picklist to tvaluelisteditor value
« Reply #6 on: May 17, 2024, 01:12:48 am »
its your  xxx.Strings.BeginUpdate and xxx.Strings.EndUpdate.

You are locking your strings.

use the outer update..


MyValueListEditor.BeginUpdate;
.....

MyValueListEditor.EndUpdate.

It worked! I can't believe it was something simple  :o. Thank you so much Jamie!  :D

babycode

  • New Member
  • *
  • Posts: 38
Re: add picklist to tvaluelisteditor value
« Reply #7 on: May 17, 2024, 01:15:09 am »
A little demonstration of what I'm trying to do. When clicking the load button, the data from the permissions table must be loaded into the valuelisteditor, and the user can change the value of the fields. But I wanted to add a pick list so that the user could only select true or false.
Could you please rewrite the demo to use a more standard database system? I don't have a running version of PostgreSQL, and I don't want to spend the time to set it up correctly "just for a forum post". SQLite3 or even a file-based database such as TBufDataset would be perfect.

Thanks for responding wp, the solution Jamie proposed solved the problem. In the next few years I will do a demo if possible with more accessible databases. ;D

 

TinyPortal © 2005-2018