![]() |
|
usb bellek format atma - Baskı Önizleme +- Delphi Can (https://www.delphican.com) +-- Forum: Delphi (https://www.delphican.com/forumdisplay.php?fid=3) +--- Forum: Genel Programlama (https://www.delphican.com/forumdisplay.php?fid=6) +--- Konu Başlığı: usb bellek format atma (/showthread.php?tid=6574) |
usb bellek format atma - erdogan - 24-01-2022 Merhaba, X sürücüye nasıl format atabilirim ? aşağıdaki kodu ile yapmaya çalıştım olmadı. unit Unit1;
interface
uses
Winapi.Windows,shellapi, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
EditSurucu: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
SHFMT_DRV_A = 0;
SHFMT_DRV_B = 1;
SHFMT_ID_DEFAULT = $FFFF;
SHFMT_OPT_QUICKFORMAT = 0;
SHFMT_OPT_FULLFORMAT = 1;
SHFMT_OPT_SYSONLY = 2;
SHFMT_ERROR = -1;
SHFMT_CANCEL = -2;
SHFMT_NOFORMAT = -3;
function SHFormatDrive(hWnd: HWND; Drive: Word; fmtID: Word; Options: Word): Longint stdcall;
external 'Shell32.dll' Name 'SHFormatDrive';
function IsRemovableDrive(Drive: Char): Boolean;
begin
Result := (Winapi.Windows.GetDriveType(PChar(Drive + ':\')) = Winapi.Windows.Drive_Removable);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
FmtRes: Longint;
Surucu : Char;
begin
try
Surucu := EditSurucu.Text[1];
FmtRes := ShFormatDrive(Handle, Ord(Surucu), SHFMT_ID_DEFAULT, SHFMT_OPT_QUICKFORMAT);
case FmtRes of
SHFMT_ERROR: ShowMessage('Sürücü biçimlendirme hatası');
SHFMT_CANCEL: ShowMessage('Kullanıcı, Sürücüyü biçimlendirmeyi iptal etti');
SHFMT_NOFORMAT: ShowMessage('fORMAT atılamadı.')
else
ShowMessage('Disk biçimlendirildi!');
end;
except
ShowMessage('Hata oluştu!');
end;
end;
end.
(24-01-2022, Saat: 14:15)erdogan Adlı Kullanıcıdan Alıntı: Merhaba, Merhaba, aşağıdaki gibi çözülmüştür. unit Unit1;
interface
uses
Winapi.Windows,shellapi, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
EditSurucu: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
SHFMT_DRV_A = 0;
SHFMT_DRV_B = 1;
SHFMT_ID_DEFAULT = $FFFF;
SHFMT_OPT_QUICKFORMAT = 0;
SHFMT_OPT_FULLFORMAT = 1;
SHFMT_OPT_SYSONLY = 2;
SHFMT_ERROR = -1;
SHFMT_CANCEL = -2;
SHFMT_NOFORMAT = -3;
function SHFormatDrive(
hWnd: HWND;
Drive: UINT;
fmtID: UINT;
Options: UINT
): DWORD; stdcall; external 'Shell32.dll';
function IsRemovableDrive(Drive: Char): Boolean;
begin
Result := (Winapi.Windows.GetDriveType(PChar(Drive + ':\')) = Winapi.Windows.Drive_Removable);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
FmtRes: Longint;
cCharTemp : Char;
nDrive : UINT; // this makes all the difference, declare its like this
begin
try
cCharTemp := EditSurucu.Text[1]; // EditSurucu.Text := 'E:\';
nDrive := Ord(cCharTEmp) - Ord('A');
FmtRes := ShFormatDrive(Handle, nDrive, SHFMT_ID_DEFAULT, SHFMT_OPT_QUICKFORMAT);
case FmtRes of
SHFMT_ERROR: ShowMessage('Sürücü biçimlendirme hatası');
SHFMT_CANCEL: ShowMessage('Kullanıcı, Sürücüyü biçimlendirmeyi iptal etti');
SHFMT_NOFORMAT: ShowMessage('Format atılamadı.')
else
ShowMessage('Disk biçimlendirildi!');
end;
except
ShowMessage('Hata oluştu!');
end;
end;
end.
|