2014-06-06 26 views
-5

直升機,我有以下的東西:selectedPanel應該得到的點擊面板對象,如果被點擊的形式,selectedPanel應該是「空」,虛無縹緲,空洞等:)在Delphi中,我可以如何設置TPanel變量類型爲空?

var 
    selectedBlock: Tpanel; <== fixed typo 

... 

procedure TForm1.stubPanelMouseDown(Sender: TObject... 
begin 

    ... 

    Panel:= Sender as TPanel; 

    if (*selectedBlock is not null*) then 
    begin 
      // ie, store the current panel 
      selectedBlock:= Panel; 
    end 
    else 
    begin 
      // empty the selection 
      *selectedBlock:= null*; 
    end; 

所以,問題是:我如何將該變量設置爲「null」?做selectedBlock:=未分配會引發錯誤。

感謝

編輯:這仍然拋出一個錯誤:訪問衝突

if (selectedBlock=nil) then <= fixed and works 
    begin 
    selectedBlock:= Panel; 
    end 
    else 
    begin 
    selectedBlock:= nil; 
end; 
+0

錯誤「未定義標識符'selectedBlock'」?那是因爲你已經宣佈它爲'selectedPanel'。 –

+0

不,當使用Unassigned時,錯誤是:「不兼容的類型:'TPanel'和'Variant' –

+2

你在這裏有一些奇怪的片段if selectedBlock = nil then selectedBlock:= nil –

回答

5

指針都爲 「零」 使用常數設置:

selectedBlock := nil; 

Null是特殊值僅適用於VariantOleVariant

+0

它仍然拋出一個訪問衝突錯誤,當我做的代碼我添加到原來的帖子... –

+1

看來,你有兩個變量:'selectedBlock''''selectedPanel',你不小心使用了一個,當你的意思是其他的。 –

+0

shooo!對不起,我在這裏打錯了代碼......它可以在項目中仍然是虛無:(:(:( –

相關問題