问题是把TOpenPictureDialog打开的图片保存在EXE文件下的图片目录,然后以edit1的text的字符串命名后保存.
现在运行时遇到的错误,求bdmh老师帮解下.
[DCC Error] Unit1.pas(45): E2035 Not enough actual parameters
[DCC Error] Unit1.pas(45): E2018 Record, object or class type required
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtDlgs, ExtCtrls, jpeg, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
OpenPictureDialog1: TOpenPictureDialog;
Panel1: TPanel;
Image1: TImage;
Edit1: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
MyPath:string;
Pic:string;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
pic := OpenPictureDialog1.FIlename;
Image1.Picture.LoadFromFile(pic);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if directoryExists(myPath+'图片') then
CopyFile('pic', 'myPath+'图片+'edit1.text+'.jpg', True);//问题就在这里
end;
end.
现在运行时遇到的错误,求bdmh老师帮解下.
[DCC Error] Unit1.pas(45): E2035 Not enough actual parameters
[DCC Error] Unit1.pas(45): E2018 Record, object or class type required
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtDlgs, ExtCtrls, jpeg, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
OpenPictureDialog1: TOpenPictureDialog;
Panel1: TPanel;
Image1: TImage;
Edit1: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;
MyPath:string;
Pic:string;
implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
pic := OpenPictureDialog1.FIlename;
Image1.Picture.LoadFromFile(pic);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if directoryExists(myPath+'图片') then
CopyFile('pic', 'myPath+'图片+'edit1.text+'.jpg', True);//问题就在这里
end;
end.
procedure TForm1.Button2Click(Sender: TObject);
var
jpeg: Tjpegimage;
begin
SavePictureDialog1.Filter :=
'*.jpg|*.jpg';
if SavePictureDialog1.Execute then
begin
try
jpeg := Tjpegimage.Create;
jpeg.Assign(image1.Picture.Bitmap);
jpeg.SaveToFile(ChangeFileExt(SavePictureDialog1.Filename,
'.jpg'));
finally
jpeg.Free;
end;
end;end;
procedure TForm1.Button2Click(Sender: TObject);
var
jpeg: Tjpegimage;
begin
SavePictureDialog1.Filter :=
'*.jpg|*.jpg';
if SavePictureDialog1.Execute then
begin
try
jpeg := Tjpegimage.Create;
jpeg.Assign(image1.Picture.Bitmap);
jpeg.SaveToFile(ChangeFileExt(SavePictureDialog1.Filename,
'.jpg'));
finally
jpeg.Free;
end;
end;end;
CopyFile('pic', 'myPath+'图片+'edit1.text+'.jpg', True);//问题就在这里
上面这就 话存在不少问题
pic和maypath都是变量,为什么还要用引号呢
"图片"二字,少个引号
edit1.text为什么左侧有个引号,右侧没有呢修改如下试试CopyFile(PChar(pic), PChar(myPath+'图片\'+edit1.text+'.jpg'), True);
begin
if OpenPictureDialog1.Execute then
begin
pic := OpenPictureDialog1.FIlename;
Image1.Picture.LoadFromFile(pic);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if directoryExists(myPath+'图片') then
CopyFile('pic',pchar(myPath+'图片'+edit1.text+'.jpg'), True);
end;
end.
begin
if OpenPictureDialog1.Execute then
begin
pic := OpenPictureDialog1.FIlename;
Image1.Picture.LoadFromFile(pic);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if length(Edit1.text) = 0 then begin
showMessage('please input pic file name');
exit;
end; if not fileExists(pic) then begin
showMessage('can not Fount pic file');
exit;
end;
if LastDelimiter('\',myPath) <> length(myPath) then mypath := myPath+'\'; if directoryExists(myPath+'图片') then
CopyFile(pic,pchar(myPath+'图片\'+edit1.text+'.jpg'), True);
end;
end.
你的pic是变量,不是字符串,不能用引号呀
看看
pic及myPath+'图片\'+edit1.text+'.jpg'的值,是不是正确的,因为看不到pic和mypath的值,所以怀疑有可能这两个参数有问题,比如mypath后面是否有'\'
2.被复制的图片是否有只读属性,有则去掉
3.目标文件是否被使用我想上面问题都确定之后,应该没有问题的,主要就是路径指向是否正确
[DCC Error] Unit1.pas(57): E2010 Incompatible types: 'string' and 'PWideChar'
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
CopyFile('pic', 'myPath+'图片+'edit1.text+'.jpg', True);
把第三个参数改成false试试,那样就会覆盖已存在的文件,
procedure TForm1.Button1Click(Sender: TObject);
begin
if OpenPictureDialog1.Execute then
begin
pic := OpenPictureDialog1.FIlename;
Image1.Picture.LoadFromFile(pic);
end;
end;procedure TForm1.Button2Click(Sender: TObject);
begin
if length(Edit1.text) = 0 then begin
showMessage('please input pic file name');
exit;
end; if not fileExists(pic) then begin
showMessage('can not Fount pic file');
exit;
end;
if LastDelimiter('\',myPath) <> length(myPath) then mypath := myPath+'\'; if directoryExists(pWidechar(myPath+'图片')) then
CopyFile(pic,pWidechar(myPath+'图片\'+edit1.text+'.jpg'), True);
end;
end.
你的DELPHI是2009的?
还是不行
[DCC Error] Unit1.pas(57): E2010 Incompatible types: 'string' and 'PWideChar'
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
还是不行
[DCC Error] Unit1.pas(57): E2010 Incompatible types: 'string' and 'PWideChar'
[DCC Fatal Error] Project1.dpr(5): F2063 Could not compile used unit 'Unit1.pas'
保存到你需要的盘符就可以了。.我测试通过
PIC这个变量是对的,myPath+'图片这个路径也是对的啊,真汗.}
這二個分別是什麼,你就明白了。
ShowMessage(pic);//这是:原图片的地址
ShowMessage(myPath+'图片\'+edit1.text+'.jpg');//这是:图片\edit1.jpg
都没错哦,奇怪,不用变量直接用路径表示就可以复制.难道是变量的问题.
都没错哦,奇怪,不用变量直接用路径表示就可以复制.难道是变量的问题.
你用這個SHOW出來的地址,在資源管理器訪問這個地址,能訪問到嗎?? 盤符都沒有!!!不對