Add "code based" data to LayoutGrid


1 comment

  • Official comment
    Roy Woll

    You can look at our PMemoryBindingDemo included with FirePower which is an example of this.  Once you have done these steps you can just drop in any FirePower control and attach it to the bind source (PrototypeBindSource1).  Basically you define your record type structure in CustomerData.pas, and then you drop in a TPrototypeBindSource (PrototypeBindSource1) to define your field definitions through its FieldDefs property. Make sure that the FieldDefs matches the type defined in customer data.pas  Finally in your OnCreateAdapter event of your prototypebindsource connect it to your data structure

    procedure TMemoryBindingForm.PrototypeBindSource1CreateAdapter(
    Sender: TObject; var ABindSourceAdapter: TBindSourceAdapter);
    begin // Connect to our CustomerList data structure
    ABindSourceAdapter :=
    CustomerList, False);

    If you want to give it some data, see the InitializeData method in the main form.

    procedure TMemoryBindingForm.InitializeData; var customer:TCustomerData; i : integer; mydate: TDateTime; //integer; begin // Initialize data for i := 0 to 1000 do begin customer := TCustomerData.Create; customer.CustNo:= 1000 + i; mydate:= StrToDateTime('1/1/1945') + Random(365*70); // 70 year range customer.StartDate:= myDate; customer.Caption := 'Caption' + inttostr(i); customer.Name := 'Name' + inttostr(i); customer.MyColor:= TwwColorComboEdit.wwColorsMap.Color[i mod (TwwColorComboEdit.wwColorsMap.Count-1)].Value; customer.TrackValue:= Random(100); customer.ProgressValue:= Random(100); CustomerList.Add(customer); end; PrototypeBindSource1.refresh; end;

    For completeness, here is the code in the unit CustomerData.pas which contains the memory structure.

    unit CustomerData;
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      Generics.Collections, Generics.Defaults,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs;
      TCustomerData = class
          FCustNo: integer;
          FCaption: String;
          FName: String;
          FStartDate: TDateTime;
          FTrackValue: integer;
          FProgressValue: integer;
          FMyColor: TAlphaColor;
          property CustNo: integer read FCustNo write FCustNo;
          property Caption: String read FCaption write FCaption;
          property Name: String read FName write FName;
          property StartDate: TDateTime read FStartDate write FStartDate;
          property TrackValue: integer read FTrackValue write FTrackValue;
          property ProgressValue: integer read FProgressValue write FProgressValue;
          property MyColor: TAlphaColor read FMyColor write FMyColor;
    var CustomerList: TObjectList<TCustomerData>;
       CustomerList := TObjectList<TCustomerData>.Create;
    Comment actions Permalink

Please sign in to leave a comment.

Powered by Zendesk