Recent

Author Topic: TIniPropStorage - Serious Limitation, Bug, or Ignorance  (Read 6441 times)

WayneSherman

  • Jr. Member
  • **
  • Posts: 71
TIniPropStorage - Serious Limitation, Bug, or Ignorance
« on: March 11, 2008, 06:10:55 pm »
I am using a TIniPropStorage on my main form to store some program settings.  In general, it works great.  But, the program runs from a directory that is read-only for some users, and it throws an exception when they try to close (cannot write ini file...).

I thought that this would be an easy fix, but I can't find a simple way of shutting off/preventing the "save" function.  I tried this:

Code: [Select]

type
  TIniPropStorageCracker = class(TIniPropStorage);

procedure TfrmMain.FormClose(Sender: TObject; var CloseAction: TCloseAction);
begin
  if FileExists(TIniPropStorageCracker(IniPropStorage).GetIniFileName) then begin
    IniPropStorage.Active := False;
  end;
end;

Setting "Active" to false, does NOT prevent saving to the ini file.  I looked through the source, and cannot find a simple way to fix this.

Am I missing something?  Any help would be appreciated.

Thanks,

Wayne

Leledumbo

  • Hero Member
  • *****
  • Posts: 8279
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: TIniPropStorage - Serious Limitation, Bug, or Ignorance
« Reply #1 on: March 12, 2008, 12:37:46 pm »
Not sure if it works:
Code: [Select]

procedure IniPropStorage.OnSaveProperties (Sender: TObject);
begin
  Exit;
end;

or
Code: [Select]

procedure IniPropStorage.OnSavingProperties (Sender: TObject);
begin
  Exit;
end;

WayneSherman

  • Jr. Member
  • **
  • Posts: 71
TIniPropStorage - Serious Limitation, Bug, or Ignorance
« Reply #2 on: March 14, 2008, 08:02:55 pm »
I checked the source code, and that won't work.  A more typical way might be:

Code: [Select]

procedure IniPropStorage.OnSavingProperties (Sender: TObject);
begin
  raise EAbort.Create('aborting ini save');
end;


But that won't work since there is no exception handling in place.  The place to catch an EAbort exception catch might be here:

propertystorage.pas original code:
Code: [Select]

procedure TCustomPropertyStorage.Save;
begin
  if FRestored or not Active then
    begin
    StorageNeeded(False);
    Try
      if Assigned(FOnSavingProperties) then
        FOnSavingProperties(Self);
      SaveProperties;
      FStoredValues.SaveValues;
      NotifyLinks(poSave);
      if Assigned(FOnSaveProperties) then
        FOnSaveProperties(Self);
      FSaved := True;
    Finally
      FreeStorage;
    end;
    end;
end;


propertystorage.pas modified code:
Code: [Select]

procedure TCustomPropertyStorage.Save;
begin
  try
    if FRestored or not Active then
      begin
      StorageNeeded(False);
      Try
        if Assigned(FOnSavingProperties) then
          FOnSavingProperties(Self);
        SaveProperties;
        FStoredValues.SaveValues;
        NotifyLinks(poSave);
        if Assigned(FOnSaveProperties) then
          FOnSaveProperties(Self);
        FSaved := True;
      Finally
        FreeStorage;
      end;
      end;
  except
    on EAbort do EXIT;
    raise;
  end;
end;

 

TinyPortal © 2005-2018