Mask
جمعه 17 آبان 1392, 12:16 عصر
سلام
کد زیر برای دلفی 7 به خوبی کار میکنه . اما برای xe نمیتونه کامپایل کنه و ارور زیر رو میده.
میشه راهنمایی بفرمایید کد رو باید چطوری تغییر داد ، تا در این نسخه درست کار کنه؟
function StrFormatByteSize(dw: Int64; szBuf: PAnsiChar; cchBuf: UINT)
: PAnsiChar; stdcall; external 'shlwapi.dll' name 'StrFormatByteSize64A';
procedure TfrmFiles.AddFile;
var
I: Integer;
Form: TfrmItem;
FileName: string;
lpSize: array [0..255] of Char;
IDH: TImageDosHeader;
INH: TImageNtHeaders;
dwTemp: DWORD;
IsEXE: Boolean;
begin
if OpenDialog.Execute then
begin
for I := 0 to (OpenDialog.Files.Count - 1) do
begin
FileName := OpenDialog.Files[I];
Form := TfrmItem.Create(frmFiles.ScrollBox);
with Form do
begin
Parent := frmFiles.ScrollBox;
Height := MinimizedHeight;
Label1.Caption := ExtractFileName(FileName);
Edit2.Text := ExtractFileName(FileName);
Form.hFile := CreateFile(pChar(FileName), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
fSize := Windows.GetFileSize(hFile, nil);
Inc(TotalSize, fSize);
StrFormatByteSize(fSize, lpSize, sizeof(lpSize) - 1);//رو این خطارور میگیره
Label2.Caption := lpSize;
ExtractIcon(FileName, Image1);
ComboBoxEx1.ItemIndex := 0;
ComboBoxEx2.ItemIndex := 2;
IsEXE := False;
ReadFile(Form.hFile, IDH, SizeOf(TImageDosHeader), dwTemp, nil);
if IDH.e_magic = IMAGE_DOS_SIGNATURE then
begin
SetFilePointer(hFile, IDH._lfanew, nil, FILE_BEGIN);
ReadFile(Form.hFile, INH, SizeOf(TImageNtHeaders), dwTemp, nil);
if INH.Signature = IMAGE_NT_SIGNATURE then
begin
IsEXE := (INH.FileHeader.Characteristics and IMAGE_FILE_DLL = 0);
Form.Alert := INH.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = 0;
end;
end;
if not IsEXE then
Form.ComboBoxEx2.ItemsEx.Delete(3);
SetFilePointer(hFile, 0, nil, FILE_BEGIN);
Show;
RefreshStatusBar();
Application.ProcessMessages;
end;
Inc(nFiles);
end;
frmFiles.ScrollBox.Refresh;
end;
end;
ارور :
[DCC Error] untFiles.pas(103): E2010 Incompatible types: 'PAnsiChar' and 'array[0..255] of Char'
کد زیر برای دلفی 7 به خوبی کار میکنه . اما برای xe نمیتونه کامپایل کنه و ارور زیر رو میده.
میشه راهنمایی بفرمایید کد رو باید چطوری تغییر داد ، تا در این نسخه درست کار کنه؟
function StrFormatByteSize(dw: Int64; szBuf: PAnsiChar; cchBuf: UINT)
: PAnsiChar; stdcall; external 'shlwapi.dll' name 'StrFormatByteSize64A';
procedure TfrmFiles.AddFile;
var
I: Integer;
Form: TfrmItem;
FileName: string;
lpSize: array [0..255] of Char;
IDH: TImageDosHeader;
INH: TImageNtHeaders;
dwTemp: DWORD;
IsEXE: Boolean;
begin
if OpenDialog.Execute then
begin
for I := 0 to (OpenDialog.Files.Count - 1) do
begin
FileName := OpenDialog.Files[I];
Form := TfrmItem.Create(frmFiles.ScrollBox);
with Form do
begin
Parent := frmFiles.ScrollBox;
Height := MinimizedHeight;
Label1.Caption := ExtractFileName(FileName);
Edit2.Text := ExtractFileName(FileName);
Form.hFile := CreateFile(pChar(FileName), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
fSize := Windows.GetFileSize(hFile, nil);
Inc(TotalSize, fSize);
StrFormatByteSize(fSize, lpSize, sizeof(lpSize) - 1);//رو این خطارور میگیره
Label2.Caption := lpSize;
ExtractIcon(FileName, Image1);
ComboBoxEx1.ItemIndex := 0;
ComboBoxEx2.ItemIndex := 2;
IsEXE := False;
ReadFile(Form.hFile, IDH, SizeOf(TImageDosHeader), dwTemp, nil);
if IDH.e_magic = IMAGE_DOS_SIGNATURE then
begin
SetFilePointer(hFile, IDH._lfanew, nil, FILE_BEGIN);
ReadFile(Form.hFile, INH, SizeOf(TImageNtHeaders), dwTemp, nil);
if INH.Signature = IMAGE_NT_SIGNATURE then
begin
IsEXE := (INH.FileHeader.Characteristics and IMAGE_FILE_DLL = 0);
Form.Alert := INH.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size = 0;
end;
end;
if not IsEXE then
Form.ComboBoxEx2.ItemsEx.Delete(3);
SetFilePointer(hFile, 0, nil, FILE_BEGIN);
Show;
RefreshStatusBar();
Application.ProcessMessages;
end;
Inc(nFiles);
end;
frmFiles.ScrollBox.Refresh;
end;
end;
ارور :
[DCC Error] untFiles.pas(103): E2010 Incompatible types: 'PAnsiChar' and 'array[0..255] of Char'