<div dir="ltr"><div>On 7 April 2016 at 20:06, Luiz Americo Pereira Camara <span dir="ltr"><<a href="mailto:luizamericop@gmail.com" target="_blank">luizamericop@gmail.com</a>></span> wrote:<br>> Any chance sharing the code or at least the syntax?</div><div class="gmail_extra"><br></div><div class="gmail_extra">(I realise I'm hijacking your conversation with Michael - apologies for that, but this interests me)</div><div class="gmail_extra"><br></div><div class="gmail_extra">My code to initialise the grid (which hides all _ID columns)</div><div class="gmail_extra"><br></div><div class="gmail_extra">Procedure InitialiseDBGrid(oGrid: TDBGrid; oDataset: TDataset; bHideIDs: Boolean = False);</div><div class="gmail_extra"><div class="gmail_extra"><...></div><div class="gmail_extra">Begin</div><div class="gmail_extra"> If not oDataset.Active Then</div><div class="gmail_extra">  Exit;</div><div class="gmail_extra"><br></div><div class="gmail_extra"> oDataset.DisableControls;</div><div class="gmail_extra"> Try</div><div class="gmail_extra">  <...></div><div class="gmail_extra">  oDataset.First;<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">  For iTemp := oGrid.Columns.Count - 1 Downto 0 Do<br></div><div class="gmail_extra">  Begin</div><div class="gmail_extra">   oColumn := oGrid.Columns[iTemp];</div><div class="gmail_extra">   oField := oColumn.Field;</div><div class="gmail_extra"><br></div><div class="gmail_extra">   <...></div><div class="gmail_extra">   // Hide the ID columns if so requested<br></div><div class="gmail_extra">   If (bHideIDs) And (Copy(oField.FieldName, Length(oField.FieldName) - 1, 2) =</div><div class="gmail_extra">    'ID') Then</div><div class="gmail_extra">   Begin</div><div class="gmail_extra">    oColumn.Visible := False;</div><div class="gmail_extra">    oField.Visible := False;</div><div class="gmail_extra">   End;</div><div class="gmail_extra">   <...></div><div class="gmail_extra">  End;<br></div><div class="gmail_extra">  <...></div><div class="gmail_extra">  oDataset.First;<br></div><div class="gmail_extra"> Finally</div><div class="gmail_extra">  oDataset.EnableControls;</div><div class="gmail_extra"> End;</div><div class="gmail_extra">End;</div><div class="gmail_extra"><br></div><div class="gmail_extra">Without getting into my architecture too deeply, I have code that hooks into the Master dataset OnAfterScroll, and the Macro's for each Detail data are handled simply by the follow sort of code...</div><div class="gmail_extra"><div class="gmail_extra"><br></div><div class="gmail_extra">Function TfrmSQLExplorer.ReplaceCommonMacros(sSQL: String): String;</div><div class="gmail_extra">Begin</div><div class="gmail_extra"> Result := sSQL;</div><div class="gmail_extra"><br></div><div class="gmail_extra"> Result := FindReplace(Result, ':UserDate', FormatDateTime('yyyy-mm-dd', dtUserDate.Date));</div><div class="gmail_extra"><br></div><div class="gmail_extra"> Result := FindReplace(Result, ':Time', FormatDateTime('HH:mm:ss', Now));</div><div class="gmail_extra"> Result := FindReplace(Result, ':Date', FormatDateTime('yyyy-mm-dd', Now));</div><div class="gmail_extra"><br></div><div class="gmail_extra"> Result := FindReplace(Result, ':Database', FClient.DatabaseName);</div><div class="gmail_extra"> Result := FindReplace(Result, ':Repository', FClient.DatabaseName + '_Rep');</div><div class="gmail_extra"><br></div><div class="gmail_extra"> Result := FFilters.ReplaceMacros(Result);</div><div class="gmail_extra">End;</div></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">(FFilters is essentially a list of frames that each contain a DBlookupCombo)</div><div class="gmail_extra"><br></div><div class="gmail_extra">and</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">Function TdckMacros.ReplaceCommonMacros(oExclude: TDataset; sSQL: String): String;</div><div class="gmail_extra">Var</div><div class="gmail_extra"> i: Integer;</div><div class="gmail_extra"> iField: Integer;</div><div class="gmail_extra"> oField: TField;</div><div class="gmail_extra"> oDataset: TDataset;</div><div class="gmail_extra"> sReplace: String;</div><div class="gmail_extra">Begin</div><div class="gmail_extra"> Result := sSQL;</div><div class="gmail_extra"><br></div><div class="gmail_extra"> For i := 0 To FDatasets.Count - 1 Do</div><div class="gmail_extra"> Begin</div><div class="gmail_extra">  oDataset := Dataset[i];</div><div class="gmail_extra">  If (oDataset <> oExclude) Then</div><div class="gmail_extra">   For iField := 0 To oDataset.Fields.Count - 1 Do</div><div class="gmail_extra">   Begin</div><div class="gmail_extra">    oField := oDataset.Fields[iField];</div><div class="gmail_extra">    sReplace := oField.AsString;</div><div class="gmail_extra"><br></div><div class="gmail_extra">    If (oField.DataType = ftInteger) And (sReplace = '') Then</div><div class="gmail_extra">     Result := FindReplace(Result, ':' + oField.FieldName, '-99999')</div><div class="gmail_extra">    Else</div><div class="gmail_extra">     Result := FindReplace(Result, ':' + oField.FieldName, sReplace);</div><div class="gmail_extra">   End;</div><div class="gmail_extra"> End;</div><div class="gmail_extra">End;</div></div><div class="gmail_extra"><br></div><div class="gmail_extra">You don't need to follow my architecture (I hope ;-) ), just the concept of cycling through a dataset, treating all columns as potential Macros for replacement. Sure, there's issues in the above code that are on my TODO, but have been there for a while, but as I construct all the SQLs used by this code, I've got used to working around those issues :-)</div><div class="gmail_extra"><br></div><div class="gmail_extra">Mike</div></div>