{"id":393,"date":"2008-05-01T01:13:11","date_gmt":"2008-05-01T01:13:11","guid":{"rendered":"http:\/\/6teen.ru\/?p=371"},"modified":"2008-05-01T01:13:11","modified_gmt":"2008-05-01T01:13:11","slug":"1052","status":"publish","type":"post","link":"http:\/\/pblog.ru\/lab\/?p=393","title":{"rendered":"\u041a\u0430\u043a \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Microsoft Word"},"content":{"rendered":"<p>\u041a\u0430\u043a \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Microsoft Word<br \/>\n<!--more--><\/p>\n<pre class=\"alt2\" style=\"margin:0px; padding:6px; border:1px inset; width:580px; height:320px; overflow:auto\"><div>\u041a\u0430\u043a \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Microsoft Word\n\n\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043c\u043e\u0434\u0443\u043b\u044c, \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u044f \u0438 \u0432\u044b\u0437\u043e\u0432\n...\npublic\n{ public declarations }\nfwordapp: _application;\nfworddoc: _document;\nfwordsink: twordconnection;\n...\n\nprocedure startwordconnection(wordapp: _application;\nworddoc: _document;\nvar wordsink: twordconnection);\nvar\npointcontainer: iconnectionpointcontainer;\npoint: iconnectionpoint;\nbegin\ntry\n\/\/ twordconnection is the com object which receives the\n\/\/ notifications from word. make sure to free wordsink when\n\/\/ you are done with it.\nwordsink := twordconnection.create;\nwordsink.wordapp := wordapp;\nwordsink.worddoc := worddoc;\n\n\/\/ sink with a word application\nolecheck(wordapp.queryinterface(iconnectionpointcontainer, pointcontainer));\nif assigned(pointcontainer) then begin\nolecheck(pointcontainer.findconnectionpoint(applicationevents, point));\nif assigned(point) then\npoint.advise((wordsink as iunknown), wordsink.appcookie);\nend;\n\n\/\/ sink with a word document advise\nolecheck(worddoc.queryinterface(iconnectionpointcontainer, pointcontainer));\nif assigned(pointcontainer) then begin\nolecheck(pointcontainer.findconnectionpoint(documentevents, point));\nif assigned(point) then\npoint.advise((wordsink as iunknown), wordsink.doccookie);\nend;\n\nexcept\non e: exception do showmessage(e.message);\nend;\nend;\n\nprocedure tmainform.btnstartclick(sender: tobject);\nbegin\nfwordapp := coapplication_.create;\nfworddoc := fwordapp.documents.add(emptyparam, emptyparam);\nfwordapp.visible := true;\nstartwordconnection( fwordapp, fworddoc, fwordsink );\nend;\n\nprocedure tmainform.btnexitclick(sender: tobject);\nbegin\nfwordapp.quit(emptyparam, emptyparam, emptyparam);\nend;\n\u00a6?o?U? \u043e\u0442\u0441\u043b\u0435\u0436\u0438\u0432\u0430\u043d\u0438\u044f \u043b\u0438\u043d\u043a\u043e\u0432\nunit connectionobject;\ninterface\n\nuses word_tlb, dialogs;\n\ntype\n\ntwordconnection = class(tobject, iunknown, idispatch)\nprotected\n\n{iunknown}\nfunction queryinterface(const iid: tguid; out obj): hresult; stdcall;\nfunction _addref: integer; stdcall;\nfunction _release: integer; stdcall;\n\n{ idispatch }\nfunction getidsofnames(const iid: tguid; names: pointer;\nnamecount, localeid: integer; dispids: pointer): hresult; stdcall;\nfunction gettypeinfo(index, localeid: integer; out typeinfo): hresult; stdcall;\nfunction gettypeinfocount(out count: integer): hresult; stdcall;\nfunction invoke(dispid: integer; const iid: tguid; localeid: integer;\nflags: word; var params; varresult, excepinfo, argerr: pointer): hresult; stdcall;\n\npublic\nwordapp: _application;\nworddoc: _document;\nappcookie, doccookie: integer;\nend;\n\nimplementation\n\n{ iunknown methods }\n\nuses windows, activex, main;\n\nprocedure logcomment(comment: string);\nbegin\nform1.memo1.lines.add(comment);\nend;\n\nfunction twordconnection._addref: integer;\nbegin\nresult := 2;\nend;\n\nfunction twordconnection._release: integer;\nbegin\nresult := 1;\nend;\n\nfunction twordconnection.queryinterface(const iid: tguid;\nout obj): hresult;\nbegin\nresult := e_nointerface;\npointer(obj) := nil;\nif (getinterface (iid, obj)) then result := s_ok;\nif not succeeded (result) then\nif (isequaliid(iid, documentevents) or isequaliid(iid, applicationevents))\nthen if (getinterface(idispatch, obj)) then result := s_ok;\nend;\n\n{ idispatch methods }\n\nfunction twordconnection.getidsofnames(const iid: tguid; names: pointer;\nnamecount, localeid: integer; dispids: pointer): hresult;\nbegin\nresult := e_notimpl;\nend;\n\nfunction twordconnection.gettypeinfo(index, localeid: integer;\nout typeinfo): hresult;\nbegin\npointer(typeinfo) := nil;\nresult := e_notimpl;\nend;\n\nfunction twordconnection.gettypeinfocount(out count: integer): hresult;\nbegin\ncount := 0;\nresult := e_notimpl;\nend;\n\nfunction twordconnection.invoke(dispid: integer; const iid: tguid;\nlocaleid: integer; flags: word; var params; varresult, excepinfo,\nargerr: pointer): hresult;\nbegin\n\/\/this is the entry point for word event sinking\nresult := s_ok;\ncase dispid of\n1: ; \/\/ startup\n2: showmessage( 'quit' ); \/\/ quit\n3: ; \/\/ document change\n4: ; \/\/ new document\n5: ; \/\/ open document\n6: showmessage( 'close' ); \/\/ close document\nelse result := e_invalidarg;\nend;\nend;\n\nend.\n\u0411\u043ep\u0438\u0441\u043e\u0432 \u041e\u043b\u0435\u0433 h\u0438\u043a\u043e\u043b\u0430\u0435\u0432\u0438\u0447\n<\/div><\/pre>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041a\u0430\u043a \u043e\u0442\u0441\u043b\u0435\u0434\u0438\u0442\u044c \u043e\u0442\u043a\u0440\u044b\u0442\u0438\u0435 \u0438 \u0437\u0430\u043a\u0440\u044b\u0442\u0438\u0435 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438 Microsoft Word<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[416,432],"tags":[1093,547,1307,735,1517,1527,930],"_links":{"self":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/393"}],"collection":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=393"}],"version-history":[{"count":0,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=\/wp\/v2\/posts\/393\/revisions"}],"wp:attachment":[{"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=393"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/pblog.ru\/lab\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}