8
How to popular a Grid with a list of users using Livebindings?
Having created a type:
TPessoa = class
private
  FId: integer;
  FNome: string;
  FDataNascimento: TDate;
public
  property Id: integer read FId write FId;
  property Nome: string read FNome write FNome;
  property DataNascimento: TDate read FDataNascimento write FDataNascimento;
end;
I added some components to the form:
- Tstringgrid
- Tdatageneratoradapter
- Tadapterbindsource
- Tbindnavigator

BindingList was automatically created.
To feed Adapterbindsource I created a variable of type Tobjectbindsourceadapter in my form:
TMainForm = class(TForm)
  strgList: TStringGrid;
  DataGeneratorAdapter: TDataGeneratorAdapter;
  AdapterBindSource: TAdapterBindSource;
  bindNav: TBindNavigator;
  BindingsList: TBindingsList;
  LinkGridToDataSourceAdapterBindSource: TLinkGridToDataSource;
  procedure FormCreate(Sender: TObject);
  procedure FormClose(Sender: TObject; var Action: TCloseAction);
  procedure AdapterBindSourceCreateAdapter(Sender: TObject; 
    var ABindSourceAdapter: TBindSourceAdapter);
private
  FPessoas: TObjectBindSourceAdapter<TPessoa>;
end;
...
procedure TMainForm.AdapterBindSourceCreateAdapter(Sender: TObject; 
  var ABindSourceAdapter: TBindSourceAdapter);
begin
  ABindSourceAdapter := FPessoas;
end;
My difficulty is in popular this list.
That’s why I thought:
procedure TMainForm.FormCreate(Sender: TObject);
var
  index: integer;
  pessoa: TPessoa;
begin
  FPessoas := TObjectBindSourceAdapter<TPessoa>.Create(self);
  for index := 1 to 100 do
  begin
    FPessoas.Append;
    pessoa := TPessoa.Create;
    pessoa.Id := index;
    pessoa.Nome := 'Nome ' + index.ToString();
    pessoa.DataNascimento := StrToDate('01/01/2000') + index;
    FPessoas.SetDataObject(pessoa);
  end;
end;
Well, that doesn’t work!
How to do?
There are other ways to do this with Livebindings?
Delphi in version XE7.
http://answall.com/questions/75037/como-fazer-livebindings-com-objetos-e-pegar-os-objetos-contidos
– Ricardo da Rocha Vitor