Results 1 to 2 of 2

Thread: Frames maintenance

  1. #1

    Frames maintenance

    Never find the need to use Frames, and now that I want to use it I have the feeling im over complicating things :?

    The idea is to have a datalist that is imbedded in one of the forms and also allow the option to separate it so it will be in a stand alone window.
    So I create a Frame with all the GUI elements I wanted and I included it inside the main app Form and in a new Form. To control the data I used the following code:

    Code:
    TMyFrame = Class(TFrame)
      Controller: TController
    end;
    
    TMyFrame.Add(S: String)
      Controller.Add(S)
    end;
    
    TMyFrame.OnControllerChangeEvent
      Repaint;
    end;
    
    ...
    
    TController.Add(S: String)
      DB.Add(S)
      NotifyAllMembers(OnControllerChangeEvent)
    end;
    What do you think, do you have a better idea for solving this issue?
    Note that in this case I won't mind having only 1 "copy" of the window, maybe I should make is as a dockable form..? had bad experience with that...
    [size=9px]BEGIN GEEK CODE BLOCK
    <br />d s-- : a24 GB GCS GTW GE C++ P L+ W++ N+ K- w++++ M- PS+ PE+ Y- t+ 5+++ X+ R*
    <br />tv b+ DI++ D+ e++ h+ G-
    <br />END GEEK CODE BLOCK[/size]
    <br />Create your own GeekCode block at: <a href="">...</a>

  2. #2

    Frames maintenance

    As there were no post I just wrote my initial idea, maybe its not the best way to do this but it works

    [pascal]
    unit SongListManagerUnit;

    interface
    uses
    Classes;

    type
    TListUpdateEvent = procedure;

    TSongListManager = class
    private
    FSongList: TStrings;
    FFrameList: TList;
    FFrameEvent: TList;

    procedure SendUpdateEvent(Sender: TObject);
    public
    constructor Create;
    procedure Free;

    procedure LoadList(path: string);
    procedure SaveList(path: string);

    procedure AddFrame(const item: TObject;
    const UpdateEventHandler: TListUpdateEvent);
    procedure AddData(data: string; Sender: TObject);
    procedure DeleteData(Index: Integer; Sender: TObject);

    property SongList: TStrings read FSongList;
    end;

    var
    SongListManager: TSongListManager;

    implementation

    constructor TSongListManager.Create;
    begin
    inherited Create;
    FSongList:= TStringlist.Create;
    FFrameList:= TList.Create;
    FFrameEvent:= TList.Create;
    end;

    procedure TSongListManager.Free;
    begin
    FSongList.Free;
    inherited;
    end;

    procedure TSongListManager.AddFrame(const item: TObject;
    const UpdateEventHandler: TListUpdateEvent);
    begin
    FFrameList.Add(item);
    FFrameEvent.Add(@UpdateEventHandler);
    end;

    procedure TSongListManager.AddData(data: string; Sender: TObject);
    begin
    FSongList.Append(data);
    SendUpdateEvent(Sender);
    end;

    procedure TSongListManager.DeleteData(Index: Integer; Sender: TObject);
    begin
    FSongList.Delete(Index);
    SendUpdateEvent(Sender);
    end;

    procedure TSongListManager.SendUpdateEvent(Sender: TObject);
    var
    I: Integer;
    begin
    for I:= 0 to FFrameEvent.Count - 1 do
    if Sender <> FFrameList[I] then
    if Assigned(FFrameEvent[I]) then
    TListUpdateEvent(FFrameEvent[I]);
    end;

    procedure TSongListManager.LoadList(path: string);
    begin
    FSongList.LoadFromFile(path);
    end;

    procedure TSongListManager.SaveList(path: string);
    begin
    FSongList.SaveToFile(path);
    end;

    Initialization
    SongListManager:= TSongListManager.Create;

    finalization
    SongListManager.Free;

    end.
    [/pascal]
    [size=9px]BEGIN GEEK CODE BLOCK
    <br />d s-- : a24 GB GCS GTW GE C++ P L+ W++ N+ K- w++++ M- PS+ PE+ Y- t+ 5+++ X+ R*
    <br />tv b+ DI++ D+ e++ h+ G-
    <br />END GEEK CODE BLOCK[/size]
    <br />Create your own GeekCode block at: <a href="">...</a>

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •