Results 1 to 9 of 9

Thread: "Scripting" language

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Hi Luuk, nice work

    I just looked at your code, rather neat.

    I have coded an extra Params() function for a variable amount of params that you could use instead of using the multiple functions if you wish...

    Code:
    function Params(const p: array of TParam): TParams; overload;
    
    
    implementation
    
    {...}
    
    
    function Params(const p: array of TParam): TParams; overload;var
      i: Integer;
    begin
      setLength(Result,Length(p));
      for i := 0 to High(p) do
        result[i] := p[i];
    end;
    You would use it like so (adding any amount of params to the 'list' between the '[' and ']'):

    Code:
    Command('SetValues', @SetValues, Params([p(PT_BOOL), p(PT_INT), p(PT_FLOAT), p(PT_STR)]));
    cheers,
    Paul

  2. #2
    Thank paul Made the following changes.

    - Unlimited parameters (Thanks to Pauls suggestion.)
    - Again less and cleaner code
    - Streamlined the error messaging

    I think the code is as streamlined and optimised as can be now so this is probably the final version

    Regards,
    Luuk
    Attached Files Attached Files

  3. #3
    There are some little things you could clean, that compiler still tells

    ignore? - scripting.pas(81,27) Hint: Local variable "c" does not seem to be initialized
    *see below 1) - scripting.pas(212,16) Warning: Local variable "str" does not seem to be initialized
    ignore? - scripting.pas(238,36) Hint: Local variable "c" does not seem to be initialized
    remove - scripting.pas(133,3) Note: Local variable "com" not used
    remove - Unit1.pas(36,23) Hint: Parameter "params" not used
    remove - Unit1.pas(41,29) Hint: Parameter "params" not used
    ignore? - Unit1.pas(63,33) Hint: Local variable "freq" does not seem to be initialized
    ignore? - Unit1.pas(64,32) Hint: Local variable "start" does not seem to be initialized
    ignore? - Unit1.pas(66,31) Hint: Local variable "stop" does not seem to be initialized
    remove - Unit1.pas(6,12) Hint: Unit "messages" not used in Unit1
    remove - ScriptingTest.lpr(12,15) Warning: Symbol "MainFormOnTaskBar" is not portable

    1) Line is str := str + script[i]; where str was not initialized (meaning str := ''; ). It could be that compiler nulls dynamic arrays and strings, but i'm not sure if it does on all possible fpc compilers and their settings.

    Lots of 'Local variable X does not seem to be initialized' could be rid of by changing "var" to "out", but i just recently read that fpc might allocate that parameter for itself, instead of using the parameter reference... That might slow down performance slightly if so.
    edit: In my test app var, out and pointer perform pretty much the same. I had 1 parameter record with 1kb data.
    Last edited by User137; 24-07-2013 at 08:46 PM.

  4. #4
    Hint: Local variable "c" does not seem to be initialized
    This usually happens when you are accesing your variable only from within if statements, case statements and while loops. The reason for this is that under certain circumstances theese variables arent even used so compiler optimization sometimes doesn't even initalize them which can result in AccesViolation or weird values of theese varaibles.
    I usually circumvent this by seting some default value to theese variables in the first few lines of the method in which they are declared.

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
  •