Этот код не работает так как надо:
| Код | unit Unit1;
interface
uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,GDIPAPI,GDIPOBJ, StdCtrls, ExtCtrls, ComCtrls, Math;
type TForm1 = class(TForm) Timer1: TTimer; Button1: TButton; procedure P(Pos, Max, Rmax, Rmin: Integer); procedure FormCreate(Sender: TObject); procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); private { Private declarations } public { Public declarations } end;
var Form1: TForm1; GraphicsGDIPlus : TGPGraphics; Pen: TGPPen; SolidBrush: TGPSolidBrush; I, I1: Integer;
implementation
{$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin DoubleBuffered:=True; end;
procedure TForm1.P(Pos, Max, Rmax, Rmin: Integer); var F, X, Y: Extended; begin if Pos>Max then Exit; F:=2 * Pi * Pos / Max; SinCos(F, X, Y); GraphicsGDIPlus.DrawLine(Pen, Rmax + X * Rmin, Rmax + Y * Rmin, Rmax + X * Rmax, Rmax + Y * Rmax); end;
procedure TForm1.Timer1Timer(Sender: TObject); begin Repaint; GraphicsGDIPlus.FillEllipse(SolidBrush,95,95,10,10); for I:=0 to 100 do begin P(I,10,100,85); P(I,20,100,90); P(I,100,100,95); end; P(I1,100,100,0); Inc(I1, 1); if I1>100 then I1:=10; Caption:=IntToStr(I1); end;
procedure TForm1.Button1Click(Sender: TObject); begin GraphicsGDIPlus:=TGPGraphics.Create(Canvas.Handle); GraphicsGDIPlus.SetSmoothingMode(SmoothingModeHighQuality); Pen:=TGPPen.Create(MakeColor(255, 0, 0, 0), 2); SolidBrush:=TGPSolidBrush.Create(MakeColor(255, 0, 0, 0)); Timer1.Enabled:=True; end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction); begin Pen.Free; SolidBrush.Free; GraphicsGDIPlus.Free; end; end.
|
А вот так работае:
| Код | procedure TForm1.Timer1Timer(Sender: TObject); begin Repaint; GraphicsGDIPlus:=TGPGraphics.Create(Canvas.Handle); GraphicsGDIPlus.SetSmoothingMode(SmoothingModeHighQuality); Pen:=TGPPen.Create(MakeColor(255, 0, 0, 0), 2); SolidBrush:=TGPSolidBrush.Create(MakeColor(255, 0, 0, 0)); GraphicsGDIPlus.FillEllipse(SolidBrush,95,95,10,10); for I:=0 to 100 do begin P(I,10,100,85); P(I,20,100,90); P(I,100,100,95); end; P(I1,100,100,0); Inc(I1, 1); if I1>100 then I1:=10; Pen.Free; SolidBrush.Free; GraphicsGDIPlus.Free; Caption:=IntToStr(I1); end;
|
Вопрос: почему когда:
| Код | GraphicsGDIPlus:=TGPGraphics.Create(Canvas.Handle); GraphicsGDIPlus.SetSmoothingMode(SmoothingModeHighQuality); Pen:=TGPPen.Create(MakeColor(255, 0, 0, 0), 2); SolidBrush:=TGPSolidBrush.Create(MakeColor(255, 0, 0, 0));
Pen.Free; SolidBrush.Free; GraphicsGDIPlus.Free;
|
выносиш за пределы одной процедуры то ничего не рисует??? И как от этого избавится??? |