// Bitmap Assign Engima in D3 and D4. Fixed in D5. // efg, 6 Feb 2000 unit ScreenBitmapAssignEnigma; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls; type TForm1 = class(TForm) ButtonRun: TButton; Image1: TImage; Image2: TImage; CheckBoxKludge: TCheckBox; procedure ButtonRunClick(Sender: TObject); procedure CheckBoxKludgeClick(Sender: TObject); private PROCEDURE UpdateBitmap; public { Public declarations } end; var Form1: TForm1; implementation {$R *.DFM} PROCEDURE TForm1.UpdateBitmap; TYPE TRGBTripleArray = ARRAY[WORD] OF TRGBTriple; pRGBTripleArray = ^TRGBTripleArray; VAR Bitmap1: TBitmap; Bitmap2: TBitmap; i,j: INTEGER; Row: pRGBTripleArray; BEGIN Bitmap1 := TBitmap.Create; TRY Bitmap1.Width := Image1.Width; Bitmap1.Height := Image1.Height; Bitmap1.PixelFormat := pf24bit; Bitmap1.Canvas.Brush.Color := clYellow; Bitmap1.Canvas.FillRect(Bitmap1.Canvas.ClipRect); // Keep Bitmap1 as an untouched "orignal". Bitmap2 should // be a "deep copy" of Bitmap1, not just a pointer to it. Bitmap2 := TBitmap.Create; TRY Bitmap2.Assign(Bitmap1); // Kludge to force independent copy in D3 and D4. IF CheckBoxKludge.Checked THEN Bitmap2.Canvas.Pixels[0,0] := Bitmap2.Canvas.Pixels[0,0]; // Change Bitmap2 -- don't do anything to Bitmap1 FOR j := 0 TO Bitmap2.Height-1 DO BEGIN Row := Bitmap2.ScanLine[j]; FOR i := 0 TO Bitmap2.Width-1 DO BEGIN WITH Row[i] DO BEGIN rgbtRed := 0; rgbtGreen := 0; rgbtBlue := 255; END END END; // Display both bitmaps -- should be different. // Image1 should always be yellow, Image2 should be blue. // Only true if "kludge" is checked in D3 and D4. // Always true in D5. Image1.Picture.Graphic := Bitmap1; Image2.Picture.Graphic := Bitmap2; FINALLY Bitmap2.Free END FINALLY Bitmap1.Free END END; procedure TForm1.ButtonRunClick(Sender: TObject); begin UpdateBitmap end; procedure TForm1.CheckBoxKludgeClick(Sender: TObject); begin UpdateBitmap end; end.