Solved

How to create a 'line' object.

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now