You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Changed it so it only exports fields with the attribute visible=true. You might consider implementing something more professional; I changed it out of necessity.
function TDataSetSerialize.SaveStructure: TJSONArray;
var
LField: TField;
LFields: TJSONArray;
LJSONObject: TJSONObject;
LDataSetName: string;
LNestedDataSet: TDataSet;
LDataSetDetails: TList;
LDataSetSerialize: TDataSetSerialize;
LDataSetNameNotDefinedCount: Integer;
begin
Result := TJSONArray.Create;
if FDataSet.FieldCount <= 0 then
Exit;
for LField in FDataSet.Fields do
begin
// change TRC- 2025-06-21 -----------------------------------------------------------------------
if LField.Visible then // ----- change
begin
LJSONObject := TJSONObject.Create;
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_ALIGNMENT, TJSONString.Create(GetEnumName(TypeInfo(TAlignment), Ord(LField.Alignment))));
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_FIELD_NAME, TJSONString.Create(LField.FieldName));
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_DISPLAY_LABEL, TJSONString.Create(LField.DisplayLabel));
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_DATA_TYPE, TJSONString.Create(GetEnumName(TypeInfo(TFieldType), Integer(LField.DataType))));
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_SIZE, {$IF DEFINED(FPC)}LField.Size{$ELSE}TJSONNumber.Create(LField.Size){$ENDIF});
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_ORIGIN, TJSONString.Create(LField.ORIGIN));
if IsPublishedProp(LField, 'Precision') then
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_PRECISION, {$IF DEFINED(FPC)}TFloatField(LField).Precision{$ELSE}TJSONNumber.Create(TFloatField(LField).Precision){$ENDIF});
{$IF DEFINED(FPC)}
LJSONObject.Add(FIELD_PROPERTY_KEY, pfInKey in LField.ProviderFlags);
LJSONObject.Add(FIELD_PROPERTY_REQUIRED, LField.Required);
LJSONObject.Add(FIELD_PROPERTY_VISIBLE, LField.Visible);
LJSONObject.Add(FIELD_PROPERTY_READ_ONLY, LField.ReadOnly);
{$ELSE}
{$IF COMPILERVERSION <= 29}
LJSONObject.AddPair(FIELD_PROPERTY_KEY, TJSONString.Create(BoolToStr(pfInKey in LField.ProviderFlags)));
LJSONObject.AddPair(FIELD_PROPERTY_REQUIRED, TJSONString.Create(BoolToStr(LField.Required)));
LJSONObject.AddPair(FIELD_PROPERTY_VISIBLE, TJSONString.Create(BoolToStr(LField.Visible)));
LJSONObject.AddPair(FIELD_PROPERTY_READ_ONLY, TJSONString.Create(BoolToStr(LField.ReadOnly)));
{$ELSE}
LJSONObject.AddPair(FIELD_PROPERTY_KEY, TJSONBool.Create(pfInKey in LField.ProviderFlags));
LJSONObject.AddPair(FIELD_PROPERTY_REQUIRED, TJSONBool.Create(LField.Required));
LJSONObject.AddPair(FIELD_PROPERTY_VISIBLE, TJSONBool.Create(LField.Visible));
LJSONObject.AddPair(FIELD_PROPERTY_READ_ONLY, TJSONBool.Create(LField.ReadOnly));
{$ENDIF}
{$ENDIF}
{$IF NOT DEFINED(FPC)}
LJSONObject.AddPair(FIELD_PROPERTY_AUTO_GENERATE_VALUE, TJSONString.Create(GetEnumName(TypeInfo(TAutoRefreshFlag), Integer(LField.AutoGenerateValue))));
{$ENDIF}
Result.{$IF DEFINED(FPC)}Add{$ELSE}AddElement{$ENDIF}(LJSONObject);
end;
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Changed it so it only exports fields with the attribute visible=true. You might consider implementing something more professional; I changed it out of necessity.
function TDataSetSerialize.SaveStructure: TJSONArray;
var
LField: TField;
LFields: TJSONArray;
LJSONObject: TJSONObject;
LDataSetName: string;
LNestedDataSet: TDataSet;
LDataSetDetails: TList;
LDataSetSerialize: TDataSetSerialize;
LDataSetNameNotDefinedCount: Integer;
begin
Result := TJSONArray.Create;
if FDataSet.FieldCount <= 0 then
Exit;
for LField in FDataSet.Fields do
begin
// change TRC- 2025-06-21 -----------------------------------------------------------------------
if LField.Visible then // ----- change
begin
LJSONObject := TJSONObject.Create;
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_ALIGNMENT, TJSONString.Create(GetEnumName(TypeInfo(TAlignment), Ord(LField.Alignment))));
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_FIELD_NAME, TJSONString.Create(LField.FieldName));
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_DISPLAY_LABEL, TJSONString.Create(LField.DisplayLabel));
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_DATA_TYPE, TJSONString.Create(GetEnumName(TypeInfo(TFieldType), Integer(LField.DataType))));
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_SIZE, {$IF DEFINED(FPC)}LField.Size{$ELSE}TJSONNumber.Create(LField.Size){$ENDIF});
LJSONObject.{$IF DEFINED(FPC)}Add{$ELSE}AddPair{$ENDIF}(FIELD_PROPERTY_ORIGIN, TJSONString.Create(LField.ORIGIN));
end;
All reactions