3

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.

Viktor Pagels
  • 271
  • 4
  • 15

1 Answers1

1

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;
Benoît Blanc
  • 191
  • 1
  • 6
  • My Class still has other functions that work on button presses. For example when I want to update my objects in my database. I made an update-function in my TDog-Class which saves the current property-values back into the DB. So I need at the very least a way to access the highlighted Object. – Viktor Pagels Nov 29 '16 at 08:55
  • 1
    Ok, after few searches, you have to use the InternalAdapter of your TAdapterBindSource. So on the OnClick button : procedure TForm8.Button1Click(Sender: TObject); var Adapter: TBindSourceAdapter; begin Adapter:= AdapterBindSource1.InternalAdapter; CurrentDog:= TDog(Adapter.Current); end; – Benoît Blanc Nov 29 '16 at 10:21
  • Thank you, after I get home, I will try to implement that and see if it works. – Viktor Pagels Nov 29 '16 at 11:13
  • Sorry for taking so long to respond. I had to travel to my parents very urgently soon after I posted my last comment and haven't been able to respond to anything until now. Just wanted to let you know that your solution works. Thank you. – Viktor Pagels Dec 03 '16 at 18:57