Beginner Posted January 29, 2018 Share Posted January 29, 2018 Hi All How to set cookie dbgrid columns visible when user check to visible or hide some column? Example user hide some column uncheck or check and save to cookie and enter again to application columns visibles read from cookies How do it this? Thank advance Quote Link to comment Share on other sites More sharing options...
Beginner Posted January 30, 2018 Author Share Posted January 30, 2018 UP How do it ? I can't this grid state set to cookie Quote Link to comment Share on other sites More sharing options...
Sherzod Posted January 30, 2018 Share Posted January 30, 2018 Hi, Which edition and build are you using ?! Best regards, Quote Link to comment Share on other sites More sharing options...
Beginner Posted January 30, 2018 Author Share Posted January 30, 2018 Trial I found solution who interesting please chek this source If you have any best solution share here Procedure StringExplode(s: string; Delimiter: string; Var res: TStringList); Begin res.Clear; res.Text := StringReplace(s, Delimiter, #13#10, [rfIgnoreCase, rfReplaceAll]); End; procedure loadGridLayout(Mydbgrid: TUnidBGrid; fileName: string); var lines: TStringList; columnInfo: TStringList; lineCtr: integer; colIdx: integer; cnt: integer; begin try lines := TStringList.Create; columnInfo := TStringList.Create; lines.Delimiter := '^'; lines.StrictDelimiter := True; lines.DelimitedText:=fileName; for lineCtr := 0 to lines.Count-1 do begin if trim(lines[lineCtr]) <> '' then begin StringExplode(lines[lineCtr], '~ ', columnInfo); cnt:=Mydbgrid.Columns.count; for colIdx := 0 to cnt-1 do begin if Mydbgrid.Columns[colIdx].FieldName = columnInfo[1] then begin Mydbgrid.Columns[colIdx].Visible := StrToBool(columnInfo[2]); Mydbgrid.Columns[colIdx].Index := lineCtr; end; end; end; end; finally lines.free; if assigned(columnInfo) then columnInfo.free; end; end; procedure TMainForm.saveGridLayout(Mydbgrid: TUnidBGrid); var lines: TStringBuilder; i: integer; begin try lines := TStringBuilder.Create; with Mydbgrid do begin for i := 0 to Mydbgrid.Columns.count-1 do begin lines.Append(IntToStr(Mydbgrid.Columns[i].Index)); lines.Append('~ '); lines.Append(Mydbgrid.Columns[i].FieldName); lines.Append('~ '); lines.Append(BoolToStr(Mydbgrid.Columns[i].Visible)); lines.Append('^'); UniApplication.Cookies.SetCookie(Mydbgrid.Name,lines.ToString, Now+(10.0/1440.0)); end; end; finally lines.free; end; end; procedure TMainForm.UniFormClose(Sender: TObject; var Action: TCloseAction); begin saveGridLayout(UniDBGrid1); end; procedure TMainForm.UniFormCreate(Sender: TObject); begin loadGridLayout(UniDBGrid1,UniApplication.Cookies.Values[UniDBGrid1.Name]); end; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.