Changeset 45 for trunk/Forms/UFormContact.pas
- Timestamp:
- Dec 2, 2021, 3:19:57 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Forms/UFormContact.pas
r43 r45 7 7 uses 8 8 Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, 9 ComCtrls, ActnList, Menus, ExtCtrls, UContact, UFormProperties;9 ComCtrls, ActnList, Menus, ExtCtrls, ExtDlgs, UContact, UFormProperties; 10 10 11 11 type … … 14 14 15 15 TFormContact = class(TForm) 16 AEditField: TAction; 16 APhotoSave: TAction; 17 APhotoLoad: TAction; 17 18 ActionList1: TActionList; 18 19 ButtonCancel: TButton; … … 114 115 MemoNotes: TMemo; 115 116 MenuItem1: TMenuItem; 117 MenuItem2: TMenuItem; 118 OpenPictureDialog1: TOpenPictureDialog; 116 119 PageControlContact: TPageControl; 117 PopupMenu1: TPopupMenu; 120 PopupMenuPhoto: TPopupMenu; 121 SavePictureDialog1: TSavePictureDialog; 118 122 TabSheetOthers: TTabSheet; 119 123 TabSheetHome: TTabSheet; … … 121 125 TabSheetGeneral: TTabSheet; 122 126 TabSheetAll: TTabSheet; 127 procedure APhotoLoadExecute(Sender: TObject); 128 procedure APhotoSaveExecute(Sender: TObject); 123 129 procedure ButtonNextClick(Sender: TObject); 124 130 procedure ButtonOkClick(Sender: TObject); … … 140 146 procedure LoadData; 141 147 procedure SaveData; 148 procedure UpdateInterface; 142 149 property Contact: TContact read FContact write SetContact; 143 150 property OnPrevious: TNotifyEvent read FOnPrevious write FOnPrevious; … … 166 173 FormProperties.Align := alClient; 167 174 FormProperties.Show; 175 UpdateInterface; 168 176 end; 169 177 … … 195 203 if FContact = AValue then Exit; 196 204 FContact := AValue; 197 LoadData;205 if Visible then LoadData; 198 206 end; 199 207 … … 212 220 begin 213 221 if Assigned(FOnNext) then FOnNext(Self); 222 end; 223 224 procedure TFormContact.APhotoLoadExecute(Sender: TObject); 225 begin 226 if OpenPictureDialog1.Execute then begin 227 ImagePhoto.Picture.LoadFromFile(OpenPictureDialog1.FileName); 228 end; 229 end; 230 231 procedure TFormContact.APhotoSaveExecute(Sender: TObject); 232 begin 233 if SavePictureDialog1.Execute then begin 234 ImagePhoto.Picture.SaveToFile(SavePictureDialog1.FileName); 235 end; 214 236 end; 215 237 … … 294 316 MemoNotes.Lines.Text := Contact.Fields[cfNote]; 295 317 318 // Photo 296 319 ImagePhoto.Picture.Bitmap.Clear; 297 320 PhotoProperty := Contact.GetProperty(cfPhoto); … … 326 349 end; 327 350 end; 351 UpdateInterface; 328 352 end; 329 353 330 354 procedure TFormContact.SaveData; 355 var 356 Photo: string; 357 PhotoProperty: TContactProperty; 358 Stream: TMemoryStream; 359 JpegImage: TJpegImage; 331 360 begin 332 361 // General … … 382 411 // Others 383 412 Contact.Fields[cfNote] := MemoNotes.Lines.Text; 413 414 // Photo 415 if (ImagePhoto.Picture.Bitmap.Width <> 0) and (ImagePhoto.Picture.Bitmap.Height <> 0) then begin 416 PhotoProperty := Contact.GetProperty(cfPhoto); 417 if not Assigned(PhotoProperty) then begin 418 PhotoProperty := TContactProperty.Create; 419 PhotoProperty.Name := 'PHOTO'; 420 PhotoProperty.Attributes.DelimitedText := 'JPEG'; 421 Contact.Properties.Add(PhotoProperty); 422 end; 423 PhotoProperty.Encoding := 'BASE64'; 424 Stream := TMemoryStream.Create; 425 try 426 if PhotoProperty.Attributes.IndexOf('JPEG') <> -1 then begin 427 JpegImage := TJPEGImage.Create; 428 try 429 try 430 JpegImage.SetSize(ImagePhoto.Picture.Bitmap.Width, ImagePhoto.Picture.Bitmap.Height); 431 JpegImage.Canvas.Draw(0, 0, ImagePhoto.Picture.Bitmap); 432 JpegImage.SaveToStream(Stream); 433 except 434 end; 435 finally 436 JpegImage.Free; 437 end; 438 end else begin 439 try 440 ImagePhoto.Picture.SaveToStream(Stream); 441 except 442 end; 443 end; 444 445 SetLength(Photo, Stream.Size); 446 Stream.Position := 0; 447 Stream.Read(Photo[1], Length(Photo)); 448 Contact.Fields[cfPhoto] := Photo; 449 finally 450 Stream.Free; 451 end; 452 end; 453 end; 454 455 procedure TFormContact.UpdateInterface; 456 begin 457 APhotoSave.Enabled := (ImagePhoto.Picture.Bitmap.Width <> 0) and 458 (ImagePhoto.Picture.Bitmap.Height <> 0); 384 459 end; 385 460
Note:
See TracChangeset
for help on using the changeset viewer.