procedure TFrmEmployee.spbAddPhotoClick(Sender: TObject); var lExtName: string; lJpegImage: TJpegImage; begin inherited; // Save if Sender = spbSavePhoto then if SavePictureDialog.Execute then begin lExtName := ExtractFileExt(SavePictureDialog.FileName); if (UpperCase(lExtName) = '.JPG') or (UpperCase(lExtName) = '.JEPG') then begin lJpegImage := TJpegImage.Create; try lJpegImage.Assign(dbimgPhoto.Picture.Graphic); lJpegImage.SaveToFile(SavePictureDialog.FileName); finally lJpegImage.Free; end; // end try end else TBlobField(adodstMas.FieldByName('Photo')).SaveToFile(SavePictureDialog.FileName); end; if not (adodstMas.State in [dsEdit, dsInsert]) then exit; // Add if Sender = spbAddPhoto then if OpenPictureDialog.Execute then begin lExtName := ExtractFileExt(OpenPictureDialog.FileName); if (UpperCase(lExtName) = '.JPG') or (UpperCase(lExtName) = '.JEPG') then begin lJpegImage := TJpegImage.Create; try lJpegImage.LoadFromFile(OpenPictureDialog.FileName); dbimgPhoto.Picture.Graphic.Assign(lJpegImage); finally lJpegImage.Free; end; // end try end else TBlobField(adodstMas.FieldByName('Photo')).LoadFromFile(OpenPictureDialog.FileName); end; // end if OpenPictureDialog.Execute then // Clear if Sender = spbClearPhoto then adodstMas.FieldByName('Photo').AsVariant := Null; end;
pic1.LoadFromFile(opendialog.FileName);
ADOQuery1.Insert;
ADOQuery1.FieldByName('xh').AsString := '1';
TBlobField(ADOQuery1.FieldByName('tp')).LoadFromFile(opendialog.FileName);
ADOQuery1.Post;
我的人事檔案里有源碼
var
lExtName: string;
lJpegImage: TJpegImage;
begin
inherited;
// Save
if Sender = spbSavePhoto then
if SavePictureDialog.Execute then
begin
lExtName := ExtractFileExt(SavePictureDialog.FileName);
if (UpperCase(lExtName) = '.JPG')
or (UpperCase(lExtName) = '.JEPG') then
begin
lJpegImage := TJpegImage.Create;
try
lJpegImage.Assign(dbimgPhoto.Picture.Graphic);
lJpegImage.SaveToFile(SavePictureDialog.FileName);
finally
lJpegImage.Free;
end; // end try
end else
TBlobField(adodstMas.FieldByName('Photo')).SaveToFile(SavePictureDialog.FileName);
end; if not (adodstMas.State in [dsEdit, dsInsert]) then exit;
// Add
if Sender = spbAddPhoto then
if OpenPictureDialog.Execute then
begin
lExtName := ExtractFileExt(OpenPictureDialog.FileName);
if (UpperCase(lExtName) = '.JPG')
or (UpperCase(lExtName) = '.JEPG') then
begin
lJpegImage := TJpegImage.Create;
try
lJpegImage.LoadFromFile(OpenPictureDialog.FileName);
dbimgPhoto.Picture.Graphic.Assign(lJpegImage);
finally
lJpegImage.Free;
end; // end try
end else
TBlobField(adodstMas.FieldByName('Photo')).LoadFromFile(OpenPictureDialog.FileName);
end; // end if OpenPictureDialog.Execute then
// Clear
if Sender = spbClearPhoto then
adodstMas.FieldByName('Photo').AsVariant := Null;
end;