Changeset 290 for trunk/UItemList.pas
- Timestamp:
- Mar 25, 2019, 12:51:41 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/UItemList.pas
r285 r290 11 11 TDataType = (dtNone, dtString, dtBoolean, dtInteger, dtFloat, dtColor, 12 12 dtTime, dtDate, dtDateTime); 13 14 { TItemField } 13 15 14 16 TItemField = class … … 19 21 Position: TPoint; 20 22 Size: TPoint; 23 procedure Assign(Source: TItemField); 21 24 end; 22 25 … … 25 28 TItemFields = class(TFPGObjectList<TItemField>) 26 29 function AddField(Index: Integer; SysName, Name: string; DataType: TDataType): TItemField; 30 function SearchByIndex(Index: Integer): TItemField; 27 31 end; 28 32 … … 37 41 Id: Integer; 38 42 Name: string; 39 function GetFields: TItemFields; virtual; 43 class function GetFields: TItemFields; virtual; 44 function GetField(Index: Integer): TItemField; 40 45 procedure GetValue(Index: Integer; out Value); virtual; 46 function GetValueInteger(Index: Integer): Integer; 47 function GetValueString(Index: Integer): string; 48 function GetValueColor(Index: Integer): TColor; 49 function GetValueBoolean(Index: Integer): Boolean; 50 function GetValueAsText(Index: Integer): string; 41 51 procedure SetValue(Index: Integer; var Value); virtual; 52 procedure SetValueInteger(Index: Integer; Value: Integer); 53 procedure SetValueString(Index: Integer; Value: string); 54 procedure SetValueColor(Index: Integer; Value: TColor); 55 procedure SetValueBoolean(Index: Integer; Value: Boolean); 42 56 procedure Assign(Source: TItem); virtual; 43 57 procedure LoadFromNode(Node: TDOMNode); virtual; 44 58 procedure SaveToNode(Node: TDOMNode); virtual; 45 59 class function GetClassSysName: string; virtual; 60 class function GetClassName: string; virtual; 46 61 end; 47 62 … … 68 83 implementation 69 84 85 resourcestring 86 SYes = 'Yes'; 87 SNo = 'No'; 88 SItem = 'Item'; 89 SName = 'Name'; 90 91 { TItemField } 92 93 procedure TItemField.Assign(Source: TItemField); 94 begin 95 SysName := Source.SysName; 96 Name := Source.Name; 97 Index := Source.Index; 98 DataType := Source.DataType; 99 Position := Source.Position; 100 Size := Source.Size; 101 end; 102 70 103 { TItemList } 71 104 … … 185 218 end; 186 219 220 function TItemFields.SearchByIndex(Index: Integer): TItemField; 221 var 222 I: Integer; 223 begin 224 I := 0; 225 while (I < Count) and (Items[I].Index <> Index) do Inc(I); 226 if I < Count then Result := Items[I] 227 else Result := nil; 228 end; 229 187 230 { TItem } 188 231 … … 192 235 ValueColor: TColor; 193 236 ValueInteger: Integer; 237 ValueBoolean: Boolean; 194 238 begin 195 239 if Field.DataType = dtString then begin … … 205 249 SetValue(Field.Index, ValueInteger); 206 250 end else 251 if Field.DataType = dtBoolean then begin 252 Source.GetValue(Field.Index, ValueBoolean); 253 SetValue(Field.Index, ValueBoolean); 254 end else 207 255 raise Exception.Create('Unsupported field value data type'); 208 256 end; … … 250 298 end; 251 299 252 function TItem.GetFields: TItemFields;300 class function TItem.GetFields: TItemFields; 253 301 begin 254 302 Result := TItemFields.Create; 255 Result.AddField(1, 'Name', 'Name', dtString); 303 Result.AddField(1, 'Name', SName, dtString); 304 end; 305 306 function TItem.GetField(Index: Integer): TItemField; 307 var 308 Fields: TItemFields; 309 begin 310 Result := TItemField.Create; 311 Fields := GetFields; 312 try 313 Result.Assign(Fields[Index]); 314 finally 315 Fields.Free; 316 end; 256 317 end; 257 318 … … 260 321 end; 261 322 323 function TItem.GetValueString(Index: Integer): string; 324 begin 325 GetValue(Index, Result); 326 end; 327 328 function TItem.GetValueInteger(Index: Integer): Integer; 329 begin 330 GetValue(Index, Result); 331 end; 332 333 function TItem.GetValueColor(Index: Integer): TColor; 334 begin 335 GetValue(Index, Result); 336 end; 337 338 function TItem.GetValueBoolean(Index: Integer): Boolean; 339 begin 340 GetValue(Index, Result); 341 end; 342 343 function TItem.GetValueAsText(Index: Integer): string; 344 var 345 Fields: TItemFields; 346 ItemField: TItemField; 347 begin 348 Fields := GetFields; 349 ItemField := GetField(Fields.IndexOf(Fields.SearchByIndex(Index))); 350 if ItemField.DataType = dtInteger then Result := IntToStr(GetValueInteger(Index)) 351 else if ItemField.DataType = dtString then Result := GetValueString(Index) 352 else if ItemField.DataType = dtColor then Result := '' 353 else if ItemField.DataType = dtBoolean then begin 354 if GetValueBoolean(Index) then Result := SYes else Result := SNo; 355 end; 356 ItemField.Free; 357 Fields.Free; 358 end; 359 262 360 procedure TItem.SetValue(Index: Integer; var Value); 263 361 begin 362 end; 363 364 procedure TItem.SetValueInteger(Index: Integer; Value: Integer); 365 begin 366 SetValue(Index, Value); 367 end; 368 369 procedure TItem.SetValueString(Index: Integer; Value: string); 370 begin 371 SetValue(Index, Value); 372 end; 373 374 procedure TItem.SetValueColor(Index: Integer; Value: TColor); 375 begin 376 SetValue(Index, Value); 377 end; 378 379 procedure TItem.SetValueBoolean(Index: Integer; Value: Boolean); 380 begin 381 SetValue(Index, Value); 264 382 end; 265 383 … … 318 436 end; 319 437 438 class function TItem.GetClassName: string; 439 begin 440 Result := SItem; 441 end; 442 320 443 end. 321 444
Note:
See TracChangeset
for help on using the changeset viewer.