Results 1 to 9 of 9

Thread: Can you open a file with a form open?

  1. #1
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default Can you open a file with a form open?

    Is it possible to open a file while a form is open?

    I remember there was some ghetto hax thing that @Brandon; did with writeln a long time ago but can't find it and I don't know if it applies to opening files

  2. #2
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default

    I don't know the answer to be honest, but we could make a short sample script to test it, right? If someone else doesn't give you a definitive answer soon I'll try to make a short test. I feel like the answer is going to be no though for some reason. Kind of like how the code pauses at ReadLn, until VK_RETURN is hit. But I'll still give it a test anyway. If it turns out being no, you could always add a Button to your form that is open and OnClick, it opens the file.


    EDIT: I may be wrong, because I don't have the most experience with forms and files in SRL, (I have some experience with forms, and some experience with files in Java, just started doing file work in Pascal yesterday) but when I edited my AlarmClock/Timer program (which has a form) I added writeln('open file') and OpenFile codes after my ShowForm in main loop. The writeln was never executed until the form was closed. So I'm guessing your best bet would be to just add a button to your form to execute the OpenFile code.

    But like I said, I could be wrong. I don't have the most experience here and I did a really short, quick test.
    Last edited by Baked0420; 02-11-2016 at 09:58 AM.

  3. #3
    Join Date
    Dec 2013
    Location
    Pitcairn Island
    Posts
    288
    Mentioned
    20 Post(s)
    Quoted
    166 Post(s)

    Default

    Quote Originally Posted by Baked0420 View Post
    I don't know the answer to be honest, but we could make a short sample script to test it, right? If someone else doesn't give you a definitive answer soon I'll try to make a short test. I feel like the answer is going to be no though for some reason. Kind of like how the code pauses at ReadLn, until VK_RETURN is hit. But I'll still give it a test anyway. If it turns out being no, you could always add a Button to your form that is open and OnClick, it opens the file.


    EDIT: I may be wrong, because I don't have the most experience with forms and files in SRL, (I have some experience with forms, and some experience with files in Java, just started doing file work in Pascal yesterday) but when I edited my AlarmClock/Timer program (which has a form) I added writeln('open file') and OpenFile codes after my ShowForm in main loop. The writeln was never executed until the form was closed. So I'm guessing your best bet would be to just add a button to your form to execute the OpenFile code.

    But like I said, I could be wrong. I don't have the most experience here and I did a really short, quick test.
    RJ is referring to the access violations you get when attempting to read/write files when a form is currently open. It is because of the way Simba handles threads.

    There are a few ways around it, by going through the client:

    Simba Code:
    program new;

    var
      Form: TForm;
      Btn: TButton;
      Str: String;

    procedure Listener(Sender: TObject); native;
    var
      MyFile: Integer;
    begin
      MyFile := Client.GetMFiles().OpenFile(IncludePath + 'srl-6\lib\interfaces\bankscreen.aca',true);
      Client.GetMFiles().ReadFileString(MyFile, Str, Client.getMFiles().FileSizeMuf(MyFile));
    end;

    procedure LoadForm(); native;
    begin
      Form.Init(nil);
      with Form do
      begin
        setWidth(280);
        setHeight(250);
        setPosition(poScreenCenter);
        setBorderStyle(bsSingle);
      end;

      Btn.Init(Form);
      with (Btn) do
      begin
        setParent(Form);
        setBounds(8, 211, 262, 30);
        setCaption('Open File');
        setOnClick(Listener);
      end;

      try
        Form.ShowModal();
      except
      finally
        Form.free();
      end;
    end;

    begin
      Sync(LoadForm);
      WriteLn(Str);
    end.

  4. #4
    Join Date
    Jun 2012
    Posts
    586
    Mentioned
    112 Post(s)
    Quoted
    296 Post(s)

    Default

    eZForm does it. TFileStream.




    Skype: obscuritySRL@outlook.com

  5. #5
    Join Date
    Sep 2010
    Posts
    5,762
    Mentioned
    136 Post(s)
    Quoted
    2739 Post(s)

    Default

    Quote Originally Posted by Obscurity View Post
    eZForm does it. TFileStream.
    Ahh yes this is what I was looking for thanks.

    That includes read/write right?

  6. #6
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default

    I don't think you need EZForm to use TFileStream. My code completion shows TFileStream and I don't have EZForm on my computer anymore.

    And whenever my form calls my Timer procedure, just like a timer that loops X-minutes than plays a sound (called from buttonclick), it says "Something went wrong in Simba..." and see error log. But when I take the repeat/until loop out, then the error doesn't happen but the procedure doesn't do what it's supposed to. Does TFileStream fix this problem?

  7. #7
    Join Date
    Dec 2011
    Location
    East Coast, USA
    Posts
    4,231
    Mentioned
    112 Post(s)
    Quoted
    1869 Post(s)

    Default

    Quote Originally Posted by Baked0420 View Post
    I don't think you need EZForm to use TFileStream.
    You don't. However I don't think Obs was implying that ezForm provided TFileStream, just that it utilized it.

    Source: was using TFileStream yesterday without any includes.
    GitLab projects | Simba 1.4 | Find me on IRC or Discord | ScapeRune scripts | Come play bot ScapeRune!

    <BenLand100> we're just in the transitional phase where society reclassifies guns as Badâ„¢ before everyone gets laser pistols

  8. #8
    Join Date
    Feb 2011
    Location
    The Future.
    Posts
    5,600
    Mentioned
    396 Post(s)
    Quoted
    1598 Post(s)

    Default

    Quote Originally Posted by Baked0420 View Post
    I don't think you need EZForm to use TFileStream. My code completion shows TFileStream and I don't have EZForm on my computer anymore.

    And whenever my form calls my Timer procedure, just like a timer that loops X-minutes than plays a sound (called from buttonclick), it says "Something went wrong in Simba..." and see error log. But when I take the repeat/until loop out, then the error doesn't happen but the procedure doesn't do what it's supposed to. Does TFileStream fix this problem?
    No because the timer and the loop might be on a different thread? Also you should access the file via client. Simba has absolutely awful threading issues.
    I am Ggzz..
    Hackintosher

  9. #9
    Join Date
    Jun 2012
    Posts
    586
    Mentioned
    112 Post(s)
    Quoted
    296 Post(s)

    Default





    Skype: obscuritySRL@outlook.com

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
  •