Results 1 to 16 of 16

Thread: an other SCAR notepad, lol

  1. #1
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default an other SCAR notepad, lol

    i wanted to learn about filemenus, and saving to files, so i decided to make a little SCAR notepad it might not be usefull, and basic, but i feel like i'v learned a good amount from this, and its some-what cool

    thanks to Da 0wner, he helped me on msn, although hes bant

    he also told me to post the notepad here lol

    SCAR Code:
    program New;

    var
      // Initform variables.
      EndInitform : Boolean;
      notepad : TForm;
      Memo1 : TMemo;
      Button1, Button2, Button3 : TButton;
      OpenDialog1 : TOpenDialog;
      SaveDialog1 : TSaveDialog;
      filemenu : TMainMenu;
      Title, Title1, Option : TMenuItem;
     
    procedure LoadFile(sender: TObject);
     begin
      OpenDialog1 := TOpenDialog.Create(notepad);
      OpenDialog1.InitialDir := AppPath;
      OpenDialog1.Options := [ofFileMustExist, ofReadOnly];
      OpenDialog1.Filter := 'Text Documents (*.txt)|*.txt|' +
                            'All Files|*|';
      if(OpenDialog1.Execute)then
      begin
        LoadFromFile(Memo1, OpenDialog1.FileName);
      end else
        WriteLn('User pressed cancel!');
      OpenDialog1.Free;
    end;

    procedure SaveFile(sender: TObject);
    begin
      SaveDialog1 := TSaveDialog.Create(nil);
      SaveDialog1.InitialDir := AppPath;
      SaveDialog1.Filter := 'Text Documents (*.txt)|*.txt|' +
                            'All Files|*|';
      if SaveDialog1.Execute then
        savetoFile(Memo1, Savedialog1.FileName);
      SaveDialog1.Free;

    end;

    procedure clear(sender : tobject);
    begin
      memo1.text:= '';
    end;

    procedure InitformOnClose(Sender : TObject; var Action : TCloseAction);
    begin
      if (not(notepad.ModalResult = 1)) then
        EndInitform := True;
    end;

    procedure Initform;
    var
      TimeInitform : Integer;
      hotkey : TMenuAutoFlag;
    begin
      TimeInitform := GetSystemTime;
      notepad := CreateForm;
      with notepad do
      begin
        OnClose := @InitformOnClose;
        Position := poScreenCenter;
        BorderStyle := bsSingle;
        BorderIcons := [biMinimize,biSystemMenu];
        ClientWidth := 600;
        ClientHeight := 600;
        Caption := 'Akwardsaw''s Note Pad';
        Color := clblack;
        Font.Color := clWindowText;
        Font.Height := -11;
        Font.Name := 'MS Sans Serif';
        Font.Style := [];
        PixelsPerInch := 96;
      end;
      Memo1 := TMemo.Create(notepad);
      with Memo1 do
      begin
        Parent := notepad;
        Left := 2;
        Top := 2;
        Width := 596;
        Height := 578;
        Memo1.ScrollBars := ssVertical;
        with Lines do
        begin
          Add('Memo1');
        end;
        text:= '';
        TabOrder := 8;
      end;
      FileMenu := TMainMenu.Create(notepad);
      Title := TMenuItem.Create(notepad);
      Title.Caption := 'File';
      FileMenu.Items.Add(Title);

      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Clear';
      Option.OnClick := @clear;
      FileMenu.Items.Items[0].Add(Option);

      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Load';
      Option.OnClick := @LoadFile;
      FileMenu.Items.Items[0].Add(Option);

      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Save';
      Option.OnClick := @SaveFile;
      FileMenu.Items.Items[0].Add(Option);

      WriteLn('Initform compiled in ' + IntToStr(GetSystemTime - TimeInitform) + ' milliseconds!');
    end;

    procedure SafeInitform;
    var
      v : TVariantArray;
    begin
      SetArrayLength(v, 0);
      ThreadSafeCall('Initform', v);
    end;

    procedure ShowInitformModal;
    begin
      notepad.ShowModal;
    end;

    procedure SafeShowInitformModal;
    var
      v : TVariantArray;
    begin
      SetArrayLength(v, 0);
      ThreadSafeCall('ShowInitformModal', v);
    end;

    procedure MainInitform;
    begin
      try
        SafeInitform;
        SafeShowInitformModal;
      finally
        FreeForm(notepad);
      except
        WriteLn('An error seems to have occurred in: Initform');
      end;
    end;

    begin
      ClearDebug;
      GetSelf.WindowState := wsMinimized;
      MainInitform;
      GetSelf.WindowState := wsNormal;
      if (EndInitform) then
        TerminateScript;
    end.

    ima try to add an edit menu later, if you guys think i should
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  2. #2
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    GetSelf.WindowState := wsNormal;
    thats kind of inconvenient. something like
    SCAR Code:
    var a: TWindowState;
    begin
      ClearDebug;
      a := GetSelf.WindowState;
      GetSelf.WindowState := wsMinimized;
      MainInitform;
      GetSelf.WindowState := a;
    would be better. Small thing, but kind of annoying without it.

    Otherwise, nice and simple, yet apparently being your point, so good job.
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  3. #3
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    if it has to do with the form, its Ron's fault but i see what you mean

    i'm also attempting to add in an edit menu to the menu bar, which should be fun haha
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  4. #4
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Wow, great job, Awk!

    It's really nice to see people getting more and more into building form-based scripts (utilities and such).. Keep working on it, mate.

    1 suggestion.. When user closes the form, and if the current text has been changed, make it ask if user wants to exit without or with saving.

  5. #5
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by Janilabo View Post
    Wow, great job, Awk!

    It's really nice to see people getting more and more into building form-based scripts (utilities and such).. Keep working on it, mate.

    1 suggestion.. When user closes the form, and if the current text has been changed, make it ask if user wants to exit without or with saving.
    thats a good idea i'll add that tonight if i can remember
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  6. #6
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    i decided to update this thing out of boredness

    SCAR Code:
    program New;

    var
      // Initform variables.
      EndInitform : Boolean;
      notepad : TForm;
      Memo1 : TMemo;
      Button1, Button2, Button3 : TButton;
      OpenDialog1 : TOpenDialog;
      SaveDialog1 : TSaveDialog;
      filemenu : TMainMenu;
      Title, Title1, Option : TMenuItem;
      t : string;

    procedure LoadFile(sender: TObject);
     begin
      OpenDialog1 := TOpenDialog.Create(notepad);
      OpenDialog1.InitialDir := AppPath;
      OpenDialog1.Options := [ofFileMustExist, ofReadOnly];
      OpenDialog1.Filter := 'Text Documents (*.txt)|*.txt|' +
                            'All Files|*|';
      if(OpenDialog1.Execute)then
      begin
        LoadFromFile(Memo1, OpenDialog1.FileName);
      end else
        WriteLn('User pressed cancel!');
      OpenDialog1.Free;
      t:= memo1.Text;
    end;

    procedure SaveTehFile;
    begin
        SaveDialog1 := TSaveDialog.Create(nil);
      SaveDialog1.InitialDir := AppPath;
      SaveDialog1.Filter := 'Text Documents (*.txt)|*.txt|' +
                            'All Files|*|';
      if SaveDialog1.Execute then
        savetoFile(Memo1, Savedialog1.FileName);
      SaveDialog1.Free;
    end;

    procedure SaveFile(sender: TObject);
    begin
      SaveTehFile;
      t:= memo1.Text;
    end;

    procedure KeyBoredComand(letter : char);
    begin
      keydown(vk_control);
      KeyDown(getkeycode(letter));
      wait(10);
      keyup(vk_control);
      Keyup(getkeycode(letter));
    end;

    procedure copy(sender : tobject);
    begin
      KeyBoredComand('c');
    end;

    procedure paste(sender : tobject);
    begin
      KeyBoredComand('v');
    end;

    procedure cut(sender : tobject);
    begin
      KeyBoredComand('x');
    end;

    procedure Undo(sender : tobject);
    begin
      KeyBoredComand('z');
    end;

    procedure Redo(sender : tobject);
    begin
      KeyBoredComand('y');
    end;

    procedure clear(sender : tobject);
    begin
      memo1.text:= '';
    end;

    procedure InitformOnClose(Sender : TObject; var Action : TCloseAction);
    begin
      if memo1.text <> t then
      if GetApplication.MessageBox('Text has been modified! Do you wish to save?', 'Save?', 4) = mryes then
        SaveTehFile;
      if (not(notepad.ModalResult = 1)) then
        EndInitform := True;
    end;

    procedure Initform;
    var
      TimeInitform : Integer;
      hotkey : TMenuAutoFlag;
    begin
      TimeInitform := GetSystemTime;
      notepad := CreateForm;
      with notepad do
      begin
        OnClose := @InitformOnClose;
        Position := poScreenCenter;
        BorderStyle := bsSingle;
        BorderIcons := [biMinimize,biSystemMenu];
        ClientWidth := 600;
        ClientHeight := 600;
        Caption := 'Akwardsaw''s Note Pad';
        Color := clblack;
        Font.Color := clWindowText;
        Font.Height := -11;
        Font.Name := 'MS Sans Serif';
        Font.Style := [];
        PixelsPerInch := 96;
      end;
      Memo1 := TMemo.Create(notepad);
      with Memo1 do
      begin
        Parent := notepad;
        Left := 2;
        Top := 2;
        Width := 596;
        Height := 578;
        Memo1.ScrollBars := ssVertical;
        with Lines do
        begin
          Add('Memo1');
        end;
        text:= '';
        TabOrder := 8;
      end;
      FileMenu := TMainMenu.Create(notepad);
      Title := TMenuItem.Create(notepad);
      Title.Caption := 'File';
      FileMenu.Items.Add(Title);

      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Clear';
      Option.OnClick := @clear;
      FileMenu.Items.Items[0].Add(Option);

      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Load';
      Option.OnClick := @LoadFile;
      FileMenu.Items.Items[0].Add(Option);

      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Save';
      Option.OnClick := @SaveFile;
      FileMenu.Items.Items[0].Add(Option);
     
      Title1 := TMenuItem.Create(notepad);
      Title1.Caption := 'Edit';
      FileMenu.Items.Add(Title1);
     
      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Undo';
      Option.OnClick := @Undo;
      FileMenu.Items.Items[1].Add(Option);
     
      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Redo';
      Option.OnClick := @Redo;
      FileMenu.Items.Items[1].Add(Option);
     
      Option := TMenuItem.Create(notepad);
      Option.Caption := '-';
      Option.Enabled := false;
      FileMenu.Items.Items[1].Add(Option);
     
      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Cut';
      Option.OnClick := @cut;
      FileMenu.Items.Items[1].Add(Option);

      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Copy';
      Option.OnClick := @copy;
      FileMenu.Items.Items[1].Add(Option);
     
      Option := TMenuItem.Create(notepad);
      Option.Caption := 'Paste';
      Option.OnClick := @paste;
      FileMenu.Items.Items[1].Add(Option);
     
      Option := TMenuItem.Create(notepad);
      Option.Caption := '-';
      Option.Enabled := false;
      FileMenu.Items.Items[1].Add(Option);
     
      WriteLn('Initform compiled in ' + IntToStr(GetSystemTime - TimeInitform) + ' milliseconds!');
    end;

    procedure SafeInitform;
    var
      v : TVariantArray;
    begin
      SetArrayLength(v, 0);
      ThreadSafeCall('Initform', v);
    end;

    procedure ShowInitformModal;
    begin
      notepad.ShowModal;
    end;

    procedure SafeShowInitformModal;
    var
      v : TVariantArray;
    begin
      SetArrayLength(v, 0);
      ThreadSafeCall('ShowInitformModal', v);
    end;

    procedure MainInitform;
    begin
      try
        SafeInitform;
        SafeShowInitformModal;
      finally
        FreeForm(notepad);
      except
        WriteLn('An error seems to have occurred in: Initform');
      end;
    end;

    begin
      ClearDebug;
      MainInitform;
      GetSelf.WindowState := wsNormal;
      t:= memo1.Text;
      if (EndInitform) then
        TerminateScript;
    end.

    i added:
    edit menu
    it now checks if you want to save your text if you changed it

    also, how would i make the edit commands into a case? i dont think you can use parameters in senders
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  7. #7
    Join Date
    Apr 2006
    Location
    I live in NH
    Posts
    611
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice notepad script, very simple. I ran pretty smoothly in SCAR 3.12 on XP.

    I can't get the Redo feature to work at all. However, I did make other modifications that you may like and that you can learn from.

    Code:
    program AwkwardsawsNotePad;
    
    var
      // Initform variables.
      notepad : TForm;
      Memo1 : TMemo;
      t : string;
    
    procedure LoadFile(sender: TObject);
    var
      OpenDialog1 : TOpenDialog;
    begin
      OpenDialog1 := TOpenDialog.Create(notepad);
      OpenDialog1.InitialDir := AppPath;
      OpenDialog1.Options := [ofFileMustExist, ofReadOnly];
      OpenDialog1.Filter := 'Text Documents (*.txt)|*.txt|' +
                            'All Files|*|';
      if(OpenDialog1.Execute)then
        LoadFromFile(Memo1, OpenDialog1.FileName);
      OpenDialog1.Free;
      t:= memo1.Text;
    end;
    
    procedure SaveTehFile;
    var
      fileName : String;
      SaveDialog1 : TSaveDialog;
    begin
      SaveDialog1 := TSaveDialog.Create(nil);
      SaveDialog1.InitialDir := AppPath;
      SaveDialog1.Filter := 'Text Documents (*.txt)|*.txt|' +
                            'All Files|*|';
      if SaveDialog1.Execute then
      begin
        fileName := SaveDialog1.FileName;
        if not(Lowercase(ExtractFileExt(fileName)) = '.txt') then
          fileName := fileName + '.txt';
        SaveToFile(Memo1, fileName);
      end;
      SaveDialog1.Free;
    end;
    
    procedure SaveFile(sender: TObject);
    begin
      SaveTehFile;
      t := memo1.Text;
    end;
    
    procedure KeyboardCommand(letter : char);
    begin
      keydown(vk_control);
      KeyDown(getkeycode(letter));
      wait(10);
      keyup(vk_control);
      Keyup(getkeycode(letter));
    end;
    
    procedure Copy(sender : tobject);
    begin
      KeyboardCommand('c');
    end;
    
    procedure Paste(sender : tobject);
    begin
      KeyboardCommand('v');
    end;
    
    procedure Cut(sender : tobject);
    begin
      KeyboardCommand('x');
    end;
    
    procedure Undo(sender : tobject);
    begin
      KeyboardCommand('z');
    end;
    
    procedure Redo(sender : tobject);
    begin
      KeyboardCommand('y');
    end;
    
    procedure Clear(sender : tobject);
    begin
      memo1.text := '';
    end;
    
    procedure InitformOnClose(Sender : TObject; var Action : TCloseAction);
    begin
      if memo1.text <> t then
        if GetApplication.MessageBox('Text has been modified! Do you wish to save?', 'Save?', 4) = mryes then
          SaveTehFile;
    end;
    
    procedure InitformOnResize(Sender : TObject);
    begin
      // subtract 5 to get rid of the form's scrollbars
      memo1.Width := notepad.ClientWidth - 5;
      memo1.Height := notepad.ClientHeight - 5;
    end;
    
    procedure Initform;
    var
      TimeInitform : Integer;
      filemenu : TMainMenu;
      Title, Option : TMenuItem;
      menuNames : Array of String;
      menuItems : Array of Array of String;
      row, col, numRow, numCol : Integer;
    begin
      TimeInitform := GetSystemTime;
      notepad := CreateForm;
      with notepad do
      begin
        OnClose := @InitformOnClose;
        Position := poScreenCenter;
        BorderStyle := bsSizeable;
        BorderIcons := [biMinimize, biMaximize, biSystemMenu];
        ClientWidth := 600;
        ClientHeight := 600;
        Caption := 'Awkwardsaw''s Note Pad';
        //Color := clblack;
        OnResize := @InitformOnResize;
      end;
      Memo1 := TMemo.Create(notepad);
      with Memo1 do
      begin
        Parent := notepad;
        Left := 2;
        Top := 2;
        //Width := 596;
        //Height := 578;
        Memo1.ScrollBars := ssVertical;
        TabOrder := 1;
      end;
      FileMenu := TMainMenu.Create(notepad);
      menuNames := ['File', 'Edit'];
      numRow := GetArrayLength(menuNames);
      SetArrayLength(menuItems, numRow);
      // under file
      menuItems[ 0 ] := ['Clear', 'Load', 'Save'];
      // under edit
      menuItems[ 1 ] := ['Undo', 'Redo', '-', 'Cut', 'Copy', 'Paste'];
      
      for row := 0 to numRow - 1 do
      begin
        Title := TMenuItem.Create(notepad);
        Title.Caption := menuNames[ row ];
        FileMenu.Items.Add(Title);
        numCol := GetArrayLength( menuItems[ row ] );
        for col := 0 to numCol - 1 do
        begin
          Option := TMenuItem.Create(notepad);
          Option.Caption := menuItems[ row ][ col ];
          FileMenu.Items.Items[ row ].Add(Option);
        end;
      end;
      
      with FileMenu.Items do
      begin
        // file
        Items[ 0 ].Items[ 0 ].OnClick := @clear;
        Items[ 0 ].Items[ 1 ].OnClick := @LoadFile;
        Items[ 0 ].Items[ 2 ].OnClick := @SaveFile;
        // edit
        Items[ 1 ].Items[ 0 ].OnClick := @Undo;
        Items[ 1 ].Items[ 1 ].OnClick := @Redo;
        Items[ 1 ].Items[ 2 ].Enabled := false;  // the dash
        Items[ 1 ].Items[ 3 ].OnClick := @cut;
        Items[ 1 ].Items[ 4 ].OnClick := @copy;
        Items[ 1 ].Items[ 5 ].OnClick := @paste;
      end;
    
      WriteLn('Initform compiled in ' + IntToStr(GetSystemTime - TimeInitform) + ' milliseconds!');
    end;
    
    procedure SafeInitform;
    var
      v : TVariantArray;
    begin
      SetArrayLength(v, 0);
      ThreadSafeCall('Initform', v);
    end;
    
    procedure ShowInitformModal;
    begin
      notepad.ShowModal;
    end;
    
    procedure SafeShowInitformModal;
    var
      v : TVariantArray;
    begin
      SetArrayLength(v, 0);
      ThreadSafeCall('ShowInitformModal', v);
    end;
    
    procedure MainInitform;
    begin
      try
        SafeInitform;
        SafeShowInitformModal;
      finally
        FreeForm(notepad);
      except
        WriteLn('An error seems to have occurred in: Initform');
      end;
    end;
    
    begin
      ClearDebug;
      GetSelf.WindowState := wsMinimized;
      MainInitform;
      GetSelf.WindowState := wsNormal;
    end.
    You spelt your name wrong in the title lol. I just had to fix the code when I saw that.

    ~Ron
    DFM Form Parser - SCAR Obfuscator - Master Keylogger - RuneScape Stats Grabber - Index Cards

  8. #8
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    thanks ron, i just got off the cpu that has SCAR on it, so i cant take a decent look at it, although i do know the changes. i'll take more of a detailed look later
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  9. #9
    Join Date
    Oct 2010
    Posts
    36
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ron, when I change the .ShowModal to .Show the .OnResize event causes an "access violation". What causes that?

  10. #10
    Join Date
    Feb 2009
    Location
    Irvine, CA
    Posts
    2,873
    Mentioned
    8 Post(s)
    Quoted
    138 Post(s)

    Default

    Quote Originally Posted by EGM View Post
    Ron, when I change the .ShowModal to .Show the .OnResize event causes an "access violation". What causes that?
    The fact that you bumped a 1 year+ old thread caused it to break.

  11. #11
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    people still use SCAR?
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  12. #12
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    people still use SCAR?
    He seems new, so he might not even know about Simba, considering SRL has many (old) resources that only mention SCAR.
    Last edited by Wizzup?; 11-16-2010 at 08:35 PM.



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  13. #13
    Join Date
    May 2008
    Posts
    1,345
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    people still use SCAR?
    I tried Simba and everything looked weird . Plus some of the stuff I tried didn't work, heh.

  14. #14
    Join Date
    May 2007
    Location
    Some where fun.
    Posts
    2,891
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    people still use SCAR?
    I do.

  15. #15
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    He seems new, so he might not even know about Simba, considering SRL has many (old) resources that only mention SCAR.
    ah that's true, i haven't noticed he's new
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  16. #16
    Join Date
    Oct 2010
    Posts
    36
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Wizzup? and Ron:

    I use Simba exclusively since discovering it, and [sometimes painstakingly] convert whatever information I find -- which is usually Scar related -- over to it. Would you prefer I perform a search first and post to an old thread, or just keep writing new threads?

    Can't wait till the Simba docs are completed! (Examples would be nice, too.. *hint*)

    What I was trying to do is create a window to write messages to.
    Simba Code:
    program ActivityLog;
    const
      CR = #$0D;
      LF = #$0A;
      CRLF = CR + LF;

    var
      ActivityLog: TForm;
      LogMemo: TMemo;
      btnCopy, btnClose: TButton;

    procedure CopyMemoToClipboard(Sender: TObject);
      begin
        LogMemo.SELECTALL;
        LogMemo.COPYTOCLIPBOARD;
      end;

    procedure ActivityLog_OnResize(Sender: TObject);
      begin
        with ActivityLog do
          begin
            //First set a minimum height and width:
            if ClientWidth < 250 then ClientWidth := 250;
            if ClientHeight < 60 then ClientHeight := 60;
            //Then change the other controls:
            LogMemo.Width := ClientWidth - 5;
            LogMemo.Height := ClientHeight - 35;
            btnCopy.Top := ClientHeight - 32;
            btnClose.Top := ClientHeight - 32;
            btnClose.Left := ClientWidth - 124;
          end;
      end;

    procedure ActivityLog_Init;
      begin
        ActivityLog := TForm.Create(ActivityLog);
        with ActivityLog do
          begin
            Width := 800;
            Height := 120;
            Top := 610;
            Left := 60;
            Caption := 'Activity Log:';
            OnResize := @ActivityLog_OnResize;
          end;
        LogMemo := TMemo.Create(ActivityLog);
        with LogMemo do
          begin
            Parent := ActivityLog;
            Top := 2;
            Left := 2;
            Height := ActivityLog.Height - 30;
            Width := ActivityLog.Width - 4;
            Color := ClWhite;
            Scrollbars := ssBoth;
            FONT.Name := 'Lucida Console';
          end;
        btnCopy := TButton.Create(ActivityLog);
        with btnCopy do
          begin
            Parent := ActivityLog;
            Top := ActivityLog.Height- 27;
            Left := 2;
            Width := 120;
            Height := 25;
            Caption := 'Copy to Clipboard';
            Hint := 'Copy the activity log to the Windows Clipboard.';
            ShowHint := True;
            OnClick := @CopyMemoToClipboard;
          end;
        btnClose := TButton.Create(ActivityLog);
        with btnClose do
          begin
            Parent := ActivityLog;
            Top := ActivityLog.Height - 27;
            Left := ActivityLog.Width - 124;
            Width := 120;
            Height := 25;
            Caption := 'Close';
            Hint := 'Close this window.';
            ShowHint := True;
            Enabled := False;
          end;
      end;

    procedure ActivityLog_SafeInit;
    var
      v: TVariantArray;
    begin
      SetArrayLength(V, 0);
      ThreadSafeCall('ActivityLog_Init', v);
    end;

    procedure ActivityLog_Show;
    begin
      ActivityLog.ShowModal;
    end;

    procedure ActivityLog_SafeShow;
    var
      v: TVariantArray;
    begin
      SetArrayLength(V, 0);
      ThreadSafeCall('ActivityLog_Show', v);
    end;

    procedure WriteLog(LogEntry: string);
      var
        h, m, s, ms: word;
      begin
        DecodeTime(Now(), h, m, s, ms);
        LogMemo.Text := LogMemo.Text + format('[%d:%d:%d.%d] %s',
          [h, m, s, ms, LogEntry]);
      end;

    procedure WriteLnLog(LogEntry: string);
      var
        h, m, s, ms: word;
      begin
        DecodeTime(Now(), h, m, s, ms);
        LogMemo.Text := LogMemo.Text + format('[%d:%d:%d.%d] %s%s',
          [h, m, s, ms, LogEntry, CRLF]);
      end;

    begin
      ActivityLog_SafeInit;
      WriteLnLog('Activity Log Started.');
      ActivityLog_SafeShow;
    end.

    Do I get my answer regarding Show/ShowModal now?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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