Select the product you need help with
ใช้การรวมก่อนหน้าและการรวมภายหลังในการทำงานอัตโนมัติหมายเลขบทความ (Article ID): 245115 - ผลิตภัณฑ์ที่เกี่ยวข้องในบทความนี้ เนื้อหาบนหน้านี้สรุปวิธีการที่คุณผูกกับเซิร์ฟเวอร์ Automation ส่งผลต่อสิ่งต่าง ๆ หลายอย่างในโปรแกรมของคุณ เช่นประสิทธิภาพ ความยืดหยุ่น และ maintainability บทความนี้อธิบายถึงชนิดของการผูกอยู่กับเครื่องไคลเอนต์ในการทำงานอัตโนมัติ และ weighs ทั้งสองข้างของแต่ละวิธี ข้อมูลเพิ่มเติมดำเนินการอัตโนมัติกระบวนการและ/ที่คอมโพเนนต์ซอฟต์แวร์หนึ่งสื่อสารกับ หรือควบคุมคอมโพเนนต์ซอฟต์แวร์อื่นที่ใช้ของ Microsoft ที่มีรูปแบบวัตถุคอมโพเนนต์ (COM) มีพื้นฐานสำหรับการสื่อสารคอมโพเนนต์หว่างส่วนใหญ่ที่ใช้ในภาษาเช่น Visual Basic หรือ Visual Basic สำหรับโปรแกรมประยุกต์ และกลาย เป็นส่วนหนึ่งปกติของโปรแกรมส่วนใหญ่ historically วัตถุ Automation เป็นวัตถุที่สนับสนุนการ IDispatch อินเทอร์เฟซ อินเทอร์เฟซนี้อนุญาตให้ไคลเอ็นต์ในการเรียกวิธี และสื่อคุณสมบัติในขณะที่ดำเนินการโดยไม่จำเป็นต้องทราบวัตถุที่แน่นอนพวกเขาเป็นสารกับเวลาในการออกแบบ กระบวนการเรียกว่าการรวมภายหลัง วันนี้ อย่างไรก็ตาม ระยะเวลาวัตถุการดำเนินการอัตโนมัติสามารถถูกประยุกต์ใช้กับวัตถุใด ๆ แบบเสมือนจริง COM แม้แต่รายการที่ไม่สนับสนุนการ IDispatch (และจึง ไม่สามารถล่าช้าผูก) บทความนี้อนุมานทั้งสองวิธีการรวมสนับสนุนวัตถุคุณกำลัง Automating สิ่งที่ถูกผูกได้หรือไม่ผูกเป็นกระบวนการของการเรียกฟังก์ชันที่เขียน โดยโปรแกรมเมอร์เมื่อต้องการรหัสที่แท้จริง (ภายใน หรือภายนอก) ที่ใช้ฟังก์ชันที่ตรงกัน คุณจะดำเนินการเมื่อมีการคอมไพล์แอพลิเคชัน และฟังก์ชันทั้งหมดที่เรียกว่าในรหัสต้องถูกผูกไว้ก่อนที่สามารถดำเนินการรหัสเมื่อต้องการทำความเข้าใจเกี่ยวกับกระบวนการ คิดของ "ผูก" ในเงื่อนไขของการประกาศในสมุดบัญชี สมมติรหัสของคุณจะเหมือนกับข้อความของสมุดบัญชีซึ่งในย่อหน้าที่แน่นอน คุณได้เขียนบางเหมือน "ดูบทที่ 12 หน้า x สำหรับรายละเอียดเพิ่มเติม" คุณไม่ทราบหมายเลขหน้าคืออะไรจนกว่าสมุดบัญชีเสร็จเรียบร้อยแล้ว ดังนั้นก่อนย่อหน้าสามารถอ่านตามวัตถุประสงค์ เพจทั้งหมดของสมุดบัญชีต้องถูกผูกไว้ด้วยกัน และหมายเลขหน้าที่ถูกต้องที่ใส่เข้าไปในย่อหน้าต่อไปนี้ คุณรอสำหรับสมุดบัญชีสามารถ "ผูก" ก่อนที่คุณสามารถอ้างอิงส่วนอื่น ๆ ของสมุดบัญชี การผูกซอฟต์แวร์จะคล้ายกัน รหัสของคุณทำขึ้นของส่วนประกอบที่จำเป็นต้องมี pulled เข้าด้วยกันก่อนที่รหัสสามารถ "อ่าน รวมถูกดำเนินการฟังก์ชันการเปลี่ยนชื่อ มีที่อยู่หน่วยความจำ (หรือหน่วยความจำ offsets ให้ชัดเจนมากขึ้น) ที่รหัสจะ "ไปยัง" เมื่อมีเรียกฟังก์ชัน สำหรับวัตถุ COM อยู่ถูกออฟเซ็ตหน่วยความจำเป็นในตารางของตัวชี้ (เรียกว่าตาราง v) ที่เก็บไว้ตามวัตถุ เมื่อฟังก์ชัน COM ถูกผูกไว้ นั้นถูกผูกไว้ผ่านตาราง v โครงสร้างของวัตถุ COM ได้อย่างง่าย เมื่อรหัสของคุณมีการอ้างอิงถึงวัตถุ จะมีตัวชี้การทางอ้อมไปด้านบนของตาราง v ตาราง v คือ อาร์เรย์ที่อยู่หน่วยความจำที่แต่ละรายการเป็นฟังก์ชันต่าง ๆ ที่สามารถถูกเรียกบนวัตถุนั้น เมื่อต้องการเรียกฟังก์ชันที่สามในวัตถุ COM คุณข้ามการลงรายการในตารางที่สาม และข้ามไปยังตำแหน่งหน่วยความจำที่กำหนดให้มี ที่ดำเนินการรหัสสำหรับฟังก์ชัน แล้ว เสร็จสมบูรณ์ เมื่อคุณกลับพร้อมที่จะกลับมาดำเนินการบรรทัดถัดไปของรหัส
+-[Code]------------+ +.................................[COM Object]...+
| | : +-------------+ :
|Set obj = Nothing -|--->| obj pointer | :
| | : +-|-----------+ :
+-------------------+ : | +-----------------+ :
: +-->| v-table pointer | :
: +--|--------------+ :
: | :
: | +----------------------------+ :
: (3rd) | | Function 1 Address pointer | :
: (Offset) | +----------------------------+ :
: | | Function 2 Address pointer | :
: | +----------------------------+ :
: +->| Function 3 Address pointer | :
: +----------------------------+ :
+................................................+
fortunately งานนี้เสร็จ โดย Visual Basic ฉากหลัง เป็นแบบโปรแกรมเมอร์ Visual Basic คุณไม่ต้องจัดการกับตาราง v โดยตรง แต่ โครงสร้างนี้เป็นวิธีวัตถุ COM ทั้งหมดถูกผูกไว้ และเป็นสิ่งสำคัญที่คุณคุ้นเคยกับการทำความเข้าใจเกี่ยวกับการผูกข้อมูลใดเป็น รวมก่อนหน้าตัวอย่างข้างต้นเป็นสิ่งที่ไม่รู้จักเป็นก่อนหน้า (หรือตาราง v) ผูก สำหรับวัตถุ COM ทั้งหมด รูปแบบนี้ใช้ในการผูกข้อมูลทำเมื่อใดก็ ตามที่เรียกว่าอินเทอร์เฟซ IUnknown ของวัตถุ COM แต่สิ่งที่เกี่ยวกับฟังก์ชันอื่น ๆ ของวัตถุหรือไม่ วิธีทำคุณเรียกวิธีการฟื้นฟูหรือคุณสมบัติพาเรนต์ของหรือไม่ ต่อไปนี้คือฟังก์ชันแบบกำหนดเองที่ไม่ซ้ำกันโดยทั่วไปไปยังวัตถุ ถ้าไม่มีสันนิษฐานยังตำแหน่งที่ตั้งในตาราง v คุณค้นไรอยู่ฟังก์ชันที่จำเป็นสำหรับการโทรออกคำตอบ นอน ขึ้นว่าหรือไม่คุณทราบล่วงหน้าของวัตถุ v-ตารางดูเหมือนกัน If you do, you can perform the same early-binding process to the object's custom methods as you did to its IUnknown methods. This is what is generally meant by "early-binding." To use early binding on an object, you need to know what its v-table looks like. In Visual Basic, you can do this by adding a reference to a type library that describes the object, its interface (v-table), and all the functions that can be called on the object. Once that is done, you can declare an object as being a certain type, then set and use that object using the v-table. For example, if you wanted to Automate Microsoft Office Excel using early binding, you would add a reference to the "Microsoft Excel 8.0 Object Library" from the Project|References dialog, and then declare your variable as being of the type "Excel.Application." From then on, all calls made to your object variable would be early bound: Late bindingCOM includes IDispatch. Objects that implement IDispatch are said to have a dispinterface (if it is the only interface they support) or dual interface (if they also have a custom interface that you can early bind to). Clients that bind to IDispatch are said to be "late bound" because the exact property or method they are calling is determined at run time using the methods of IDispatch to locate them. Going back to the book example earlier, think of it as being like a footnote that directs you to the table of contents where you have to "look up" the page number at "read time" rather than having it already printed there in the text.The magic of the interface is controlled by two functions: GetIDsOfNames and Invoke. The first maps function names (strings) to an identifier (called a dispid) that represents the function. Once you know the ID for the function you want to call, you can call it using the Invoke function. This form of method invocation is called "late binding." Again, in Visual Basic the way you specify how the object is bound is by your object declaration. If you declare an object variable as "Object" you are, in fact, telling Visual Basic to use IDispatch, and are therefore late binding: It is important to note that what is "late bound" is the function being called and not the way it is called. From the earlier discussion on binding in general, you should notice that IDispatch itself is "early bound:" that is to say that Visual Basic makes the call to set the Visible property through a v-table entry (IDispatch::Invoke) as it would any COM call. The COM object itself is responsible for forwarding the call to the correct function to make Excel visible. This indirection allows the Visual Basic client to be compiled (that is, bound to a valid function address) but still not know the exact function that will actually do the work. Dispid bindingSome Automation clients (most noticeably MFC and Visual Basic 3.0, but also Visual Basic 5.0 and 6.0 with respect to ActiveX Controls) use a hybrid form of late binding called dispid binding. If the COM object is known at design time, the dispids for the functions that are called can be cached and passed directly to IDispatch::Invoke without the need to call GetIDsOfNames at run time. This can greatly increase performance, because instead of making two COM calls per function, you only need to make one.Dispid binding is not an option you can normally choose in Visual Basic 5.0 or 6.0. It is used for objects that are referenced in a type library but do not contain a custom interface (that is, for objects that have a dispinterface only) and for aggregated ActiveX Controls but, in general, Visual Basic uses early binding any place you would normally use dispid binding. Which form of binding should I use?The answer to this question depends as much on the design of your project as anything else. Microsoft recommends early binding in almost all cases. However, there may be reasons for choosing late binding.Early binding is the preferred method. It is the best performer because your application binds directly to the address of the function being called and there is no extra overhead in doing a run-time lookup. In terms of overall execution speed, it is at least twice as fast as late binding. รวมก่อนหน้าให้ปลอดภัยชนิด เมื่อคุณมีการอ้างอิงที่กำหนดไปยังไลบรารีชนิดของส่วนประกอบ Visual Basic ให้การสนับสนุน IntelliSense เพื่อช่วยให้คุณรหัสฟังก์ชันแต่ละอย่างถูกต้อง visual Basic จะเตือนคุณถ้าข้อมูลพิมพ์ของพารามิเตอร์ หรือคืนค่าไม่ถูกต้อง บันทึกจำนวนมากเวลาเมื่อเขียน และการดีบักรหัส รวมภายหลังจะยังคงเป็นประโยชน์ในกรณีที่มีการเรียกที่อินเทอร์เฟซที่แน่นอนของวัตถุไม่ว่าในขณะออกแบบ ถ้าโปรแกรมประยุกต์ของคุณ seeks การพูดคุยกับเซิร์ฟเวอร์ที่ไม่รู้จักหรือความต้องการเรียกฟังก์ชัน โดยชื่อ (ใช้ 6.0 Visual Basic หลายรายการCallByNameฟังก์ชันตัวอย่างเช่น) จาก นั้นคุณจำเป็นต้องใช้การรวมภายหลัง นอกจากนี้ยังเป็นประโยชน์เมื่อต้องการแก้ไขปัญหาความเข้ากันได้ระหว่างคอมโพเนนต์ที่ไม่ถูกต้องปรับเปลี่ยน หรือ adapted ของอินเทอร์เฟซระหว่างรุ่น หลายรุ่นรวมภายหลังได้ ข้อดีที่มีการรวมก่อนหน้าทำให้เป็นตัวเลือกที่ดีที่สุดเมื่อใดก็ ตามที่เป็นไปได้ การรักษาความเข้ากันได้ข้ามการหลายรุ่นถ้าคุณจะใช้คอมโพเนนต์ที่คุณไม่ได้กระจายกับแพคเกจการติดตั้งของคุณ และไม่สามารถถูก assured ของเวอร์ชันที่แน่นอนที่อธิบายคุณจะได้ทราบด้วยเวลารัน- คุณควรจ่ายความสนใจพิเศษในการผูกก่อนหน้าไปยังอินเทอร์เฟซที่เข้ากันได้กับทุกเวอร์ชัน ของส่วนประกอบ หรือ (ในบางกรณี) ใช้การรวมภายหลังเพื่อที่เรียกใช้เมธอดที่อาจมีอยู่ในรุ่นที่เฉพาะ และล้มเหลว gracefully ถ้าวิธีการที่ไม่มีอยู่ในรุ่นที่ติดตั้งอยู่บนระบบไคลเอ็นต์โปรแกรมประยุกต์ Microsoft Office แสดงตัวอย่างที่ดีของเซิร์ฟเวอร์ COM เช่น โปรแกรมประยุกต์ office โดยปกติจะขยายอินเทอร์เฟซของพวกเขาเพิ่มฟังก์ชันการทำงานใหม่หรือ shortcomings ก่อนหน้านี้ที่ถูกต้องระหว่างรุ่น ถ้าคุณต้องการทำให้โปรแกรมประยุกต์ Office ขอแนะนำว่า คุณก่อนหน้าผูกกับรุ่นผลิตภัณฑ์ที่คุณคาดว่า อาจมีการติดตั้งบนระบบของไคลเอ็นต์ ที่เร็วที่สุด ตัวอย่างเช่น ถ้าคุณจำเป็นเพื่อให้สามารถทำให้ Excel 95, Excel 97, Excel 2000 และ Excel 2002 คุณควรใช้ไลบรารีชนิดสำหรับ Excel 95 (XL5en32.olb) เพื่อรักษาความเข้ากันได้กับรุ่นสามทั้งหมด โปรแกรมประยุกต์ office ยังสาธิตรูปแบบของวัตถุกับอินเทอร์เฟซที่สองขนาดใหญ่สามารถ suffer ข้อจำกัดใน marshalling บนแพลตฟอร์มบางอย่าง สำหรับรหัสของคุณให้เหมาะสำหรับทุกแพลทฟอร์ม ใช้ IDispatchFor more information on maintaining compatibility when working with Office applications, click the following article number to view the article in the Microsoft Knowledge Base: 247579
(http://support.microsoft.com/kb/247579/
)
Use DISPID binding to automate Office applications whenever possibleข้อมูลอ้างอิงFor more information about COM, v-tables, and using
Automation, please see the following books: Rogerson, Dale,Inside COM, MSPRESS, ISBN: 1-57231-349-8. Curland, Matt,Advanced Visual Basic 6, DevelopMentor, 0201707128. คุณสมบัติหมายเลขบทความ (Article ID): 245115 - รีวิวครั้งสุดท้าย: 8 มกราคม 2554 - Revision: 3.0 ใช้กับ
แปลโดยคอมพิวเตอร์ ข้อมูลสำคัญ: บทความนี้แปลโดยซอฟต์แวร์การแปลด้วยคอมพิวเตอร์ของ Microsoft แทนที่จะเป็นนักแปลที่เป็นบุคคล Microsoft มีบทความที่แปลโดยนักแปลและบทความที่แปลด้วยคอมพิวเตอร์ เพื่อให้คุณสามารถเข้าถึงบทความทั้งหมดในฐานความรู้ของเรา ในภาษาของคุณเอง อย่างไรก็ตาม บทความที่แปลด้วยคอมพิวเตอร์นั้นอาจมีข้อบกพร่อง โดยอาจมีข้อผิดพลาดในคำศัพท์ รูปแบบการใช้ภาษาและไวยากรณ์ เช่นเดียวกับกรณีที่ชาวต่างชาติพูดผิดเมื่อพูดภาษาของคุณ Microsoft ไม่มีส่วนรับผิดชอบต่อความคลาดเคลื่อน ความผิดพลาดหรือความเสียหายที่เกิดจากการแปลเนื้อหาผิดพลาด หรือการใช้บทแปลของลูกค้า และ Microsoft มีการปรับปรุงซอฟต์แวร์การแปลด้วยคอมพิวเตอร์อยู่เป็นประจำ ต่อไปนี้เป็นฉบับภาษาอังกฤษของบทความนี้:245115
(http://support.microsoft.com/kb/245115/en-us/
)
| การแปลบทความ
|




กลับไปด้านบน








