How popular is a Grid with a list of users using LiveBindings?

8

How popular is 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've added some components to the form:

  
  • TStringGrid
  •   
  • TDataGeneratorAdapter
  •   
  • TAdapterBindSource
  •   
  • TBindNavigator
  •   

    BindingListwasautomaticallycreated.

    TofeedtheAdapterBindSourceIcreatedaTObjectBindSourceAdaptertypevariableinmyform:

    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 this list is popular.
    For this 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;
    
    There are other ways to do this with LiveBindings?

    Delphi in XE7.

        
    asked by anonymous 02.03.2015 / 18:35

    1 answer

    1

    To populate the Grid with a list of objects you should use TListBindSourceAdapter and not TObjectBindSourceAdapter.

        
    18.05.2015 / 03:16