Jump to content

Dmitriy M

  • Content Count

  • Joined

  • Last visited

Community Reputation

3 Neutral

Technical Information

  • Delphi-Version
    Delphi 10.2 Tokyo
  1. It seems like a simple factory class could solve your issue. Let it have bunch of class methods like CreateItemsFrame, CreateUsersFrame etc. Let it know about your TProjectDataType enums that will get passed to corresponding factory methods. Main form only needs to know about this factory class. If there is some actions that needs to be taken based on what type of frame is displayed on main form, then let the frames to expose some event that main form can subscribe to and trigger this event when required.
  2. It's not that difficult to modify REST.JsonReflect.pas to make it work in 10.2 (maybe prior versions too) procedure TJSONUnMarshal.PopulateFields {...} case revAttr.ReverterType of rtTypeObjects: begin Delete(FieldName, 1, 1); if (jsonFieldVal is TJSONArray) or (jsonFieldVal is TJSONNull) then begin // raise Exception.Create('NOT IMPLEMENTED'); SetField(Data, FieldName, revAttr.TypeObjectsReverter(GetArgObjects(LObjectType, TJSONArray(jsonFieldVal)))) end else raise EConversionError.Create(Format(SArrayExpectedForField, [FieldName, jsonFieldVal.ToString])); end; rtTypeStrings: {...} function JsonReflectAttribute.JSONInterceptor: TJSONInterceptor; begin // Result := FInterceptor.NewInstance as TJSONInterceptor;; Result := FInterceptor.Create as TJSONInterceptor; Result.ConverterType := FConverterType; Result.ReverterType := FReverterType; end; This works like a charm with @Uwe Raabe code from this post.
  3. This is really confusing. So the new "type" section makes compiler consider class completely defined What is an explanation of this? type TMyObjectList = TObjectList<TMyObject>; TMyObjectListInterceptor = TObjectListInterceptor<TMyObject>; type // if above "type" keyword is commented out then // [dcc32 Error]: E2086 Type 'TObjectListInterceptor<T>' is not yet completely defined TMyClass = class private [JsonReflect(ctTypeObjects, rtTypeObjects, TMyObjectListInterceptor)] FContent: TMyObjectList; end;
  4. Dmitriy M

    paste into watch list

    Another non-obvious trick is that you can drag&drop selected identifier/expression (double click to select) into the watch list.
  5. Dmitriy M

    JSON - Why self ins't updated with new values ?

    program Project1; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, REST.JSON, Unit1 in 'Unit1.pas'; var Person1, Person2: TPerson; jsonstr: string; begin Person1 := TPerson.Create; try Person1.Name := 'Hello'; jsonstr := Person1.SaveSettings; writeln(jsonstr); //write {"name":"Hello"} Person1.Name := 'hi'; Person1.LoadSettings(jsonstr); writeln(Person1.Name); //write Hello readln; finally Person1.Free; end; jsonstr := '{"name":"Stephane"}'; Person2 := TPerson.FromString(jsonstr); try writeln(Person2.Name); //write Stephane readln; finally Person2.Free; end; end. unit Unit1; interface type TPerson = class(TObject) private [JSONNameAttribute('NAME')] FName: string; public class function FromString(const aJsonString: String): TPerson; procedure LoadSettings(const aJsonString: String); function SaveSettings: string; property Name: string read FName write FName; end; implementation uses REST.JSON; class function TPerson.FromString(const aJsonString: String): TPerson; begin Result := TJSON.JsonToObject<TPerson>(aJsonString); end; procedure TPerson.LoadSettings(const aJsonString: String); var oJSON: TJSONObject; begin oJSON := TJSONObject.ParseJSONValue(aJsonString) as TJSONObject; try TJSON.JsonToObject(self, oJSON); finally oJSON.Free; end; end; function TPerson.SaveSettings: String; begin Result := TJSON.ObjectToJsonString(self); end; end. Reference
  6. Dmitriy M

    Maintaining For loop(s)

    Take a look at FireDAC Local SQL engine. You can populate FDMemTable with data stored in your TProject records and run plain SQL queries against this dataset.