home *** CD-ROM | disk | FTP | other *** search
- unit Main;
-
- { Program copyright (c) 1995 by Charles Calvert }
- { Project Name: LINELOOP }
-
- { Demonstrates how to use the Canvas MoveTo and LineTo
- routines. Also shows how to handle PeekMessage loops,
- which is all about sharing processor time with other
- programs. More general info about coordinates, and
- about using the RGB function to access the colors
- available on your system.
-
- Note the comments above the call to YieldToOthers }
-
- interface
-
- uses
- WinTypes, WinProcs,
- Classes, Messages,
- Graphics, Controls, Printers,
- Forms, Menus;
-
- type
- TForm1 = class(TForm)
- MainMenu1: TMainMenu;
- Start1: TMenuItem;
- Start2: TMenuItem;
- Stop1: TMenuItem;
- procedure BStartClick(Sender: TObject);
- procedure BStopClick(Sender: TObject);
- private
- Draw: Boolean;
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
-
- { You can call either YieldToOthers, or the built
- in function: Application.ProcessMessages }
- procedure YieldToOthers;
- var
- Msg : TMsg;
- begin
- while PeekMessage(Msg,0,0,0,PM_REMOVE) do begin
- if (Msg.Message = WM_QUIT) then begin
- exit;
- end;
- TranslateMessage(Msg);
- DispatchMessage(Msg);
- end;
- end;
-
- procedure TForm1.BStartClick(Sender: TObject);
- var
- R: TRect;
- x, y: Integer;
- begin
- Canvas.MoveTo(10, 10);
- R := GetClientRect;
- Draw := True;
- while Draw do begin
- x := Random(R.Right);
- y := Random(R.Bottom);
- Canvas.Pen.Color := RGB(Random(255), Random(255), Random(255));
- Canvas.LineTo(X, Y);
- YieldToOthers; { or Application.ProcessMessages }
- end;
- end;
-
- procedure TForm1.BStopClick(Sender: TObject);
- begin
- Draw := False;
- end;
-
- end.
-