Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to create a 'line' object.

Posted on 1997-06-04
3
Medium Priority
?
177 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

722 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