Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to create a 'line' object.

Posted on 1997-06-04
3
Medium Priority
?
179 Views
Last Modified: 2010-04-06
I'm just beginning delphi.  In general, I don't have much experience on the graphical side of things.  Mostly I write business apps.

I know that the Canvas property has LineTo and MoveTo stuff for drawing lines.  The problem is that I want to be able to move these lines at runtime.  In VB there is a line object that can be moved.  How do I do this in delphi?

I'm creating a program that allows a user to graphically connect two boxes with a line.  When the box moves (by the user), I want the lines to move as well. Also I want the user to be able to grab the line and reposition it as well.  

Any help, code would be great.



0
Comment
Question by:blitz051697
3 Comments
 
LVL 1

Expert Comment

by:jackb022197
ID: 1336814
I guess you have to overwrite the original line with the background color and then draw the new line in in the correct color...
0
 

Author Comment

by:blitz051697
ID: 1336815
I realize I could do that.  But it is not a true object.  I assume someone has arlready done this.    

I want to be able to click the line.  Have handles appear.  Move with the attached object.  
0
 

Accepted Solution

by:
arnoldu earned 300 total points
ID: 1336816
Dear Blitz, think I have a solution for your problem:
To have a kind of "line" object you should declare a new class, give them some properties and methods and have an event handler for mouse events which creates objects of your new lines class (="Draw") or manipulates parameters of existing (="moving"). You should keep all your lines inside a TList of it. A sample source code for the class would be:

TBlitzLine = class
                       constructor create(x1,y1,x2,y2, color, width : Integer);
        public
          fx1,fy1,fx2,fy2,fcolor,fwidth : Integer;
          Procedure Draw(DrawOn : TCanvas);
        end;

Then your form could have a List of those objects with

      Linelist : TList;

and furtheron (in createform)

   LineList := TList.Create;

and ListList.Free in destroyForm

The mouse interface for moving lines must find the line next to the mouse click - so you have to compare the x,y mouse coordinates from the mousemove event with any line. The best is to calculate the distance from the x,y point to the line or to the endpoints of line and have a "range" within a line is selected. And following mousemove events must change this line endpoints accordingly to the mouse movement. The paint method of the form should go through the complete list and draw all lines using their Draw-method called with the canvas of the form or whereever you want them to be drawn.

Is this enough to understand what I mean?

Arnold
                     

end;


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question