2013-06-20 35 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

相關問題