How to make livebindings with objects and pick up the objects contained?

Asked

Viewed 759 times

2

I have a problem that I cannot solve in any way. With the Delphi XE8, have already done livebindings to connect screen components TEdit with non-visual objects, but I cannot connect screen components with objects contained in other objects: Example:

TEstado = class
  FUF: string;
end;

TCidade = class
  FNome: string;
  FEstado: TEstado;
end;

In this case I can connect the name of the city with some component of the screen, but I can’t get cidade.estado.uf to show on screen.

  • When I need to edit that list? In case I have a button that updates this list with other values, which function do I call to update the visual component? Because if I just update the grid this way then I won’t update the visual component to show the data.

1 answer

1

To make your class structure available to Livebinding, use the "Datageneratoradapter" component. Create the properties of your class in it, from here you can connect your visual components to this structure.

After that, use the "Adapterbindsource" component to link your class to this structure created in the "Datageneratoradapter". Program the "Createadapter" event as follows:

procedure TForm1.AdapterBindSource2CreateAdapter(Sender: TObject;
  var ABindSourceAdapter: TBindSourceAdapter);

begin

     FLista := TObjectList<TPessoa>.Create;
     FLista.Add(TPessoa.Create('Filipe', 25, '[email protected]'));
     FLista.Add(TPessoa.Create('Cíntia', 27, '[email protected]'));
     FLista.Add(TPessoa.Create('Julio', 32, '[email protected]'));
     ABindSourceAdapter := TListBindSourceAdapter<TPessoa>.Create(Self,     FLista);

end;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.