Returning 'strings' from a Function

Discussion in 'C-Touch/HomeGate/SchedulePlus/PICED Software' started by dbsoft, Jul 19, 2009.

  1. dbsoft

    dbsoft

    Joined:
    Jul 17, 2008
    Messages:
    6
    Likes Received:
    0
    I am trying to return a string type from a PAC function, however the documentation says it is possible but I am getting Error C120 with the following code when it compiles:-

    function SceneSelect : string;
    begin
    SceneSelect := 'test scene';
    end;

    if string types cannot be returned from a function can anybody help me with the syntax to return an array of char?


    Regards
     
    dbsoft, Jul 19, 2009
    #1
  2. dbsoft

    Darren Senior Member

    Joined:
    Jul 29, 2004
    Messages:
    2,361
    Likes Received:
    0
    Location:
    Adelaide, South Australia
    You need to have the string as a "var" parameter. Here is an example which returns a string of characters:

    Code:
    procedure StringOfChar(n : integer; c: char; var s : String);
    var
      i : integer;
    begin
      s := '';
      for i := 1 to n do
        Append(s, c);
    end;
    You can use this like so:

    Code:
    StringOfChar(5, 'x', s); 
    WriteLn('result = ',s); 
    Which will display:

    result = xxxxx
     
    Darren, Jul 20, 2009
    #2
  3. dbsoft

    dbsoft

    Joined:
    Jul 17, 2008
    Messages:
    6
    Likes Received:
    0
    Ideal as an alternative to using Functions.

    Thanks for the reply
     
    dbsoft, Jul 20, 2009
    #3
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.