Thread: MDIForms

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    6
    Rep Power
    0

    MDIForms


    Okay, i have an mdi form, and I want to be able to find/use it after creation, any help?
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    6
    Rep Power
    0

    Angry


    Ok, maby I can clear this up.
    i have an MDIChild Form (TChild)
    and on this form I have a TMemo (Memo)
    When ever I try Child(Form1.ActiveMDIChild).Memo.Lines.Add(); i get an error...
  4. #3
  5. Code Cruncher
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Tasmania, Australia
    Posts
    121
    Rep Power
    14
    Have a look at this code.
    C:\Program Files\Borland\Delphi6\Demos\Doc\TextEdit
    Hope this helps.
    Beware of a programmer with a screwdriver!
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    6
    Rep Power
    0
    OK, I will look at hat.
    If you have any better ideas then the MDI interface, namely, tabbing. I'm all ears. I just am not sure on how I can add text to a certain RichEdit/Memo...
  8. #5
  9. Code Cruncher
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Tasmania, Australia
    Posts
    121
    Rep Power
    14
    What is it your application has to do?
    You have not told us what you need it for yet.
    Beware of a programmer with a screwdriver!
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    6
    Rep Power
    0
    Im making an Instant Messanger client.

    I am trying to be able to put a line into a richedit/memo depending on what user the IM is from/to

    Im tryin a different tactic, using an array of pointers to store the RichEdit pointers, but, im worried about how i will delete the pointers...

    So, i wanted to do an MDI style, but, the demo you gave me was no help
  12. #7
  13. Code Cruncher
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    Tasmania, Australia
    Posts
    121
    Rep Power
    14
    You need to give each child form something unique that you can find again at runtime. In this example I have used the Window caption, you could also use Tag or a value in a property you have made.

    Take the example program above and make these changes:

    1. On the TEditForm, chande the OnCreate so it looks like the one below. This will let us put in a unique caption for each new window.
    Code:
    procedure TEditForm.FormCreate(Sender: TObject);
    var
       s: string;
    begin
      PathName := DefaultFileName;
    
       InputQuery('MDI Test Stuff', 'Give me a new window caption', s);
       Caption := s;
    end;
    2. Now on the TFrameForm. Add a panel and set Align=alTop. Put a button on this panel. Set the OnClick for the button as shown below.
    Code:
    procedure TFrameForm.Button1Click(Sender: TObject);
    var
       i: integer;
       s: string;
    begin
       InputQuery('MDI Window Find', 'What is the window caption to find', s);
    
       for i := 0 to self.MDIChildCount-1 do
          if (Self.MDIChildren[i].Caption = s) then
          begin
             TEditForm(Self.MDIChildren[i]).Editor.Lines.Add('Window is currently index '+IntToStr(i));
             break;
          end;
    end;
    When you run the program, do File | New a few times and type in some easy strings (like "aa", "gg", etc). When you have several child forms open press the button and try locating the one you need.

    Now when you press the button you can find one of the childern and put a line into the memo. Note that the MDIChildern index may be different each time depending in which child has current focus. So you can not store the index, you need to find the window like this each time.

    Let me know how you go with this

    Will each of your child windows have a unique caption you can use to find it, or will you need to use some other way?
    Beware of a programmer with a screwdriver!
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    32
    Rep Power
    10
    Your idea of MDI child windows is fine. Just my own view here but I would take the oo aproach and create an object which holds window handles versus chat clients so for example
    if you have a new chat open (they would have an identity e.g. ip address, not quite sure what your using there) but something along the lines of

    //This stores a person you're chatting with (their ID)
    //and their identifier.

    TOpenChatItem = class
    id : string
    windowHandle : THandle
    end;

    //this is a list of people you are chatting too.

    TOpenchatList (TObjectList)
    public
    function GetChatWindowHandle(Id : string) : THandle;
    //finds handle of client

    procedure AddNewchat(Id : string);
    //allocates a new window, gets its handle and creates a
    //new open chat item adds it to the list.

    procedure RemoveChat(id : string);
    end;

    you could use a TCollection and TCollectionItem if you want too I guess. Just a little cleaner than using a caption to identify which window handle you require and a lot easier to expand upon too.

    just my 10 cents worth....
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    6
    Rep Power
    0
    Well, I ended up using an aray to store the handles of the forms. just disappointed because I can only have a limited number of windows open.

IMN logo majestic logo threadwatch logo seochat tools logo