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

    Join Date
    Sep 2007
    Posts
    196
    Rep Power
    63

    Create memo at runtime - how to access it?


    ok so i have:

    Code:
    procedure SetupSourceEditor;
    
    implementation
    
    procedure SetupSourceEditor;
    var
      SourceEditor1: TMemo;
    begin
      SourceEditor1:= TMemo.Create(frmMainIDE);
      with SourceEditor1 do
      begin
        Parent:= frmMainIDE.MainPanelSourceEditor;
        Align:= alClient;
        Font.Name:= 'Courier New';
        Font.Size:= 10;
        Font.Style:= [fsBold];
        Name:= 'SourceEditor';
        Scrollbars:= ssVertical;
        Visible:= True;
      end;
    end;
    In a a seperate unit, and i can call SetupSourceEditor from the FormShow event no problem, it creates the memo ok. But how can i access SourceEditor1 from any other form? Because when i click MainPanelSourceEditor i want to set focus to SourceEditor1 - but im not sure how to reference to it.

    Thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2007
    Posts
    196
    Rep Power
    63
    bah, stupid me!

    Code:
    with TMemo(FindComponent('SourceEditor')) do
    begin
       //
    end;
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Or you can use this


    for i:=0 to Form1.componentscount -1 do
    begin
    if Form1.Component[i] is TMemo then
    TMemo(Componet[i]).Text:= 'Hello World...'
    end;
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2007
    Posts
    196
    Rep Power
    63
    Originally Posted by majed_ali
    for i:=0 to Form1.componentscount -1 do
    begin
    if Form1.Component[i] is TMemo then
    TMemo(Componet[i]).Text:= 'Hello World...'
    end;
    thanks but i solved it in my last post anyway, your way works but my way finds the memo by its name and class, not just class which may conflict with other memos.

IMN logo majestic logo threadwatch logo seochat tools logo