SOLVED: Code generates an error after upgraded to FPC 3.2.2 lazarus / 62-General ---------------------------------------------------------------------- JZS · 2021-11-16 14:44 Hello everyone, I just found out that something has changed from FPC 3.2.0 to FPC 3.2.2 that is starting to cause error in a simple app that sends emails through MS Outlook. I believe the changes have taken place in the unit ComObj, but I could be wrong. PS:I do not own this code. Snippet 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 uses comobj, variants; ... procedure TForm1.SendBtnClick(Sender: TObject);const  olMailItem = 0;  olByValue = 1;var  MailItem: OLEVariant;  podatak: OLEVariant;begin  try    Outlook := GetActiveOleObject('Outlook.Application');  except    Outlook := CreateOleObject('Outlook.Application');  end;   namespace := Outlook.GetNamespace('MAPI');  namespace.logon;   MailItem := Outlook.CreateItem(olMailItem);  podatak := 'test@test.com';  MailItem.Recipients.Add(podatak);  MailItem.Recipients.ResolveAll;  podatak := 'Subject';  MailItem.Subject := podatak;  podatak := 'Body Msg';  MailItem.Body := podatak;   MailItem.Display;//send   Outlook := Unassigned;end; This code last worked fine while on FPC 3.2.0 but when upgraded to FPC 3.2.2 it started erroring at the line: MailItem.Subject := podatak; Appreciate if someone can assist in pointing out something (the above code or the FPC code Thank you... ---------------------------------------------------------------------- marcov · 2021-11-16 14:56 Try to assign it to a widestring variable first, and only then to a property. ---------------------------------------------------------------------- af0815 · 2021-11-16 15:02 Compiles here -> Lazarus 2.3.0 rmain-2_3-342-gc44d729ba2 FPC 3.2.3 i386-win32-win32/win64 -> Lazarus 2.0.12 r64642 FPC 3.2.0 i386-win32-win32/win64 without an Problem if i extend 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 var  MailItem: OLEVariant;  podatak: OLEVariant;  Outlook,  namespace: OLEVariant;  I cant run your code, because my PC have never seen Outlook or MS- Office. ---------------------------------------------------------------------- PascalDragon · 2021-11-16 21:28 Quote from: JZS on November 16, 2021, 03:44:05 pmI just found out that something has changed from FPC 3.2.0 to FPC 3.2.2 that is starting to cause error in a simple app that sends emails through MS Outlook. This is a bit hard to debug cause I don't use MS Outlook. Do you by chance use Open- or LibreOffice? Could you in that case try to reproduce the problem using code like the following: 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 program tvartest; {$mode objfpc}{$H+} uses  SysUtils, Variants, ComObj, ActiveX; procedure DoTest;var  App, Instance, Document, Sheet, Cell : OleVariant;  v: OleVariant;  p: String;begin  p := ExtractFilePath(ParamStr(0)) + 'test.xls';  try    Writeln('Creating application');    App := CreateOLEObject('com.sun.star.ServiceManager');    if VarIsNull(App) then      raise Exception.Create('Failed to create App');    Writeln('Creating instance');    Instance := App.createInstance('com.sun.star.frame.Desktop');    if VarIsNull(Instance) then      raise Exception.Create('Failed to create Instance');    Writeln('Loading component');    Document := Instance.loadComponentFromURL('private:factory/scalc', '_blank', 0, VarArrayCreate([0, -1], varVariant));    if VarIsNull(Document) then    raise Exception.Create('Failed to load component');    Writeln('Creating sheet');    Sheet := Document.createInstance('com.sun.star.sheet.Spreadsheet');    if VarIsNull(Sheet) then      raise Exception.Create('Failed to create sheet');    Writeln('Inserting sheet');    Document.Sheets.insertByName('MySheet', Sheet);    Writeln('Retrieving cell');    Cell := Sheet.getCellbyPosition(2, 3);    if VarIsNull(Cell) then      raise Exception.Create('Failed to retrieve cell');    Writeln('Setting cell content');    v := 'Test Text';    Cell.&String := v;    v := Null;    v := Cell.&String;    Writeln('Data: ', VarToStr(v));  except    on e: Exception do      Writeln('Exception (', e.ClassName, '): ', e.Message);  end;end; begin  CoInitializeEx(Nil, COINIT_APARTMENTTHREADED);  try  DoTest;  finally    CoUninitialize;  end;end. Judging by your explanation this should fail at Cell.&String := v. It doesn't for me for 3.2.0 - 3.3.1 however. ---------------------------------------------------------------------- JZS · 2021-11-18 07:40 Quote from: marcov on November 16, 2021, 03:56:53 pmTry to assign it to a widestring variable first, and only then to a property. It worked. 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 podatak: widestring;//OLEVariant; ---------------------------------------------------------------------- JZS · 2021-11-18 07:42 Quote from: af0815 on November 16, 2021, 04:02:50 pmCompiles here -> Lazarus 2.3.0 rmain-2_3-342-gc44d729ba2 FPC 3.2.3 i386-win32-win32/win64 -> Lazarus 2.0.12 r64642 FPC 3.2.0 i386-win32-win32/win64 without an Problem I should have mentioned it errors at executing not at compiling. ---------------------------------------------------------------------- JZS · 2021-11-18 07:46 Quote from: PascalDragon on November 16, 2021, 10:28:51 pmQuote from: JZS on November 16, 2021, 03:44:05 pmI just found out that something has changed from FPC 3.2.0 to FPC 3.2.2 that is starting to cause error in a simple app that sends emails through MS Outlook. This is a bit hard to debug cause I don't use MS Outlook. Do you by chance use Open- or LibreOffice? Could you in that case try to reproduce the problem using code like the following: 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 program tvartest; {$mode objfpc}{$H+} uses  SysUtils, Variants, ComObj, ActiveX; procedure DoTest;var  App, Instance, Document, Sheet, Cell : OleVariant;  v: OleVariant;  p: String;begin  p := ExtractFilePath(ParamStr(0)) + 'test.xls';  try    Writeln('Creating application');    App := CreateOLEObject('com.sun.star.ServiceManager');    if VarIsNull(App) then      raise Exception.Create('Failed to create App');    Writeln('Creating instance');    Instance := App.createInstance('com.sun.star.frame.Desktop');    if VarIsNull(Instance) then      raise Exception.Create('Failed to create Instance');    Writeln('Loading component');    Document := Instance.loadComponentFromURL('private:factory/scalc', '_blank', 0, VarArrayCreate([0, -1], varVariant));    if VarIsNull(Document) then    raise Exception.Create('Failed to load component');    Writeln('Creating sheet');    Sheet := Document.createInstance('com.sun.star.sheet.Spreadsheet');    if VarIsNull(Sheet) then      raise Exception.Create('Failed to create sheet');    Writeln('Inserting sheet');    Document.Sheets.insertByName('MySheet', Sheet);    Writeln('Retrieving cell');    Cell := Sheet.getCellbyPosition(2, 3);    if VarIsNull(Cell) then      raise Exception.Create('Failed to retrieve cell');    Writeln('Setting cell content');    v := 'Test Text';    Cell.&String := v;    v := Null;    v := Cell.&String;    Writeln('Data: ', VarToStr(v));  except    on e: Exception do      Writeln('Exception (', e.ClassName, '): ', e.Message);  end;end; begin  CoInitializeEx(Nil, COINIT_APARTMENTTHREADED);  try  DoTest;  finally    CoUninitialize;  end;end. Judging by your explanation this should fail at Cell.&String := v. It doesn't for me for 3.2.0 - 3.3.1 however. Do not have Open/LibreOffice ATM. Will give it a try some time in the near future.