Ver Mensaje Individual
  #2  
Antiguo 19-03-2022
juank1971 juank1971 is offline
Miembro
 
Registrado: feb 2008
Posts: 230
Reputación: 17
juank1971 Va por buen camino
Resolvi con un codigo de un delphiano llamado jordi que me ayudo por si algien lo necesita, yo lo cambie para Tgrid, porque estaba con dbgrid, ahora funciona correcto en firemonkey. por ejemplo yo no conocia el Split, muy buena variante para quitarnos trabajo de encima.



Código Delphi [-]
  FIELD_SEP = '|'; 
  REGISTER_SEP = ';'; 



function GuardarColumnasGrid(g: TGrid): string;
var
  i: integer;
begin
  Result := '';
  for i := 0 to g.ColumnCount - 1 do
    Result := Result + g.Columns[i].Header + FIELD_SEP + g.Columns[i]
      .Width.ToString + FIELD_SEP + ifthen(g.Columns[i].Visible, 'S', 'N') +
      REGISTER_SEP;
end;


procedure CargarColumnasGrid(g: TGrid; cfg: string);
  function BuscarColumna(g: TGrid; const AFieldName: string): TColumn;
  var
    i: integer;
  begin
    Result := nil;
    for i := 0 to g.ColumnCount - 1 do
    begin
      if (g.Columns[i].Header = AFieldName) then
      begin
        Result := g.Columns[i];
        Exit;
      end;
    end;
  end;
begin
  var  reg := cfg.Split([REGISTER_SEP]);
  // se divide todo antes del ' ; '  para cada campo
  for var i := 0 to High(reg) do
  begin
    var
    cmp := reg[i].Split([FIELD_SEP]);
    // se divide todo lo separado por ' | '  nombre|tamaño | visible de cada columna
    if length(cmp) > 0 then
    begin
      var col := BuscarColumna(g, cmp[0]); 
       if Assigned(col) then
      begin
        col.Index := i;
        col.Width := StrToIntDef(cmp[1], col.Width.ToString.ToInteger);
        col.Visible := cmp[2] = 'S';
      end;
    end;
  end;
end;
Responder Con Cita