Guest User

Untitled

a guest
Jun 10th, 2018
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.40 KB | None | 0 0
  1. procedure TForm1.PopulateDataSet(Layout: TGridPanelLayout; DataSet: TFDDataSet);
  2. var
  3.   Row, Col: Integer;
  4.  
  5.   function AddColumn(Width: Integer): TGridPanelLayout.TColumnItem;
  6.   begin
  7.     Result := Layout.ColumnCollection.Add;
  8.     Result.SizeStyle := TGridPanelLayout.TSizeStyle.Absolute;
  9.     Result.Value := Width;
  10.   end;
  11.  
  12.   function AddContent(const Text: string; Bold: Boolean = False): TLabel;
  13.   begin
  14.     Result := TLabel.Create(Layout);
  15.     Result.Parent := Layout;
  16.     Result.Text := Text;
  17.     if Bold then
  18.     begin
  19.       Result.StyledSettings := Result.StyledSettings - [TStyledSetting.Style];
  20.       Result.TextSettings.Font.Style := Result.TextSettings.Font.Style + [TFontStyle.fsBold];
  21.     end;
  22.     Result.Align := TAlignLayout.Center;
  23.     Result.Margins.Top := 2;
  24.     Result.Margins.Bottom := 2;
  25.     Layout.ControlCollection.AddControl(Result, Col, Row);
  26.   end;
  27.  
  28. begin
  29.   Layout.ControlCollection.Clear;
  30.   Layout.RowCollection.Clear;
  31.   Layout.ColumnCollection.Clear;
  32.  
  33.   Layout.BeginUpdate;
  34.   try
  35.     Row := 0;
  36.  
  37.     for Col := 0 to DataSet.Table.Columns.Count - 1 do
  38.     begin
  39.       AddColumn(150);
  40.       AddContent(DataSet.Table.Columns[Col].Caption, True);
  41.     end;
  42.  
  43.     for Row := 0 to DataSet.Table.Rows.Count - 1 do
  44.       for Col := 0 to DataSet.Table.Columns.Count - 1 do
  45.         AddContent(DataSet.Table.Rows[Row].GetData(Col));
  46.   finally
  47.     Layout.EndUpdate;
  48.   end;
  49. end;
Advertisement
Add Comment
Please, Sign In to add comment