Recent

Author Topic: Lazarus 3.x: OLE Error setting MS Word Document Page Layout  (Read 260 times)

Ralle80

  • Newbie
  • Posts: 1
Lazarus 3.x: OLE Error setting MS Word Document Page Layout
« on: October 14, 2024, 01:15:51 pm »
Hi everyone,

Lazarus gives a "EOleException" (Screenshot attached) when trying to set the Page Layout (Left Margin) of a newly created Word (2013) Document. Error is only present in 3.x Versions - program runs fine in 2.0.12. Error message would be translated "LeftMargin is not a reference property".

Code: Pascal  [Select][+][-]
  1. unit OleError;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ComObj;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Button1: TButton;
  16.     procedure Button1Click(Sender: TObject);
  17.   private
  18.  
  19.   public
  20.  
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.   WdApp,Dokument:OleVariant;
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. procedure TForm1.Button1Click(Sender: TObject);
  33. var oleVar:OleVariant;
  34. begin
  35.  WdApp := CreateOleObject('Word.Application');
  36.  WdApp.Visible := True;
  37.  Dokument := WdApp.Documents.Add;
  38.  Dokument.Activate;
  39.  oleVar := 36;Dokument.PageSetup.LeftMargin := oleVar;
  40. end;
  41.  
  42. end.

Anyone know how to solve that ? Thanks !


 

TinyPortal © 2005-2018