{------------------------------------------------------------------------------} { Unit Name: portForm Purpose : To show problems when porting Delphi 5 project to Kylix Author : Vesa Lappalainen, vesal@mit.jyu.fi Date : 4.11.2000 Changed : Usage : Make new project and replace main units code by this unit. All components are made dynamically, so the .dfm can be very minimal. Following unit aliases was used in Kylix: ExtCtrls=QExtCtrls;Messages=QImgList;Windows=Types;StdCtrls=QStdCtrls;Dialogs=QDialogs;Forms=QForms;Controls=QControls;Graphics=QGraphics;WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE; ToDo : } {------------------------------------------------------------------------------} (* Problems with IDE (GNome): 1) From keyboard f.ex ALt-F - j (Open Project) does not put focus to Open Project -dialog. 2) When clicking f.ex Button-control to made ButtonClick, focus does not change to code window 3) Does not show "running" on the main window bar. 4) New projects code window starts very small {------------------------------------------------------------------------------} Problems when porting from Delphi 5 project: #1) No Form.DoubleBuffered (even an dummy one if not needed) #2) {$ *.DFM} not understood, Delphi (until ver 5) puts that allways It could be better if .DFM is not found, .dfm is searched (at least an option for that) Same with {$.RES} #3) TGraphicControl.Invalidate does not clear the backround as it does in Windows version. I found that in some project, but could not repeat in this project. #4) TBitmap.TransparentColor works strange compared to Delphi 5-version. F.ex loading two times a bitmap from file to same bitmap (of course coping the result f.ex TImageList in between) changes the TransparentColor. In this example the third picture is not drawn correctly in Kylix-version #5) TCanvas.CopyRect not working like in Delphi-version (in Windows version if rectancle is "mirrored", the the picture is Mirrored) #6) Function RGB missing #7) Kylix can't use .res file made from .rc file in Windows (to collect lot of bitmaps inside final application) #8) TImageList.Add works strange in Kylix if any bitmap has TransparentColor other that default *) {------------------------------------------------------------------------------} unit portform; interface uses SysUtils, Classes, QGraphics, QControls, QForms, QDialogs, QStdCtrls, QImgList, QExtCtrls, Types; type TForm1 = class(TForm) procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private FIndex : integer; FImageList : TImageList; FPaintBox : TPaintBox; ButtonFlip : TButton; public procedure OnPaintBoxPaint(Sender: TObject); procedure OnFlipClick(Sender: TObject); constructor Create(AOwner : TComponent); override; end; var Form1: TForm1; implementation {$R *.dfm} // #2 if .DFM Kylix does not find form { TForm1 } constructor TForm1.Create(AOwner: TComponent); begin inherited; OnCreate := FormCreate; end; procedure TForm1.FormCreate(Sender: TObject); // Creates three bitmaps: // // \ / // ---\ /--- ---/ // / // 1. 2. 3. // // and puts them to imagelist. // 1. and 3. are drawn directly to bitmap rbmp // 2. is mirrored from 1 to lbmp // // 3. is not drawn correctly if Transparent color is // in default state (all assignments commented) or white or black // {$define MASKED} // #8 Comment this to get non-masked behaviour var lbmp,rbmp : TBitmap; rect,rect2 : TRect; begin // DoubleBuffered := True; // #1, not working in Kylix FIndex := 0; ButtonFlip := TButton.Create(self); ButtonFlip.Parent := self; ButtonFlip.Caption := '&Flip'; ButtonFlip.OnClick := OnFlipClick; rbmp := TBitmap.Create; rbmp.Height := 200; rbmp.Width := 200; rect.Left := 0; // rect for helping coping rect.Top := 0; rect.Right := rbmp.Width; rect.Bottom := rbmp.Height; rbmp.Canvas.Pen.Color := clBlack; rbmp.Canvas.Brush.Color := clWhite; rbmp.Canvas.Rectangle(rect); rbmp.Canvas.Pen.Color := clBlack; // first picture -\ rbmp.Canvas.MoveTo(0,100); rbmp.Canvas.LineTo(200,100); rbmp.Canvas.LineTo(100,0); // rbmp.TransparentColor := 1; // #4 only this works in Kylix // rbmp.TransparentColor := RGB(255,255,255); // #6 does not work in Kylix // rbmp.TransparentColor := clWhite; // lbmp := TBitmap.Create; // lbmp.Assign(rbmp); // Do identical bmp // lbmp.FreeImage; // lbmp.FreePixmap; lbmp.Width := rbmp.Width; lbmp.Height := rbmp.Height; lbmp.TransparentColor := clWhite; rect2 := rect; // rect2 is a mirror from rect rect2.Right := -1; rect2.Left := rect.Right-1; // Mirror to /- // lbmp.Canvas.CopyRect(rect2,rbmp.Canvas, rect); // #5 does not work in Kylix lbmp.Canvas.StretchDraw(rect2,rbmp); // This works correctly FImageList := TImageList.Create(self); FImageList.Width := rbmp.Width; FImageList.Height := rbmp.Height; {$ifdef MASKED} FImageList.AddMasked(rbmp,rbmp.TransparentColor); FImageList.AddMasked(lbmp,rbmp.TransparentColor); {$else} FImageList.Masked := false; FImageList.Add(rbmp,nil); FImageList.Add(lbmp,nil); {$endif} // rbmp.FreeImage; // rbmp.FreePixmap; rbmp.Canvas.Pen.Color := clBlack; rbmp.Canvas.Brush.Color := clWhite; rbmp.Canvas.Rectangle(rect); rbmp.Canvas.Pen.Color := clBlack; // Third picture -/ rbmp.Canvas.MoveTo(0,100); rbmp.Canvas.LineTo(200,100); rbmp.Canvas.LineTo(100,200); // rbmp.TransparentColor := clWhite; // rbmp.TransparentColor := clBlack; {$ifdef MASKED} FImageList.AddMasked(rbmp,rbmp.TransparentColor); {$else} FImageList.Add(rbmp,nil); {$endif} FPaintBox := TPaintBox.Create(self); FPaintBox.Parent := self; FPaintBox.Top := 100; FPaintBox.Left := 100; FPaintBox.Width := 200; FPaintBox.Height := 200; FPaintBox.OnPaint := OnPaintBoxPaint; lbmp.Free; rbmp.Free; end; procedure TForm1.OnFlipClick(Sender: TObject); begin FIndex := (FIndex+1) mod 3; FPaintBox.Invalidate; end; procedure TForm1.OnPaintBoxPaint(Sender: TObject); begin FImageList.Draw(FPaintBox.Canvas,0,0,FIndex); end; procedure TForm1.Button1Click(Sender: TObject); begin // end; end.