delphilivebindings

How to extract Object of a BindSource in Delphis LiveBindings?


In Delphi 10.1 I have an ObjectList named DogCollection and each entry is of the type TDog, a custom class.

thanks to tutorials from malcolm groves I was able to populate a Stringgrid with my DogCollection.

http://www.malcolmgroves.com/blog/?p=1084

Now I'd like to be able to scroll through the stringgrid and everytime I scroll I want to update the variable "CurrentDog" from the type TDog, with whatever Object is highlighted in the stringgrid.

So I have an Overview about my DogObjects and also a single Object of my Dog which I can independently view/manipulate.

I am out of ideas at this point.

If it is of any help to you, I can also not get the AfterScroll events of the Adapter to trigger, not even when I add a Navigator with RightClick->Add Navigator.

I thank you for your help and time.


Solution

  • Not sure to understand the question but I think you don't need to have a variable "CurrentDog" to work on the selected object of your list.

    You can create all the components (TEdit) you need for your dog (Name, Age...) and bind these components to the same fields (Name, Age...) in your TDataGeneratorAdapter (which is linked to the "Adapter" property of your TAdapterBindSource).

    Then, when you select a row in your grid, the corresponding object appears in your edit components. When you modify the "Text" properties, the grid is updated.

    EDIT : InternalAdapter

    After few searches, you can get your object with the InternalAdapter of your TAdapterBindSource

    On the OnClick event :

    procedure TForm1.Button1Click(Sender: TObject);
    var
      Adapter: TBindSourceAdapter;
    begin
      Adapter:= AdapterBindSource1.InternalAdapter;
    
      CurrentDog:= TDog(Adapter.Current);
    end;