2013-06-20 39 views
0

我有一个函数来获取一个随机的URL。将函数的结果添加到字符串作为变量 - SAM广播器

FUNCTION randurl : String; 
BEGIN 
    // Randomize URL 
    Rx2 := RandomInt(4); 
    if (Rx = 0) then 
    result := 'www.site1.com' 
    else if (Rx2 = 1) then 
    result := 'www.site2.com' 
    else if (Rx2 = 2) then 
    result := 'www.site3.com' 
    else if (Rx2 = 3) then 
    result := 'www.site4.com'; 
END; 

我正在编译字符串...

var  Rx2 : integer; 

{Declaration (Functions and Procedures)} 
// Construct the GET String for the Web Script, call it and return the output 
PROCEDURE update(status : String); forward; 

BEGIN 
    // Message to display in twitter 
    statusmessage := '#Nowplaying ' + Song['artist'] + ' - ' + Song['title'] + ' @ ' + $FUNCTION_OUTPUT_VARIABLE + ' #' + Song['genre']; 
    update(statusmessage); 
    END; 
END; 

其中$ FUNCTION_OUTPUT_VARIABLE以上,我需要随机URL被包括在内。如何调用函数,然后在代码的每次传递中插入输出?

非常感谢!

编辑:

下面是我用上述的功能去解决。

{Declaration (Variables)} 

var  Rx2 : integer; 

FUNCTION randurl : String; forward; 

    BEGIN 
    // Message to display in twitter 
    statusmessage := '#Nowplaying ' + Song['artist'] + ' - ' + Song['title'] + ' @ ' + randurl + ' #' + Song['genre']; 
    update(statusmessage); 
    END; 
END; 
+0

这不是德尔福。它是什么? –

+0

它是PAL,来自基于Pascal/Delphi的SAM广播公司的语言。它具有定制的对象,但有很多相似之处。我不是一个编码器,但据我所知,在字符串中作为变量来获取函数遵循相同的语法/方法。你在这里看到的是连接。我只想在每次传递中将所述函数的结果作为变量放入。希望这是有道理的。 –

+0

你的意思是你不能用randurl替换$ FUNCTION_OUTPUT_VARIABLE? –

回答

2

我不知道的语言PAL,这里是如何,将在德尔福工作的两个变种:

第一:

var 
    tmp: String; 
begin 
    tmp := randurl; 
    statusmessage := '#Nowplaying ' + Song['artist'] + ' - ' + Song['title'] + 
     ' @ ' + tmp + ' #' + Song['genre']; 

    update(statusmessage); 
    end; 
end; 

二:

begin 
    statusmessage := '#Nowplaying ' + Song['artist'] + ' - ' + Song['title'] + 
     ' @ ' + randurl + ' #' + Song['genre']; 

    update(statusmessage); 
    end; 
end; 
+0

我试过第二个,这对我有意义。但它说“未知的名字randurl”。我必须先调用函数吗?我怎么做? –

+0

好吧,我明白了。我使用了第二种解决方案,并在脚本开始时定义了该功能。我会在上面添加我的解决方案。谢谢! –

+0

在delphi中,您需要先定义一个过程,然后才能调用它。您可以在使用类时在“interface”或“implementation”下包含单元,或使用“forward”定义前向声明。 – 2013-06-20 10:58:14

相关问题