1 2 //--------------------------------------------------------------------------- 3 4 #include <vcl.h> 5 #pragma hdrstop 6 #include <sysvari.h> 7 #include <ComObj.hpp> 8 #include <Clipbrd.hpp> 9 #include "Unit1.h" 10 //--------------------------------------------------------------------------- 11 #pragma package(smart_init) 12 #pragma link "Word_2K_SRVR" 13 #pragma resource "*.dfm" 14 TForm1 *Form1; 15 //--------------------------------------------------------------------------- 16 __fastcall TForm1::TForm1(TComponent* Owner) 17 : TForm(Owner) 18 { 19 } 20 //--------------------------------------------------------------------------- 21 22 void __fastcall TForm1::Button1Click(TObject *Sender) 23 { 24 TStringList* sl= new TStringList(); 25 TClipboard *SysClip = new TClipboard(); 26 try 27 { 28 try 29 { 30 WordApplication->Connect(); 31 } 32 catch (Exception &exception) 33 { 34 MessageDlg("Word may not be installed", mtError, TMsgDlgButtons() << mbYes, 35 0); 36 Abort; 37 } 38 WordApplication->GetDefaultInterface()->Visible = true; 39 WordApplication->set_Caption(StringToOleStr("DevSuperPage.com")); 40 //Create new document 41 //Turn Spell checking off because it takes a long time if enabled and slows 42 down Winword 43 WordApplication->Options->CheckSpellingAsYouType = false; 44 WordApplication->Options->CheckGrammarAsYouType = false; 45 sl->LoadFromFile("c:\\test.txt"); 46 SysClip->AsText =sl->Text; 47 SysClip->Free(); 48 sl->Free(); 49 WordDocument->Sentences->Last->Paste(); 50 51 52 } 53 catch (Exception &exception) 54 { 55 Application->ShowException(&exception); 56 WordApplication->Disconnect(); 57 } 58 59 } 60 //---------------------------------------------------------------------------