📄 jvplacemnt.pas
字号:
begin
FMinMaxInfo := TJvWinMinMaxInfo(Source).FMinMaxInfo;
if FOwner <> nil then
FOwner.MinMaxInfoModified;
end
else
inherited Assign(Source);
end;
function TJvWinMinMaxInfo.GetMinMaxInfo(Index: Integer): Integer;
begin
with FMinMaxInfo do
begin
case Index of
0:
Result := ptMaxPosition.X;
1:
Result := ptMaxPosition.Y;
2:
Result := ptMaxSize.Y;
3:
Result := ptMaxSize.X;
4:
Result := ptMaxTrackSize.Y;
5:
Result := ptMaxTrackSize.X;
6:
Result := ptMinTrackSize.Y;
7:
Result := ptMinTrackSize.X;
else
Result := 0;
end;
end;
end;
procedure TJvWinMinMaxInfo.SetMinMaxInfo(Index: Integer; Value: Integer);
begin
if GetMinMaxInfo(Index) <> Value then
begin
with FMinMaxInfo do
begin
case Index of
0:
ptMaxPosition.X := Value;
1:
ptMaxPosition.Y := Value;
2:
ptMaxSize.Y := Value;
3:
ptMaxSize.X := Value;
4:
ptMaxTrackSize.Y := Value;
5:
ptMaxTrackSize.X := Value;
6:
ptMinTrackSize.Y := Value;
7:
ptMinTrackSize.X := Value;
end;
end;
if FOwner <> nil then
FOwner.MinMaxInfoModified;
end;
end;
function TJvWinMinMaxInfo.DefaultMinMaxInfo: Boolean;
begin
with FMinMaxInfo do
begin
Result := not ((ptMinTrackSize.X <> 0) or (ptMinTrackSize.Y <> 0) or
(ptMaxTrackSize.X <> 0) or (ptMaxTrackSize.Y <> 0) or
(ptMaxSize.X <> 0) or (ptMaxSize.Y <> 0) or
(ptMaxPosition.X <> 0) or (ptMaxPosition.Y <> 0));
end;
end;
//=== TJvFormStorage =========================================================
constructor TJvFormStorage.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
FStoredProps := TStringList.Create;
{$IFDEF COMPILER3_UP}
FStoredValues := TJvStoredValues.Create{$IFDEF COMPILER4_UP}(Self){$ENDIF COMPILER4_UP};
FStoredValues.Storage := Self;
{$ENDIF COMPILER3_UP}
end;
destructor TJvFormStorage.Destroy;
begin
FStoredProps.Free;
FStoredProps := nil;
{$IFDEF COMPILER3_UP}
FStoredValues.Free;
FStoredValues := nil;
{$ENDIF COMPILER3_UP}
inherited Destroy;
end;
{$IFDEF WIN32}
procedure TJvFormStorage.SetNotification;
var
I: Integer;
Component: TComponent;
begin
for I := FStoredProps.Count - 1 downto 0 do
begin
Component := TComponent(FStoredProps.Objects[I]);
if Component <> nil then
Component.FreeNotification(Self);
end;
end;
{$ENDIF WIN32}
procedure TJvFormStorage.SetStoredProps(Value: TStrings);
begin
FStoredProps.Assign(Value);
{$IFDEF WIN32}
SetNotification;
{$ENDIF}
end;
{$IFDEF COMPILER3_UP}
procedure TJvFormStorage.SeTJvStoredValues(Value: TJvStoredValues);
begin
FStoredValues.Assign(Value);
end;
function TJvFormStorage.GeTJvStoredValue(const Name: string): Variant;
begin
Result := StoredValues.StoredValue[Name];
end;
procedure TJvFormStorage.SeTJvStoredValue(const Name: string; Value: Variant);
begin
StoredValues.StoredValue[Name] := Value;
end;
{$ENDIF COMPILER3_UP}
procedure TJvFormStorage.Loaded;
begin
inherited Loaded;
UpdateStoredList(Owner, FStoredProps, True);
end;
procedure TJvFormStorage.WriteState(Writer: TWriter);
begin
UpdateStoredList(Owner, FStoredProps, False);
inherited WriteState(Writer);
end;
procedure TJvFormStorage.Notification(AComponent: TComponent; Operation: TOperation);
var
I: Integer;
Component: TComponent;
begin
inherited Notification(AComponent, Operation);
if not (csDestroying in ComponentState) and (Operation = opRemove) and
(FStoredProps <> nil) then
for I := FStoredProps.Count - 1 downto 0 do
begin
Component := TComponent(FStoredProps.Objects[I]);
if Component = AComponent then
FStoredProps.Delete(I);
end;
end;
procedure TJvFormStorage.SaveProperties;
begin
with TJvPropsStorage.Create do
try
Section := IniSection;
OnWriteString := DoWriteString;
{$IFDEF WIN32}
if UseRegistry then
OnEraseSection := FRegIniFile.EraseSection
else
OnEraseSection := FIniFile.EraseSection;
{$ELSE}
OnEraseSection := FIniFile.EraseSection;
{$ENDIF WIN32}
StoreObjectsProps(Owner, FStoredProps);
finally
Free;
end;
end;
procedure TJvFormStorage.RestoreProperties;
begin
with TJvPropsStorage.Create do
try
Section := IniSection;
OnReadString := DoReadString;
try
LoadObjectsProps(Owner, FStoredProps);
except
{ ignore any exceptions }
end;
finally
Free;
end;
end;
procedure TJvFormStorage.SavePlacement;
begin
inherited SavePlacement;
SaveProperties;
{$IFDEF COMPILER3_UP}
StoredValues.SaveValues;
{$ENDIF}
end;
procedure TJvFormStorage.RestorePlacement;
begin
inherited RestorePlacement;
FRestored := True;
RestoreProperties;
{$IFDEF COMPILER3_UP}
StoredValues.RestoreValues;
{$ENDIF}
end;
//=== TJvIniLink =============================================================
destructor TJvIniLink.Destroy;
begin
FOnSave := nil;
FOnLoad := nil;
SetStorage(nil);
inherited Destroy;
end;
function TJvIniLink.GetIniObject: TObject;
begin
if Assigned(FStorage) then
Result := FStorage.IniFileObject
else
Result := nil;
end;
function TJvIniLink.GetRootSection: string;
begin
if Assigned(FStorage) then
Result := FStorage.FIniSection
else
Result := '';
if Result <> '' then
Result := Result + '\';
end;
procedure TJvIniLink.SetStorage(Value: TJvFormPlacement);
begin
if FStorage <> Value then
begin
if FStorage <> nil then
FStorage.RemoveLink(Self);
if Value <> nil then
Value.AddLink(Self);
end;
end;
procedure TJvIniLink.SaveToIni;
begin
if Assigned(FOnSave) then
FOnSave(Self);
end;
procedure TJvIniLink.LoadFromIni;
begin
if Assigned(FOnLoad) then
FOnLoad(Self);
end;
//=== TJvStoredValue =========================================================
{$IFDEF COMPILER3_UP}
constructor TJvStoredValue.Create(Collection: TCollection);
begin
inherited Create(Collection);
FValue := Unassigned;
end;
procedure TJvStoredValue.Assign(Source: TPersistent);
begin
if (Source is TJvStoredValue) and (Source <> nil) then
begin
if VarIsEmpty(TJvStoredValue(Source).FValue) then
Clear
else
Value := TJvStoredValue(Source).FValue;
Name := TJvStoredValue(Source).Name;
KeyString := TJvStoredValue(Source).KeyString;
end;
end;
function TJvStoredValue.GetDisplayName: string;
begin
if FName = '' then
Result := inherited GetDisplayName
else
Result := FName;
end;
procedure TJvStoredValue.SetDisplayName(const Value: string);
begin
if (Value <> '') and (AnsiCompareText(Value, FName) <> 0) and
(Collection is TJvStoredValues) and (TJvStoredValues(Collection).IndexOf(Value) >= 0) then
raise EJVCLException.Create(SDuplicateString);
FName := Value;
inherited;
end;
function TJvStoredValue.GeTJvStoredValues: TJvStoredValues;
begin
if Collection is TJvStoredValues then
Result := TJvStoredValues(Collection)
else
Result := nil;
end;
procedure TJvStoredValue.Clear;
begin
FValue := Unassigned;
end;
function TJvStoredValue.IsValueStored: Boolean;
begin
Result := not VarIsEmpty(FValue);
end;
procedure TJvStoredValue.Save;
var
SaveValue: Variant;
SaveStrValue: string;
begin
SaveValue := Value;
if Assigned(FOnSave) then
FOnSave(Self, SaveValue);
SaveStrValue := VarToStr(SaveValue);
if KeyString <> '' then
SaveStrValue := XorEncode(KeyString, SaveStrValue);
StoredValues.Storage.WriteString(Name, SaveStrValue);
end;
procedure TJvStoredValue.Restore;
var
RestoreValue: Variant;
RestoreStrValue, DefaultStrValue: string;
begin
DefaultStrValue := VarToStr(Value);
if KeyString <> '' then
DefaultStrValue := XorEncode(KeyString, DefaultStrValue);
RestoreStrValue := StoredValues.Storage.ReadString(Name, DefaultStrValue);
if KeyString <> '' then
RestoreStrValue := XorDecode(KeyString, RestoreStrValue);
RestoreValue := RestoreStrValue;
if Assigned(FOnRestore) then
FOnRestore(Self, RestoreValue);
Value := RestoreValue;
end;
//=== TJvStoredValues ========================================================
{$IFDEF COMPILER4_UP}
constructor TJvStoredValues.Create(AOwner: TPersistent);
begin
inherited Create(AOwner, TJvStoredValue);
end;
{$ELSE}
constructor TJvStoredValues.Create;
begin
inherited Create(TJvStoredValue);
end;
{$ENDIF}
function TJvStoredValues.IndexOf(const Name: string): Integer;
begin
for Result := 0 to Count - 1 do
if AnsiCompareText(Items[Result].Name, Name) = 0 then
Exit;
Result := -1;
end;
function TJvStoredValues.GetItem(Index: Integer): TJvStoredValue;
begin
Result := TJvStoredValue(inherited Items[Index]);
end;
procedure TJvStoredValues.SetItem(Index: Integer; StoredValue: TJvStoredValue);
begin
inherited SetItem(Index, TCollectionItem(StoredValue));
end;
function TJvStoredValues.GeTJvStoredValue(const Name: string): Variant;
var
StoredValue: TJvStoredValue;
begin
StoredValue := GetValue(Name);
if StoredValue = nil then
Result := Null
else
Result := StoredValue.Value;
end;
procedure TJvStoredValues.SeTJvStoredValue(const Name: string; Value: Variant);
var
StoredValue: TJvStoredValue;
begin
StoredValue := GetValue(Name);
if StoredValue = nil then
begin
StoredValue := TJvStoredValue(Add);
StoredValue.Name := Name;
StoredValue.Value := Value;
end
else
StoredValue.Value := Value;
end;
function TJvStoredValues.GetValue(const Name: string): TJvStoredValue;
var
I: Integer;
begin
I := IndexOf(Name);
if I < 0 then
Result := nil
else
Result := Items[I];
end;
procedure TJvStoredValues.SetValue(const Name: string; StoredValue: TJvStoredValue);
var
I: Integer;
begin
I := IndexOf(Name);
if I >= 0 then
Items[I].Assign(StoredValue);
end;
procedure TJvStoredValues.SaveValues;
var
I: Integer;
begin
for I := 0 to Count - 1 do
Items[I].Save;
end;
procedure TJvStoredValues.RestoreValues;
var
I: Integer;
begin
for I := 0 to Count - 1 do
Items[I].Restore;
end;
{$ENDIF COMPILER3_UP}
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -