OLEVariants problem lazarus / 16-Databases ---------------------------------------------------------------------- daveinhull · 2019-02-18 07:54 Hi, I have a problem with an OLEVariant (connects to Excel). When I cloase a particualr form I want to make sure that the Excel object is also closed, so I have used Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i If ExcelServer <> Unassigned thenbegin  ExcelServer.ActiveWorkbook.Close (False);  if ExcelServer.Workbooks.Count = 0 then    ExcelServer.Quit;    ExcelServer := Unassigned;  end.... Which is ok if the ExcelServer was never assigned during the program execution, i.e. the user didn't want to do anything with Excel. However, it fails with an "Invalid Variant Operation Displatch = Empty" message if I actually do setup a link to Excel. If I change the code Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if ExcelServer <> Null then it also fails. Anybody got any thoughts in this? Dave ---------------------------------------------------------------------- rvk · 2019-02-18 11:32 Maybe Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if not VarIsEmpty(ExcelServer) then ---------------------------------------------------------------------- Thaddy · 2019-02-18 13:16 I expected VarNull or VarEmpty ---------------------------------------------------------------------- rvk · 2019-02-18 13:48 VarIsEmpty checks for VarEmpty. It's just a wrapper for the check. You shouldn't check for VarEmpty directory. QuoteVarIsEmpty returns true if the given variant contains the value Unassigned. So to make sure you could also do Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if not VarIsNullthen(ExcelServer) and not VarIsEmpty(ExcelServer) then //... O yeah, to make it more confusing there is also VarIsClear() Also note the function: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function VarIsEmpty(const V: Variant): Boolean;begin  Result:=TVarData(V).vType=varEmpty;end; So that's something different from Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if Variant <> varEmpty then ... // <-- incorrect SoCheck for unassigned with VarIsEmpty.Check for an undefined value with VarIsClear.Check for a null value with VarIsNull. ---------------------------------------------------------------------- daveinhull · 2019-02-19 01:56 Thanks guys, This worked Quote from: rvk on February 18, 2019, 12:32:12 pmMaybe Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if not VarIsEmpty(ExcelServer) then And thanks for the other info as well, all useful learning  Dave