2013-02-19 43 views
-3

我有以下代碼爲什麼這是錯

procedure TfrmJsApplications.colMaintStylesGetContentStyle(
    Sender: TcxCustomGridTableView; ARecord: TcxCustomGridRecord; 
    AItem: TcxCustomGridTableItem; out AStyle: TcxStyle); 
var 
    aColumn: TcxCustomGridTableItem; 
    aValue: Variant; 
begin 
    inherited; 
    try 
    aColumn := Sender.FindItemByName('colApplication_Doc'); 
    aValue := aRecord.Values[aColumn.Index]; 
    if VarToStr(aValue) <> '' then 
     colMaint.Properties.Buttons[0].Caption := 'Redigere' 
    else 
     colMaint.Properties.Buttons[0].Caption := 'Opret' 
    except 
    on E:exception do 
     Logfile.Error('F_JsApplications.colMaintStylesGetContentStyle: ' + E.Message); 
    end; 

在一個cxGrid一列運行。 但由於某些原因,我根本無法弄清楚行

if VarToStr(aValue) <> '' then 

使功能崩潰。 我知道,這是在安勤成爲一個空值,但據我可以計算出VarToStr應該在這種情況下

+4

「使功能崩潰」沒有多大幫助。請提供完整的錯誤消息。 – 2013-02-19 14:16:41

+0

它實際上並沒有給出任何消息 - 它只是停止程序,並在過程DebugBreak – OZ8HP 2013-02-19 18:17:11

+0

@ OZ8HP中顯示名爲ELowLevel的Eurekalog單元的源這仍然是我們需要知道的重要信息,以便對您有所幫助。 – 2013-02-19 19:55:38

回答

6

aValue返回「」可能不是NULLempty。嘗試使用支票,如

if(FindVarData(aValue)^.VType in [varNull, varEmpty])then ... 

改爲。或

if VarIsEmpty(aValue) or VarIsNull(aValue) then 
+0

其實 如果VarToStr(aValue)=''然後 工作正常 - 它看起來像是 colMaint.Properties.Buttons [0] .Caption:='Opret' 崩潰了應用程序 – OZ8HP 2013-02-19 19:12:10