-4

I have the following code

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;

running on a column in a cxGrid. But for some reason that I simply can't figure out the line

if VarToStr(aValue) <> '' then

makes the function crash. I know that it is when aValue becomes a Null value but as far as I can figure out the VarToStr should return '' in this case

OZ8HP
  • 1,443
  • 4
  • 31
  • 61
  • 4
    "makes the function crash" doesn't help much. Please provide full error messages. – David Heffernan Feb 19 '13 at 14:16
  • It actually doesn't give any message - it just stops the program and displays the source of a Eurekalog unit called ELowLevel in procedure DebugBreak – OZ8HP Feb 19 '13 at 18:17
  • @OZ8HP This is still critical information which we need to know in order to be of any help to you. – Jerry Dodge Feb 19 '13 at 19:55
  • I would love to give a message but there is none. And now the question is closed being too localized. I don't get it. I will try somewhere else then. – OZ8HP Feb 20 '13 at 05:44
  • But what I want to do is to set the caption of a button in a column based on the value of another column - if the column contains data the button should have one text and if not then it should have another text – OZ8HP Feb 20 '13 at 07:50

1 Answers1

6

The aValue is probably not NULL but empty. Try to use check like

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

instead. Or

if VarIsEmpty(aValue) or VarIsNull(aValue) then
ain
  • 22,394
  • 3
  • 54
  • 74
  • Actually if VarToStr(aValue) = '' then works OK - it looks like it is the colMaint.Properties.Buttons[0].Caption := 'Opret' that crashes the app – OZ8HP Feb 19 '13 at 19:12