Changeset 362 for PersistentData/Backend/UPDClientMemory.pas
- Timestamp:
- May 10, 2012, 1:18:25 PM (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
PersistentData/Backend/UPDClientMemory.pas
r361 r362 14 14 TPDClientMemory = class(TPDClient) 15 15 protected 16 FLastObjectId: Integer; 16 17 procedure InitSystemTypes; override; 17 18 function GetConnected: Boolean; override; 18 19 procedure Init; override; 20 function GetNewObjectId: Integer; 21 function SearchObject(Id: Integer): TObjectProxy; 19 22 public 20 23 Objects: TListObject; … … 35 38 end; 36 39 40 resourcestring 41 SObjectNotFound = 'Object with id %s not found'; 42 37 43 implementation 38 44 … … 54 60 end; 55 61 62 function TPDClientMemory.GetNewObjectId: Integer; 63 begin 64 Inc(FLastObjectId); 65 Result := FLastObjectId; 66 end; 67 68 function TPDClientMemory.SearchObject(Id: Integer): TObjectProxy; 69 var 70 I: Integer; 71 begin 72 I := 0; 73 while (I < Objects.Count) and 74 (TObjectProxy(Objects[I]).Id <> Id) do Inc(I); 75 if I < Objects.Count then Result := TObjectProxy(Objects[I]) 76 else Result := nil; 77 end; 78 56 79 procedure TPDClientMemory.ObjectLoad(AObject: TObjectProxy); 57 begin 58 80 var 81 Obj: TObjectProxy; 82 begin 83 if AObject.Id = 0 then raise Exception.Create(SCantLoadObjectWithoutId); 84 Obj := SearchObject(AObject.Id); 85 if Assigned(Obj) then AObject.Assign(Obj) 86 else raise Exception.CreateFmt(SObjectNotFound, [AObject.Id]); 59 87 end; 60 88 61 89 procedure TPDClientMemory.ObjectSave(AObject: TObjectProxy); 62 begin 63 90 var 91 I: Integer; 92 Obj: TObjectProxy; 93 begin 94 if AObject.Id = 0 then raise Exception.Create(SCantLoadObjectWithoutId); 95 Obj := SearchObject(AObject.Id); 96 if Assigned(Obj) then Obj.Assign(AObject) 97 else begin 98 AObject.Id := GetNewObjectId; 99 Obj := TObjectProxy(Objects.AddNew(TObjectProxy.Create)); 100 Obj.Assign(AObject); 101 end; 64 102 end; 65 103 66 104 procedure TPDClientMemory.ObjectDelete(AObject: TObjectProxy); 67 begin 68 105 var 106 Obj: TObjectProxy; 107 begin 108 Obj := SearchObject(AObject.Id); 109 if Assigned(Obj) then Objects.Delete(Objects.IndexOf(Obj)) 110 else raise Exception.CreateFmt(SObjectNotFound, [AObject.Id]) 69 111 end; 70 112 71 113 procedure TPDClientMemory.ListLoad(AList: TListProxy); 72 begin 73 114 var 115 Filter: string; 116 DbCondition: string; 117 I: Integer; 118 P: Integer; 119 NewObject: TObjectProxy; 120 Table: string; 121 begin 122 AList.Objects.Clear; 123 for I := 0 to Objects.Count - 1 do 124 with TObjectProxy(Objects[I]) do begin 125 if 1 = 1 then begin 126 NewObject := TObjectProxy.Create; 127 NewObject.Properties.Assign(Properties); 128 NewObject.Client := AList.Client; 129 NewObject.ObjectName := AList.ObjectName; 130 NewObject.Path := AList.Path; 131 AList.Objects.Add(NewObject); 132 133 if AList.ColummsFilterUse then begin 134 for P := 0 to Properties.Count - 1 do 135 if AList.ColumnsFilter.IndexOf(Properties.Keys[I]) <> -1 then 136 NewObject.Properties.Add(Properties.Keys[I], Properties[I].Value); 137 end else NewObject.Properties.Assign(Properties); 138 end; 139 end; 140 if AList.OrderUse then begin 141 142 end; 143 if AList.PageUse then begin 144 end; 74 145 end; 75 146
Note:
See TracChangeset
for help on using the changeset viewer.