起步软件技术论坛-X3

 找回密码
 立即注册
搜索
查看: 207|回复: 3

【搞定】[请求]在X3平台下,怎么实现Record的定义?

[复制链接]
发表于 2007-5-24 11:08:58 | 显示全部楼层 |阅读模式
在X3平台下,怎么实现record的定义?如果不能实现,怎么用其它的方法能够绕过去?

附代码如下:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, TeeProcs, TeEngine, Chart, ExtCtrls, StdCtrls, Series, DB, ADODB,
  DbChart, Buttons, ImgList;

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    btn1: TButton;
    ADOConnection1: TADOConnection;
    ADOQuery1: TADOQuery;
    ADOQuery2: TADOQuery;
    Chart3: TChart;
    LineSeries1: TLineSeries;
    Button1: TButton;
    btn2: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    ColorBox1: TColorBox;
    Image1: TImage;
    BitBtn1: TBitBtn;
    ImageList1: TImageList;
    BitBtn2: TBitBtn;
    procedure btn2Click(Sender: TObject);
    procedure Chart3MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Chart3MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure Chart3MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure BitBtn1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);

  private
    { Private declarations }

     procedure preMove(myPoint:TPoint);
     procedure preDel(myPoint:TPoint);
     function prepare(myPoint,firstPoint,secondPoint:TPoint):boolean;
     procedure realMoveLine(myPoint:TPoint);
     procedure drawLine(topLeft: TPoint; bottomRight: TPoint);//me
    // procedure preFill(myPoint:TPoint);
  public
    { Public declarations }

  end;

type myDraw=(null,myLine,myRect,myEllips,myCircle);
type pLine=^recordLine;
     recordLine=record
     originP,finalP:TPoint;
     lineColor:TColor;
     next:pLine;
     end;

var
  Form1: TForm1;

  drawing,filling,moving,deling: Boolean;
  movingLine,movingRect,movingEllips,movingCircle:Boolean;
  myDrawStart:myDraw;
  origin,movePt:TPoint;
  itsLine,firstLine,lastLine,dLine:pLine;

implementation

{$R *.dfm}

procedure TForm1.btn2Click(Sender: TObject);
begin
  Image1.Canvas.LineTo(100,1000);
  myDrawStart:=myLine;
  filling:=false;
  moving:=false;
  deling:=false;
  edit1.Text :='绘制直线:拾取起始点(按下鼠标左键)';
end;

procedure TForm1.drawLine(topLeft: TPoint; bottomRight: TPoint);
begin

  with Chart3.canvas do
  begin
    MoveTo(topLeft.x,topLeft.y);
     
    Draw(topLeft.X,topLeft.Y,BitBtn2.Glyph);
    lineto(bottomRight.x,bottomRight.y);
  end;
end;

procedure TForm1.preMove(myPoint:TPoint);
begin
  itsLine:=firstLine^.next ;
  while itsLine<>nil do
  begin
   
    if prepare(myPoint,itsLine^.originP,itsLine^.finalP) then
    begin
      edit1.Text :='拾取移动终止点:按住左键并且移动鼠标至终止点再松开';
      realMoveLine(myPoint);
      movingLine:=True;

      exit;//<<<<<<<<<<<<<<<  Bug !!! <<<<<<<<<<
    end;
    itsLine:=itsLine^.next ;
  end;
  if itsLine=nil then
     itsLine:=lastLine;   //<<<<<< Bug! <<

end;

procedure TForm1.preDel(myPoint:TPoint);
begin
  dLine:=firstLine;
  itsLine:=firstLine^.next ;
  while itsLine<>nil do
  begin
    if prepare(myPoint,itsLine^.originP,itsLine^.finalP) then
    begin
      edit1.Text :='继续刚才的操作类型,或者重新选择操作类型';
      Chart3.Canvas.Pen.Color := clRed;
      drawLine(itsLine^.originP,itsLine^.finalP);
      dLine^.next :=itsLine^.next ;
      if itsLine=lastLine then
         lastLine:=dLine;
      dispose(itsLine);
      itsLine:=lastLine;

      exit;//
    end;
    dLine:=dLine^.next ;
    itsLine:=itsLine^.next ;
  end;
  if itsLine=nil then
     itsLine:=lastLine;   //
end;

procedure TForm1.Chart3MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if button=mbLeft then
  begin
    drawing:=true;
    Chart3.Canvas.Pen.Color :=colorbox1.Selected;
    origin:=Point(x,y);
    movePt:=origin;
    if moving=true then
    begin
      drawing:=false;
      premove(origin);
    end;
    if deling=true then
    begin
      drawing:=false;
      preDel(origin);
    end;

    if drawing=true then
    begin
      edit1.Text :='拾取终点:按住左键并且移动鼠标至终点再松开';
    end;

  end;
end;

function TForm1.prepare(myPoint,firstPoint,secondPoint:TPoint):boolean;
var
  lengthA,lengthB,lengthC:real;
  lengthX,lengthY:real; //integer;
begin
  lengthX:=abs(myPoint.X-firstPoint.X );
  lengthY:=abs(myPoint.Y-firstPoint.Y );
  lengthX:=sqr(lengthX);
  lengthY:=sqr(lengthY);
  lengthA:=sqrt(lengthX+lengthY);

  lengthX:=abs(myPoint.X-secondPoint.X );
  lengthY:=abs(myPoint.Y-secondPoint.Y );
  lengthX:=sqr(lengthX);
  lengthY:=sqr(lengthY);
  lengthB:=sqrt(lengthX+lengthY);

  lengthX:=abs(secondPoint.X-firstPoint.X );
  lengthY:=abs(secondPoint.Y-firstPoint.Y );
  lengthX:=sqr(lengthX);
  lengthY:=sqr(lengthY);
  lengthC:=sqrt(lengthX+lengthY);

  if lengthA+lengthB<lengthC+1 then
    result:=true
  else
    result:=false;
end;

procedure TForm1.realMoveLine(myPoint:TPoint);
var
  deltaX,deltaY:integer;
  firstPoint,secondPoint:TPoint;
begin
  Chart3.Canvas.Pen.Color :=itsLine^.lineColor ;
  drawLine(itsLine^.originP,itsLine^.finalP);
  deltaX:=-origin.X+myPoint.X;
  deltaY:=-origin.Y+myPoint.Y;
  firstPoint:=Point(itsLine^.originP.X+deltaX,itsLine^.originP.Y+deltaY);
  secondPoint:=Point(itsLine^.finalP.X+deltaX,itsLine^.finalP.Y+deltaY);
  drawLine(firstPoint,secondPoint);
  origin:=myPoint;
  itsLine^.originP:=firstPoint;
  itsLine^.finalP:=secondPoint;
end;

procedure TForm1.Chart3MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
label1.Caption:='坐标  ( '+intToStr(x)+' , '+intToStr(Chart3.Height-y)+' )';
if drawing then
begin
Chart3.Canvas.Pen.Mode :=pmNotXor;  //--------?????
Chart3.Canvas.Brush.Style :=bsClear;//<<< !!!

case myDrawStart of
   myLine:
     begin
       drawLine(origin,movePt);
       movePt:=Point(x,y);
       drawLine(origin,movePt);
     end;
end;
end;

if movingLine then
  begin
  movePt:=Point(x,y);
  realMoveLine(movePt);
  end;
end;

procedure TForm1.Chart3MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
if button=mbLeft then
begin
if drawing then
begin
  drawing:=false;

  edit1.Text :='继续刚才的操作类型,或者重新选择操作类型';

case myDrawStart of
   myLine:
   begin
     new(itsLine^.next);
     itsLine:=itsLine^.next;
     itsLine^.originP:=origin;
     itsLine^.finalP:=movePt;
     itsLine^.lineColor:=Chart3.Canvas.Pen.Color;
     lastLine:=itsLine;
   end;
end;
if movingLine then
begin
   movingLine:=false;   //<<<<<<<<  Right
   itsLine:=lastLine;
   edit1.Text :='继续刚才的操作类型,或者重新选择操作类型';
end;
end;
end;


if movingLine then
begin
   movingLine:=false;   //<<<<<<<<  Right
   itsLine:=lastLine;
   edit1.Text :='继续刚才的操作类型,或者重新选择操作类型';
end;

end;

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
deling:=true;
  filling:=false;
  moving:=false;

  edit1.Text :='删除图形(请选择图形的轮廓线)';
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
drawing:=false;
  filling:=false;
  moving:=false;
  deling:=false;

  movingLine:=false;
  movingRect:=false;
  movingEllips:=false;
  movingCircle:=false;

  edit1.Text :='请选择操作类型:选择下拉菜单或者操作按钮';

  new(itsLine);
  itsLine^.next:=nil;
  firstLine:=itsLine ;  //<<<<<<<<<<<<<
  lastLine:=itsLine;
end;

end.
回复

使用道具 举报

发表于 2007-5-25 11:05:45 | 显示全部楼层
期待中,顶上
回复 支持 反对

使用道具 举报

发表于 2007-5-25 11:34:38 | 显示全部楼层
不用记录,你可以用对象啊
回复 支持 反对

使用道具 举报

 楼主| 发表于 2007-5-29 10:42:27 | 显示全部楼层
谢谢楼主,结帖。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-1-10 23:37 , Processed in 0.035787 second(s), 15 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表