📄 jvqpropertystore.pas
字号:
{******************************************************************************}
{* WARNING: JEDI VCL To CLX Converter generated unit. *}
{* Manual modifications will be lost on next release. *}
{******************************************************************************}
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html
Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.
The Original Code is: JvPropertyStore.pas, released on 2003-11-13.
The Initial Developer of the Original Code is Jens Fudickar
Portions created by Marcel Bestebroer are Copyright (C) 2003 Jens Fudickar
All Rights Reserved.
Contributor(s):
Marcel Bestebroer
You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net
Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvQPropertyStore.pas,v 1.21 2005/02/06 14:06:16 asnepvangers Exp $
unit JvQPropertyStore;
{$I jvcl.inc}
interface
uses
Classes,
JvQAppStorage, JvQComponent;
type
TJvIgnorePropertiesStringList = class(TStringList)
public
procedure AddDelete(AItem: string; ADelete: Boolean);
end;
TJvCustomPropertyStore = class(TJvComponent)
private
FAppStoragePath: string;
FAppStorage: TJvCustomAppStorage;
FEnabled: Boolean;
FReadOnly: Boolean;
FDeleteBeforeStore: Boolean;
FClearBeforeLoad: Boolean;
FIntIgnoreProperties: TStringList;
FIgnoreProperties: TJvIgnorePropertiesStringList;
FAutoLoad: Boolean;
FLastLoadTime: TDateTime;
FIgnoreLastLoadTime: Boolean;
FCombinedIgnoreProperties: TStringList;
FOnBeforeLoadProperties: TNotifyEvent;
FOnAfterLoadProperties: TNotifyEvent;
FOnBeforeStoreProperties: TNotifyEvent;
FOnAfterStoreProperties: TNotifyEvent;
procedure SetAutoLoad(Value: Boolean);
function GetIgnoreProperties: TJvIgnorePropertiesStringList;
procedure SetIgnoreProperties(Value: TJvIgnorePropertiesStringList);
function GetPropCount(Instance: TPersistent): Integer;
function GetPropName(Instance: TPersistent; Index: Integer): string;
procedure CloneClass(Src, Dest: TPersistent);
function GetLastSaveTime: TDateTime;
protected
procedure UpdateChildPaths(OldPath: string = ''); virtual;
procedure SetPath(Value: string); virtual;
procedure SetAppStorage(Value: TJvCustomAppStorage);
procedure Loaded; override;
procedure DisableAutoLoadDown;
procedure LoadData; virtual;
procedure StoreData; virtual;
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
function GetCombinedIgnoreProperties: TStringList;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure StoreProperties; virtual;
procedure LoadProperties; virtual;
procedure Assign(Source: TPersistent); override;
procedure Clear; virtual;
function TranslatePropertyName(AName: string): string; virtual;
property AppStorage: TJvCustomAppStorage read FAppStorage write SetAppStorage;
property CombinedIgnoreProperties: TStringList read GetCombinedIgnoreProperties;
property IgnoreProperties: TJvIgnorePropertiesStringList read GetIgnoreProperties write SetIgnoreProperties;
property AutoLoad: Boolean read FAutoLoad write SetAutoLoad;
property AppStoragePath: string read FAppStoragePath write SetPath;
property Enabled: Boolean read FEnabled write FEnabled default True;
property ReadOnly: Boolean read FReadOnly write FReadOnly default False;
property DeleteBeforeStore: Boolean read FDeleteBeforeStore write FDeleteBeforeStore default False;
property ClearBeforeLoad: Boolean read FClearBeforeLoad write FClearBeforeLoad default False;
property IgnoreLastLoadTime: Boolean read FIgnoreLastLoadTime write FIgnoreLastLoadTime default False;
property OnBeforeLoadProperties: TNotifyEvent read FOnBeforeLoadProperties write FOnBeforeLoadProperties;
property OnAfterLoadProperties: TNotifyEvent read FOnAfterLoadProperties write FOnAfterLoadProperties;
property OnBeforeStoreProperties: TNotifyEvent read FOnBeforeStoreProperties write FOnBeforeStoreProperties;
property OnAfterStoreProperties: TNotifyEvent read FOnAfterStoreProperties write FOnAfterStoreProperties;
property Tag;
end;
TJvCustomPropertyListStore = class(TJvCustomPropertyStore)
private
FItems: TStringList;
FFreeObjects: Boolean;
FCreateListEntries: Boolean;
FItemName: string;
function GetItems: TStringList;
protected
function GetString(Index: Integer): string;
function GetObject(Index: Integer): TObject;
procedure SetString(Index: Integer; Value: string);
procedure SetObject(Index: Integer; Value: TObject);
function GetCount: Integer;
procedure ReadSLOItem(Sender: TJvCustomAppStorage; const Path: string;
const List: TObject;const Index: Integer; const ItemName: string);
procedure WriteSLOItem(Sender: TJvCustomAppStorage; const Path: string;
const List: TObject; const Index: Integer; const ItemName: string);
procedure DeleteSLOItems(Sender: TJvCustomAppStorage; const Path: string;
const List: TObject; const First, Last: Integer; const ItemName: string);
function CreateItemList: TStringList; virtual;
function CreateObject: TObject; virtual;
function GetSorted: Boolean;
procedure SetSorted(Value: Boolean);
function GetDuplicates: TDuplicates;
procedure SetDuplicates(Value: TDuplicates);
procedure StoreData; override;
procedure LoadData; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Clear; override;
property Strings[Index: Integer]: string read GetString write SetString;
property Objects[Index: Integer]: TObject read GetObject write SetObject;
property Items: TStringList read GetItems;
property Count: Integer read GetCount;
{ Defines if the Items.Objects- Objects will be freed inside the clear procedure }
property FreeObjects: Boolean read FFreeObjects write FFreeObjects default True;
{ Defines if new List entries will be created if there are stored entries, which
are not in the current object }
property CreateListEntries: Boolean read FCreateListEntries write FCreateListEntries default True;
property ItemName: string read FItemName write FItemName;
property Sorted: Boolean read GetSorted write SetSorted;
end;
implementation
uses
{$IFDEF UNITVERSIONING}
JclUnitVersioning,
{$ENDIF UNITVERSIONING}
{$IFDEF HAS_UNIT_RTLCONSTS}
RTLConsts,
{$ENDIF HAS_UNIT_RTLCONSTS}
QConsts, SysUtils, TypInfo;
const
cLastSaveTime = 'Last Save Time';
cObject = 'Object';
cItem = 'Item';
//=== { TCombinedStrings } ===================================================
type
// Read-only TStrings combining multiple TStrings instances in a single list
TCombinedStrings = class(TStringList)
private
FList: TList;
protected
function Get(Index: Integer): string; override;
function GetObject(Index: Integer): TObject; override;
function GetCount: Integer; override;
public
constructor Create;
destructor Destroy; override;
procedure AddStrings(Strings: TStrings); override;
// procedure DeleteStrings(Strings: TStrings);
procedure Clear; override;
procedure Delete(Index: Integer); override;
procedure Insert(Index: Integer; const S: string); override;
end;
constructor TCombinedStrings.Create;
begin
inherited Create;
FList := TList.Create;
end;
destructor TCombinedStrings.Destroy;
begin
FreeAndNil(FList);
inherited Destroy;
end;
function TCombinedStrings.Get(Index: Integer): string;
var
OrgIndex: Integer;
I: Integer;
begin
OrgIndex := Index;
I := 0;
if Index < 0 then
Error(SListIndexError, Index);
while (I < FList.Count) and (Index >= TStrings(FList[I]).Count) do
begin
Dec(Index, TStrings(FList[I]).Count);
Inc(I);
end;
if I >= FList.Count then
Error(SListIndexError, OrgIndex);
Result := TStrings(FList[I])[Index];
end;
function TCombinedStrings.GetObject(Index: Integer): TObject;
var
OrgIndex: Integer;
I: Integer;
begin
OrgIndex := Index;
I := 0;
if Index < 0 then
Error(SListIndexError, Index);
while (Index < TStrings(FList[I]).Count) and (I < FList.Count) do
begin
Dec(Index, TStrings(FList[I]).Count);
Inc(I);
end;
if I >= FList.Count then
Error(SListIndexError, OrgIndex);
Result := TStrings(FList[I]).Objects[Index];
end;
function TCombinedStrings.GetCount: Integer;
var
I: Integer;
begin
Result := 0;
for I := 0 to FList.Count - 1 do
Inc(Result, TStrings(FList[I]).Count);
end;
procedure TCombinedStrings.AddStrings(Strings: TStrings);
begin
if FList.IndexOf(Strings) = -1 then
FList.Add(Strings);
end;
(*
procedure TCombinedStrings.DeleteStrings(Strings: TStrings);
begin
FList.Remove(Strings);
end;
*)
procedure TCombinedStrings.Clear;
begin
FList.Clear;
end;
procedure TCombinedStrings.Delete(Index: Integer);
begin
end;
procedure TCombinedStrings.Insert(Index: Integer; const S: string);
begin
end;
//=== { TJvIgnorePropertiesStringList } ======================================
procedure TJvIgnorePropertiesStringList.AddDelete(AItem: string; ADelete: Boolean);
begin
if ADelete then
begin
if IndexOf(AItem) >= 0 then
Delete(IndexOf(AItem));
end
else
begin
if IndexOf(AItem) < 0 then
Add(AItem);
end;
end;
//=== { TJvCustomPropertyStore } =============================================
constructor TJvCustomPropertyStore.Create(AOwner: TComponent);
const
IgnorePropertyList: array [1..16] of PChar =
(
'AboutJVCL',
'AppStorage',
'AppStoragePath',
'AutoLoad',
'ClearBeforeLoad',
'Name',
'Tag',
'Enabled',
'ReadOnly',
'DeleteBeforeStore',
'IgnoreLastLoadTime',
'IgnoreProperties',
'OnBeforeLoadProperties',
'OnAfterLoadProperties',
'OnBeforeStoreProperties',
'OnAfterStoreProperties'
);
var
I: Integer;
begin
inherited Create(AOwner);
FLastLoadTime := Now;
FAppStorage := nil;
FEnabled := True;
FReadOnly := False;
FDeleteBeforeStore := False;
FAutoLoad := False;
FIntIgnoreProperties := TStringList.Create;
FIgnoreProperties := TJvIgnorePropertiesStringList.Create;
FIgnoreLastLoadTime := False;
FCombinedIgnoreProperties := TCombinedStrings.Create;
for I := Low(IgnorePropertyList) to High(IgnorePropertyList) do
FIntIgnoreProperties.Add(IgnorePropertyList[I]);
end;
destructor TJvCustomPropertyStore.Destroy;
begin
if not (csDesigning in ComponentState) then
if AutoLoad then
StoreProperties;
FreeAndNil(FCombinedIgnoreProperties);
FreeAndNil(FIntIgnoreProperties);
FreeAndNil(FIgnoreProperties);
Clear;
inherited Destroy;
end;
procedure TJvCustomPropertyStore.Notification(AComponent: TComponent;
Operation: TOperation);
begin
inherited Notification(AComponent, Operation);
if (Operation = opRemove) and (AComponent = FAppStorage) then
FAppStorage := nil;
end;
function TJvCustomPropertyStore.GetCombinedIgnoreProperties: TStringList;
begin
FCombinedIgnoreProperties.Assign(FIntIgnoreProperties);
FCombinedIgnoreProperties.AddStrings(FIgnoreProperties);
Result := FCombinedIgnoreProperties;
end;
function TJvCustomPropertyStore.GetPropCount(Instance: TPersistent): Integer;
var
Data: PTypeData;
begin
Data := GetTypeData(Instance.ClassInfo);
Result := Data^.PropCount;
end;
function TJvCustomPropertyStore.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;
procedure TJvCustomPropertyStore.CloneClass(Src, Dest: TPersistent);
var
Index: Integer;
SrcPropInfo: PPropInfo;
DestPropInfo: PPropInfo;
begin
for Index := 0 to GetPropCount(Src) - 1 do
if CompareText(GetPropName(Src, Index), 'Name') <> 0 then
begin
SrcPropInfo := GetPropInfo(Src.ClassInfo, GetPropName(Src, Index));
DestPropInfo := GetPropInfo(Dest.ClassInfo, GetPropName(Src, Index));
if (DestPropInfo <> nil) and (DestPropInfo^.PropType^.Kind = SrcPropInfo^.PropType^.Kind) then
case DestPropInfo^.PropType^.Kind of
tkLString, tkString:
SetStrProp(Dest, DestPropInfo, GetStrProp(Src, SrcPropInfo));
tkInteger, tkChar, tkEnumeration, tkSet:
SetOrdProp(Dest, DestPropInfo, GetOrdProp(Src, SrcPropInfo));
tkFloat:
SetFloatProp(Dest, DestPropInfo, GetFloatProp(Src, SrcPropInfo));
tkVariant:
SetVariantProp(Dest, DestPropInfo, GetVariantProp(Src, SrcPropInfo));
tkClass:
TPersistent(GetOrdProp(Dest, DestPropInfo)).Assign(TPersistent(GetOrdProp(Src, SrcPropInfo)));
tkMethod:
SetMethodProp(Dest, DestPropInfo, GetMethodProp(Src, SrcPropInfo));
end;
end;
end;
procedure TJvCustomPropertyStore.Loaded;
begin
inherited Loaded;
if not (csDesigning in ComponentState) then
if AutoLoad then
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -