Solved

How to create a 'line' object.

Posted on 1997-06-04
3
174 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

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

Suggested Solutions

Title # Comments Views Activity
Mobile Keyboard covers the display of the TMemo 3 112
Convert MS Word document to a PDF file 9 130
RESTRequest Parameter 4 76
Delphi, TImage, Png 2 51
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

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