Solved

How to create a 'line' object.

Posted on 1997-06-04
3
175 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 100 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

Technology Partners: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

734 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