📄 jvappstorage.pas
字号:
var
Data: PTypeData;
begin
Data := GetTypeData(Instance.ClassInfo);
Result := Data^.PropCount;
end;
function TJvCustomAppStorage.GetPropName(Instance: TPersistent; Index: Integer): string;
var
PropList: PPropList;
PropInfo: PPropInfo;
Data: PTypeData;
begin
Result := '';
Data := GetTypeData(Instance.ClassInfo);
GetMem(PropList, Data^.PropCount * SizeOf(PPropInfo));
try
GetPropInfos(Instance.ClassInfo, PropList);
PropInfo := PropList^[Index];
Result := PropInfo^.Name;
finally
FreeMem(PropList, Data^.PropCount * SizeOf(PPropInfo));
end;
end;
class function TJvCustomAppStorage.GetStorageOptionsClass: TJvAppStorageOptionsClass;
begin
Result := TJvAppStorageOptions;
end;
procedure TJvCustomAppStorage.SplitKeyPath(const Path: string; out Key, ValueName: string);
var
AbsPath: string;
ValueNamePos: Integer;
begin
AbsPath := GetAbsPath(Path);
ValueNamePos := LastDelimiter(PathDelim, AbsPath);
Key := StrLeft(AbsPath, ValueNamePos - 1);
ValueName := StrRestOf(AbsPath, ValueNamePos + 1);
end;
procedure TJvCustomAppStorage.SetSubStorages(Value: TJvAppSubStorages);
begin
end;
function TJvCustomAppStorage.GetRoot: string;
begin
Result := FRoot;
end;
procedure TJvCustomAppStorage.SetRoot(const Value: string);
begin
FRoot := OptimizePaths([Value]);
end;
function TJvCustomAppStorage.GetCurrentPath: string;
begin
Result := GetAbsPath('');
end;
function TJvCustomAppStorage.GetAbsPath(const Path: string): string;
begin
Result := GetRoot + PathDelim + OptimizePaths([GetPath, Path]);
while (Result <> '') and (Result[1] = PathDelim) do
Delete(Result, 1, 1);
end;
procedure TJvCustomAppStorage.ReadStringListItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const Index: Integer; const ItemName: string);
begin
if List is TStrings then
TStrings(List).Add(Sender.ReadString(ConcatPaths([Path, ItemName + IntToStr(Index)])));
end;
procedure TJvCustomAppStorage.WriteStringListItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const Index: Integer; const ItemName: string);
begin
if List is TStrings then
Sender.WriteStringInt(ConcatPaths([Path, ItemName + IntToStr(Index)]), TStrings(List)[Index]);
end;
procedure TJvCustomAppStorage.DeleteStringListItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const First, Last: Integer; const ItemName: string);
var
I: Integer;
begin
if List is TStrings then
for I := First to Last do
Sender.DeleteValue(ConcatPaths([Path, ItemName + IntToStr(I)]));
end;
function TJvCustomAppStorage.DefaultObjectListItemCreateEvent(Sender: TJvCustomAppStorage; const Path: string; Index: Integer): TPersistent;
var
NewClassName: string;
begin
NewClassName := Sender.ReadString(ConcatPaths([Path, cClassName]));
Result := TPersistent(GetClass(NewClassName).Create);
end;
procedure TJvCustomAppStorage.ReadObjectListItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const Index: Integer; const ItemName: string);
var
NewItem: TPersistent;
NewPath: string;
begin
if List is TList then
begin
try
NewPath := ConcatPaths([Path, ItemName + IntToStr(Index)]);
NewItem := FCurrentInstanceCreateEvent(Sender, NewPath, Index);
TList(List).Add(NewItem);
Sender.ReadPersistent(NewPath, NewItem);
except
end;
end;
end;
procedure TJvCustomAppStorage.WriteObjectListItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const Index: Integer; const ItemName: string);
begin
if List is TList then
if Assigned(TList(List)[Index]) then
Sender.WritePersistent(ConcatPaths([Path, ItemName + IntToStr(Index)]), TPersistent(TList(List)[Index]));
end;
procedure TJvCustomAppStorage.DeleteObjectListItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const First, Last: Integer; const ItemName: string);
var
I: Integer;
begin
if List is TList then
for I := First to Last do
Sender.DeleteValue(ConcatPaths([Path, ItemName + IntToStr(I)]));
end;
procedure TJvCustomAppStorage.ReadStringObjectListItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const Index: Integer; const ItemName: string);
var
NewItem: TPersistent;
NewPath: string;
NewName: string;
begin
if List is TStrings then
begin
try
NewPath := ConcatPaths([Path, ItemName + IntToStr(Index)]);
NewItem := FCurrentInstanceCreateEvent(Sender, ConcatPaths([NewPath, cObject]), Index);
NewName := Sender.ReadString(ConcatPaths([NewPath, cItemName]));
TStrings(List).AddObject(NewName, NewItem);
if NewItem is TJvCustomPropertyStore then
Sender.ReadPersistent(ConcatPaths ([NewPath, cObject]), NewItem,
True, True, TJvCustomPropertyStore(NewItem).CombinedIgnoreProperties)
else
Sender.ReadPersistent(ConcatPaths([NewPath, cObject]), NewItem);
except
end;
end;
end;
procedure TJvCustomAppStorage.WriteStringObjectListItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const Index: Integer; const ItemName: string);
var
Obj: TObject;
begin
if List is TStrings then
begin
Sender.WriteString(ConcatPaths([Path, ItemName + IntToStr(Index), cItemName]), TStrings(List)[Index]);
Obj := TStrings(List).Objects[Index];
if Assigned(Obj) then
if (Obj is TJvCustomPropertyStore) then
if not TJvCustomPropertyStore(Obj).ReadOnly then
Sender.WritePersistent(ConcatPaths([Path, ItemName + IntToStr(Index), cObject]), TPersistent(Obj),
True, TJvCustomPropertyStore(Obj).CombinedIgnoreProperties)
else
else
Sender.WritePersistent(ConcatPaths([Path, ItemName + IntToStr(Index), cObject]), TPersistent(Obj));
end;
end;
procedure TJvCustomAppStorage.DeleteStringObjectListItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const First, Last: Integer; const ItemName: string);
var
I: Integer;
begin
if List is TStrings then
for I := First to Last do
Sender.DeleteValue(ConcatPaths([Path, ItemName + IntToStr(I)]));
end;
procedure TJvCustomAppStorage.ReadCollectionItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const Index: Integer; const ItemName: string);
var
NewItem: TPersistent;
NewPath: string;
begin
if List is TCollection then
begin
try
NewPath := ConcatPaths([Path, ItemName + IntToStr(Index)]);
NewItem := TCollection(List).Add;
if NewItem is TJvCustomPropertyStore then
Sender.ReadPersistent(NewPath, NewItem, True, True,
TJvCustomPropertyStore(NewItem).CombinedIgnoreProperties)
else
Sender.ReadPersistent(NewPath, NewItem);
except
end;
end;
end;
procedure TJvCustomAppStorage.WriteCollectionItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const Index: Integer; const ItemName: string);
var
Item: TObject;
begin
if List is TCollection then
begin
Item := TCollection(List).Items[Index];
if Assigned(Item) then
if Item is TJvCustomPropertyStore then
if not TJvCustomPropertyStore(Item).ReadOnly then
Sender.WritePersistent(ConcatPaths([Path, ItemName + IntToStr(Index)]), TPersistent(Item),
True, TJvCustomPropertyStore(Item).CombinedIgnoreProperties)
else
else
Sender.WritePersistent(ConcatPaths([Path, ItemName + IntToStr(Index)]), TPersistent(Item));
end;
end;
procedure TJvCustomAppStorage.DeleteCollectionItem(Sender: TJvCustomAppStorage;
const Path: string; const List: TObject; const First, Last: Integer; const ItemName: string);
var
I: Integer;
begin
if List is TCollection then
for I := First to Last do
Sender.DeleteValue(ConcatPaths([Path, ItemName + IntToStr(I)]));
end;
procedure TJvCustomAppStorage.InternalGetStoredValues(const PrefixPath, SearchPath: string;
const Strings: TStrings; const Options: TJvAppStorageEnumOptions);
var
TempList: TStrings;
I: Integer;
S: string;
PrevIdx: Integer;
begin
TempList := TStringList.Create;
try
if aeoValues in Options then
begin
EnumValues(SearchPath, TempList, aeoReportListAsValue in Options);
for I := 0 to TempList.Count - 1 do
begin
if TempList[I] = '' then
S := Copy(PrefixPath, 1, Length(PrefixPath) - 1)
else
S := PrefixPath + TempList[I];
if S <> '' then
begin
PrevIdx := Strings.IndexOf(S);
if PrevIdx > -1 then
Strings.Objects[PrevIdx] :=
TObject(Integer(Strings.Objects[PrevIdx]) or aptValue)
else
Strings.AddObject(S, TObject(aptValue));
end;
end;
end;
if (aeoFolders in Options) or (aeoRecursive in Options) then
begin
TempList.Clear;
EnumFolders(SearchPath, TempList, False);
for I := 0 to TempList.Count - 1 do
begin
if (aeoFolders in Options) and IsFolder(SearchPath + PathDelim +
TempList[I], aeoReportListAsValue in Options) then
begin
PrevIdx := Strings.IndexOf(PrefixPath + TempList[I]);
if PrevIdx > -1 then
Strings.Objects[PrevIdx] :=
TObject(Integer(Strings.Obje
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -