TA的每日心情 | 衰 2021-8-18 08:54 |
---|
签到天数: 1421 天 [LV.10]以坛为家III
|
同样执行下面的代码,模拟一个石英钟,为何两者的执行效果差那么远?
Delphi7 下:
Lazarus 1.08下:
下面是代码:
unit clock;
{$IFDEF FPC}
{$MODE Delphi}
{$ENDIF}
interface
uses
{$IFNDEF FPC}
Windows,
{$ELSE}
LCLIntf, LCLType, LMessages,
{$ENDIF}
Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
StatusBar1: TStatusBar;
pnl1: TPanel;
img1: TImage;
tmr1: TTimer;
procedure FormCreate(Sender: TObject);
procedure tmr1Timer(Sender: TObject);
private
firsttime:Boolean;
vho,vmo,vso:Real;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
var
i:Integer;
begin
with Form1.img1.Canvas do begin
Pen.Color:=clWhite;
Pen.Style:=psSolid;
Pen.Width:=1;
Brush.Color:=clWhite;
Rectangle(0,0,Width,Height);
Pen.Color:=clBlack;
for i:=1 to 12 do
Pixels[img1.Width div 2+ Round(img1.Width div 2*sin(i/12.0*2*pi)),
img1.Width div 2-round(img1.Width div 2*cos(i/12.0*2*pi))]:=clBlack;
end;
end;
procedure TForm1.tmr1Timer(Sender: TObject);
var
mynow:TDateTime;
hour,min,sec,msec:Word;
vh,vm,vs:Real;
PoiLong:Integer;
begin
mynow:=Now();
DecodeTime(mynow,hour,min,sec,msec);
vm:=min/60.0*2*pi;
vh:=hour/12.0*2*pi+(vm/12);
vs:=sec/60.0*2*pi;
with Form1.img1.Canvas do begin
PoiLong := img1.Width div 2;
{ if not firsttime then
begin }
Pen.Color:=clWhite;
MoveTo(PoiLong,PoiLong);
LineTo(PoiLong+round(PoiLong/3*sin(vho)),PoiLong-round(PoiLong/3*cos(vho)));
MoveTo(PoiLong,PoiLong);
LineTo(PoiLong+round(PoiLong/2*sin(vmo)),PoiLong-round(PoiLong/2*cos(vmo)));
MoveTo(PoiLong,PoiLong);
LineTo(PoiLong+round(PoiLong/1.5*sin(vso)),PoiLong-round(PoiLong/1.5*cos(vso)));
(* end
else
firsttime:=false; *)
Pen.Color:=clBlack;
MoveTo(PoiLong,PoiLong);
LineTo(PoiLong+round(PoiLong/3*sin(vh)),PoiLong-round(PoiLong/3*cos(vh)));
MoveTo(PoiLong,PoiLong);
LineTo(PoiLong+round(PoiLong/2*sin(vm)),PoiLong-round(PoiLong/2*cos(vm)));
MoveTo(PoiLong,PoiLong);
LineTo(PoiLong+round(PoiLong/1.5*sin(vs)),PoiLong-round(PoiLong/1.5*cos(vs)));
end;
vho:=vh;
vmo:=vm;
vso:=vs;
StatusBar1.Panels[0].Text:='System Time:' + DateTimeToStr(Now());
end;
end.
为啥呢?百思不得其解,请论坛大虾指教。
Good Luck~
|
|