مشاهدة النسخة كاملة : كيف أعرف اسم القرص
السلام عليكم
جزاكم الله خيراً على مجاهديكم...
كيف أعرف اسم قرص محدد مثلا القرص C:\ اسمه local disk
كيف أحصل على هذا الإسم؟
kachwahed
13-08-2010, 12:34 AM
وعليكم السلام ورحمة الله
للاستعلام عن معلومات قطاع من القرص نستخدم التابع GetVolumeInformation
عبارة Local Disk يعبر عنها Windows عندما لا يتم تسمية القرص
فإذا رأيت اسمه Local Disk يعني أن اسمه في الحقيقة هو ''
بناء على ذلك يمكن أن نكتب:
function GetVolumeName(DriveLetter: Char): string;
var
dummy: DWORD;
buffer: array[0..MAX_PATH] of Char;
oldmode: LongInt;
begin
oldmode := SetErrorMode(SEM_FAILCRITICALERRORS);
try
GetVolumeInformation(PChar(DriveLetter + ':\'),
buffer,
SizeOf(buffer),
nil,
dummy,
dummy,
nil,
0);
if buffer = '' then Result := 'Local Disk' else
Result := StrPas(buffer);
finally
SetErrorMode(oldmode);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
Caption := GetVolumeName('c');
end;
والله أعلم
بالتوفيق.
abdelmalek
13-08-2010, 06:38 AM
اخي kachwahed :
لي سؤال : اين هم من ادا اجاب عن شيئ فهما (شرح) وادا صمت توعدا
اخي انت تكتب تابع GetVolumeName ولم تشرح تابع SetErrorMode والله عجبا .
كما تلاحظ ان FPS هو عضو مبتدأ ( طبعا من طريقة طرح السؤال)
اسف واعتدر عن كلامي فانا ( متكلم بسم المبتدئين )
في امان الله
بالتوفيق للجميع
kachwahed
13-08-2010, 12:22 PM
الأخ abdelmalek جيد أنك تحدثت بكل بصراحة :)
1- إعلم أن الذي يكتب كود ليس بالضرورة أن يفهم كل ما جاء فيه! كما قد يظن بعض المبتدئين...
ولا يعني طبعا أنه يحفظه أن ظهر قلب !
يعني أنا أيضا لا أعرف ما معنى SetErrorMode وإنما نسختها كما هي !
لكن... لننظر ولنفتح من دلفي:
Help -> Windows SDK
ونبحث عن التابع SetErrorMode
يمكنك البحث في MSDN أيضا:
http://msdn.microsoft.com/en-us/library/ms680621%28VS.85%29.aspx
وجدنا الشرح:
The SetErrorMode function controls how the operating system handles several types of serious errors. You can specify that the operating system will handle these errors or that the application will receive and handle them.
إذا كنت لا تفهم الإنجليزية استخدم Google Translate (http://translate.google.com/#en|ar|) وتحصل على:
الدالة SetErrorMode تتحكم في نظام التشغيل يتعامل مع عدة أنواع من أخطاء خطيرة. يمكنك تحديد أن نظام التشغيل ومعالجة هذه الأخطاء أو أن الطلب سوف تلقي والتعامل معها.
تعريف التابع:
UINT SetErrorMode(
UINT uMode // set of bit flags that specify error-handling properties
);
الترجمة...
شرح المعلمة:
Parameters
uMode
A set of bit flags that specify system error-handling properties. The following error mode bit flag constants are defined; you can set any combination of them:
الترجمة...
القيمة الممكنة وشرحها:
SEM_FAILCRITICALERRORS If this flag is set, the operating system does not display the critical-error-handler message box when such an error occurs. Instead, the operating system sends the error to the calling process.
SEM_NOALIGNMENTFAULTEXCEPT If this flag is set, the operating system automatically fixes memory alignment faults and makes them invisible to the application. It does this for the calling process and any descendant processes. This flag always affects MIPS processors. It has no effect on x86 processors.If the registry value \CurrentControlSet\Control\Session Manager:EnableAlignmentFaultExceptions is set to REG_DWORD 0x0, this key has no effect on ALPHA processors. That is the system default. If the registry key is set to REG_DWORD 0x1, the SEM_NOALIGNMENTFAULTEXCEPT flag does affect ALPHA processors.
SEM_NOGPFAULTERRORBOX If this flag is set, the operating system does not display the general-protection-fault message box when such an error occurs. This flag should only be set by debugging applications that handle general protection (GP) faults themselves via an appropriate exception handler.
SEM_NOOPENFILEERRORBOX If this flag is set, the operating system does not display a message box when it fails to find a a file. Instead, the error is returned to the calling process.
ومعلومات إضافية أخرى حول القيمة المسترجعة وغير ذلك...
القليل من التجارب في دلفي (أكتب الدالة وغير قيمة المعلمة في كل مرة وجرب التنفيذ...)
الآن صرنا نعرف عمل هذا التابع. أرأيت؟ كل شيء موجود بالبحث :)
اخي انت تكتب تابع GetVolumeName ولم تشرح تابع SetErrorMode والله عجبا .
2- انتبه فقد تجعل البعض يرفض الإجابة أصلا بسبب مثل هذه الردود، أو بسبب أنه سينجر إلى المزيد من الأسئلة!
كما تلاحظ ان FPS هو عضو مبتدأ ( طبعا من طريقة طرح السؤال)
3- طبعا لا يمكن أن نعرف المبتدئ من غيره والسؤال هو الذي يفرض نوع الإجابة. يعني إذا كان السؤال عن شيء صعب (في نظر السائل) فلا تنتظر أن تكون الإجابة بسيطة!
شكرا أخي abdelmalek على توضيحك :)
بالتوفيق.
abdelmalek
13-08-2010, 07:07 PM
هههههههه والله اعجبتني بشرحك هدا اخي kachwahed
لقد زدتني اعجابا بك
جزاك الله خيرا
سلامي وحبي لك اخي
في امان الله
vBulletin® , Copyright ©2008-2012