الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

استفسار فى Option Strict

مغلق
بدأه AHMAD FATHY في 10 يوليو 2006 · 2 رد · 452 مشاهدة · في Microsoft Visual Basic.NET
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم

قرأت فى ال MSDN عن Options strict محاولا ايجاد المعلومات الكافية و لكن لم افهم جزء فأرجو التوضيح

هذا جزء من المكتوب فى MSDN

Remarks

When used, the Option Strict statement must appear before any other code.

Visual Basic .NET generally allows implicit conversions of any data type to any other data type. Data loss can occur when the value of one data type is converted to a data type with less precision or smaller capacity, however, a run-time error message will occur if data will be lost in such a conversion. Option Strict ensures compile-time notification of these types of conversions so they may be avoided.

In addition to disallowing narrowing conversions, Option Strict generates an error for late binding. An object is late bound when it is assigned to a variable that is declared to be of type Object.

Note The compiler default is Option Strict Off if do not specify Option Strict in your code.

Example

This example demonstrates how the Option Strict statement disallows late binding and conversions where data would be lost.



Dim MyVar As Integer ' Declare variables.
Dim Obj As Object

MyVar = 1000 ' Declared variable does not generate error.

'Attempting to convert to an Integer generates an error.
MyVar = 1234567890.987654321
'
'Call Obj.Method1() ' Late-bound call generates an error
Option Strict On   ' Force explicit variable declaration.

AlexCard.gif

Business Card

Ahmad Fathy Ahmad

Computer and Systems Department

Faculty of Engineering, Alexandria University

Cellular: +2 010 1461154

E-mail: midoalx@hotmail.com

ICQ: 148481391

#2

السلام عليكم

8 – الإرتباط المُتأخر و الارتباط المبكر Late Bound And Early Bound

كل المتغيرات التي تكون من نوع Object هي متغيرات مرجعية Reference Type

على أفضليتها في أنها تقبل أي قيمة إلا أنه توصف بـ Late Bound وهو الارتباط المُتأخر

يحدث ذلك إذا لم يتم تعريف المتغير على أنه قالب معين specific Class

و يعرف على انه متغير من نوع Object مثال ذلك

Dim myVar As Object ‘Late Bound
Dim myVar As Form1 ‘Early Bound

السبب

تعود أفضلية الارتباط السريع بإن المترجم يقوم ببعض التحسينات Management على المتغير أثناء التشغيل

أما الارتباط المتأخر فإن المترجم مجبر على التحقق من نوع المتغير مع عناصرهِ أو قيمه

إضافه إلى ذلك يكون غير مقروء unreadable

وصعب التعديل , كما أن مشروعك قد يكون معرض لظهور الأخطاء أثناء التشغيل Run Time Error

النصيحة : دائماً تجنب التعريف الغير مباشر كل ما أمكن , ودئماً إستخدم التعريف المباشر أو المبكر كل ما أمكن

لقراءة المقالة ككل إليك الرابط التالي ( القول المنير في أصول التطوير )

بالتوفيق إن شاء الله.

في المثال يتضح المقال

#3

السلام عليكم

جزاك الله خيراً موضوعك فعلا مفيد جداً ;)

AlexCard.gif

Business Card

Ahmad Fathy Ahmad

Computer and Systems Department

Faculty of Engineering, Alexandria University

Cellular: +2 010 1461154

E-mail: midoalx@hotmail.com

ICQ: 148481391

هذا الموضوع مغلق.

مواضيع مشابهة