I am using firemonkey, delphi, community edition. I have a form with a button and a listview component. On clicking the button the program executes a procedure (form13.exportlistviewtoword(listview1)) that opens ms word and displays the contents of the listview in the ms word window. Unfortunately, on clocking the button ms-word opens as it should but the following message appears: Method ‘listview’ not supported by automation object. Can someone tell me where I’ve gone wrong (and provide a fix!).
The program code is:
unit Unit13;
interface
uses
fmx.platform,System.SysUtils, System.Types, System.UITypes,
System.Classes,
System.Variants,FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics,
FMX.Dialogs,
FMX.StdCtrls, FMX.Objects, FMX.Edit, FMX.ListBox,
FMX.Controls.Presentation,
FMX.ListView.Types, FMX.ListView.Appearances,
FMX.ListView.Adapters.Base,
FMX.ListView,system.strutils, FMX.Menus, FMX.Layouts,activex,comobj;
type
TForm13 = class(TForm)
ListView1: TListView;
Button1: TButton;
procedure Button1Click(Sender: TObject);
public
procedure exportlistviewtoword(listview:Tlistview);
end;
var
Form13: TForm13;
implementation
{$R *.fmx}
procedure TForm13.Button1Click(Sender: TObject);
begin
form13.exportlistviewtoword(listview1);
end;
procedure tform13.exportlistviewtoword(listview:Tlistview);
var
wordApp,worddoc,wordtable:olevariant;
i,j:integer;
item:tlistviewitem;
subitemtext:string;
begin
try
olecheck(coinitialize(nil));
wordapp:=createoleobject('Word.Application');
wordapp.visible:=true;
worddoc:=wordapp.documents.add;
''''wordtable:=worddoc.tables.add(worddoc.paragraphs.item(1).range.listview.items.count,2);
for I :=0 to listview1.Items.Count-1 do
begin
item:=listview1.Items[I];
wordtable.cell(I+1,1).range.text:= item.text;
subitemtext:=item.Detail;
if item.Detail<>''then
wordtable.cell(I+1,2).range.text:=subitemtext;
end;
finally
couninitialize;
end;
end;
end.