Changeset 366 for Common


Ignore:
Timestamp:
May 22, 2012, 1:45:06 PM (13 years ago)
Author:
chronos
Message:
  • Modified: More clear TLastOpenedList implementation using OnChange event and exteranally called method LoadToMenuItem.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Common/ULastOpenedList.pas

    r329 r366  
    1313
    1414  TLastOpenedList = class(TStringList)
     15  private
     16    FOnChange: TNotifyEvent;
    1517  public
    1618    MaxCount: Integer;
    17     MenuItem: TMenuItem;
    1819    ClickAction: TNotifyEvent;
    1920    constructor Create;
    2021    destructor Destroy; override;
    21     procedure ReloadMenu;
     22    procedure LoadToMenuItem(MenuItem: TMenuItem);
    2223    procedure LoadFromRegistry(Root: HKEY; Key: string);
    2324    procedure SaveToRegistry(Root: HKEY; Key: string);
    2425    procedure AddItem(FileName: string);
     26    property OnChange: TNotifyEvent read FOnChange write FOnChange;
    2527  end;
    2628
     
    4042end;
    4143
    42 procedure TLastOpenedList.ReloadMenu;
     44procedure TLastOpenedList.LoadToMenuItem(MenuItem: TMenuItem);
    4345var
    4446  NewMenuItem: TMenuItem;
     
    6062  I: Integer;
    6163  Registry: TRegistryEx;
     64  FileName: string;
    6265begin
    6366  Registry := TRegistryEx.Create;
     
    6972    I := 0;
    7073    while ValueExists('File' + IntToStr(I)) and (I < MaxCount) do begin
    71       inherited Add(UTF8Encode(ReadStringWithDefault('File' + IntToStr(I), '')));
     74      FileName := UTF8Encode(ReadStringWithDefault('File' + IntToStr(I), ''));
     75      if Trim(FileName) <> '' then inherited Add(FileName);
    7276      Inc(I);
    7377    end;
    74     ReloadMenu;
     78    if Assigned(FOnChange) then
     79      FOnChange(Self);
    7580  finally
    7681    Free;
     
    101106    Delete(Count - 1);
    102107
    103   ReloadMenu;
     108  if Assigned(FOnChange) then
     109    FOnChange(Self);
    104110end;
    105111
Note: See TracChangeset for help on using the changeset viewer.