Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 8th, 2010, 10:43 AM   #21
alienkinetics
Programmer
 
alienkinetics's Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 56
Rep Power: 1 alienkinetics is on a distinguished road
Simple. Just Override DblClick(). There is a little issue with mouse clicks that is easierly solved. InputQuery() is a cool function from the Dialogs Unit.

uses Dialogs; << Add dialogs to your uses list

  TWorkFlowShape = class(TPaintBox)
  public
    procedure DblClick; override; <<< Add New Method
  end;

procedure TWorkFlowShape.DblClick;
var S: String;
begin
  FIgnoreClick := True; // Ignore a mouse down click. Read below
  if InputQuery(Application.Title, 'Enter Text', S) then
  begin
    Text := S;
    Invalidate;
  end;
end;

Add the variable FIgnoreClick:Boolean to the TWorkflowShape class. In the MouseDown method add this code to the start:

if FIgnoreClick then
  begin
    FIgnoreClick := False;
    Exit;
  end;

This enables us to ignore a mousedown click when we receive a Double click.
alienkinetics is offline   Reply With Quote
Old Feb 8th, 2010, 12:07 PM   #22
abdul.gafur
Trying to be a Real Coder
 
abdul.gafur's Avatar
 
Join Date: Feb 2010
Location: Salo, Riau, Indonesia
Posts: 112
Rep Power: 1 abdul.gafur is on a distinguished road
Send a message via Yahoo to abdul.gafur
Re: Drag and drop shape

So cool. I'm got it.

Oke. Biggest obstacle right now is how to make line that can be drag and drop, I really have no clue.
If this problem has been solved, the next step is how to build a database, I've never done before, any suggestion?

Just a little confide, I have learned tool that can build a web based apps, such as flash, js, or java applet before. But, my lecturer recommends for using delphi. Indeed, I've made a monopoly game using delphi, but I don't understand graphic on Delphi.

{please understandable, I found it difficult to write English sentences correctly }
__________________
just a drop of dew in the morning
abdul.gafur is offline   Reply With Quote
Old Feb 8th, 2010, 2:29 PM   #23
alienkinetics
Programmer
 
alienkinetics's Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 56
Rep Power: 1 alienkinetics is on a distinguished road
Re: Drag and drop shape

Here are some updates. Now supports text editing, multiple connections and you can detach/attach connections to different shapes. Double click a "grip" to disconnect a connector, and then drag it over another grip to reconnect it.

Workflow.png

Workflow.zip

As for loading and saving. I normally use TXMLDocument. I code each class so it knows how to load and save, too and from TXMLNode's. If you haven't used XML before, then you can try TIniFile which is a bit easier, but has its limitations.
alienkinetics is offline   Reply With Quote
Old Feb 8th, 2010, 7:11 PM   #24
abdul.gafur
Trying to be a Real Coder
 
abdul.gafur's Avatar
 
Join Date: Feb 2010
Location: Salo, Riau, Indonesia
Posts: 112
Rep Power: 1 abdul.gafur is on a distinguished road
Send a message via Yahoo to abdul.gafur
Re: Drag and drop shape

delphi Syntax (Toggle Plain Text)
  1.  
  2. P := ClientToScreen(Point(Width div 2, Height div 2));
  3. for I := 0 to Parent.ControlCount - 1 do
  4. try
  5. LShape := Parent.Controls[i] as TWorkFlowShapeGripped; //<-- error : invalid class typecast
  6. LGripCode := LShape.GetGripFromScreenPoint(P);
  7. if LGripCode > 0 then
  8. begin
__________________
just a drop of dew in the morning
abdul.gafur is offline   Reply With Quote
Old Feb 8th, 2010, 10:51 PM   #25
abdul.gafur
Trying to be a Real Coder
 
abdul.gafur's Avatar
 
Join Date: Feb 2010
Location: Salo, Riau, Indonesia
Posts: 112
Rep Power: 1 abdul.gafur is on a distinguished road
Send a message via Yahoo to abdul.gafur
Re: Drag and drop shape

I want to add an event on FPaintBox
delphi Syntax (Toggle Plain Text)
  1. ...
  2. TWorkFlow = class(TScrollBox)
  3. private
  4. FPaintBox: TPaintBox;
  5. public
  6. LConnector: TWorkFlowShapeConnector;
  7. public
  8. constructor Create(AOwner: TComponent); override;
  9. procedure Paint(ASender: TObject);
  10. procedure FPaintBoxDblClick(Sender: TObject);
  11. end;
  12. ...
  13.  
  14. Implementation
  15. ...
  16. procedure TWorkFlow.FPaintBoxDblClick(Sender: TObject);
  17. begin
  18. ShowMessage('Do Something'); // do something
  19. end;
  20. ..

When I double click on FPaintBox, the popup (ShowMessage('Do Something'); ) does not appear
__________________
just a drop of dew in the morning
abdul.gafur is offline   Reply With Quote
Old Feb 9th, 2010, 1:01 AM   #26
alienkinetics
Programmer
 
alienkinetics's Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 56
Rep Power: 1 alienkinetics is on a distinguished road
Re: Drag and drop shape

Quote:
RE: //<-- error : invalid class typecast
The code compiles out of the box. You might have accidently hacked the code. To extend the code I uses exactly the same method as my previous posts described.

Quote:
When I double click on FPaintBox, the popup (ShowMessage('Do Something'); ) does not appear
There are 3 main ways to catch messages in Delphi.

1) Overload a method (Only works if you inherit from a class)
2) Patch into a "notify event". (Works when another class wants the events). Note, if multiple methods connect to an event, you need to make sure you link the events. Otherwise, you disable code.
3) "message methods". Used for messages that haven't been implemented by Delphi. This is non-portable to CLX

So, you need number 2. which means you need this in the TWorkFlow constructor:

Quote:
FPaintBox.OnDblClick := FPaintBoxDblClick;
alienkinetics is offline   Reply With Quote
Old Feb 9th, 2010, 5:43 AM   #27
abdul.gafur
Trying to be a Real Coder
 
abdul.gafur's Avatar
 
Join Date: Feb 2010
Location: Salo, Riau, Indonesia
Posts: 112
Rep Power: 1 abdul.gafur is on a distinguished road
Send a message via Yahoo to abdul.gafur
Re: Drag and drop shape

ok thanks. You very expert about delphi, i'm salute to you
__________________
just a drop of dew in the morning
abdul.gafur is offline   Reply With Quote
Old Feb 11th, 2010, 9:46 PM   #28
abdul.gafur
Trying to be a Real Coder
 
abdul.gafur's Avatar
 
Join Date: Feb 2010
Location: Salo, Riau, Indonesia
Posts: 112
Rep Power: 1 abdul.gafur is on a distinguished road
Send a message via Yahoo to abdul.gafur
Re: Drag and drop shape

I want to make a Line Class (TPaintBox) in workflow.pas

delphi Syntax (Toggle Plain Text)
  1. // main program
  2. L := TLine.Create(LWorkFlow);
  3. L.SetLine(250, 250, 550, 550); L.Parent := LWorkFlow;
  4.  
  5. // class workflow
  6. type
  7. TLine = class(TPaintBox)
  8. private
  9. FP1, FP2: TPoint;
  10. FIsButtonDown: array[TMouseButton] of Boolean;
  11. FGripCodeLine: Integer;
  12. public
  13. constructor Create(AOwner: TWorkFlow); reintroduce; virtual;
  14. procedure Paint; override;
  15. procedure DblClick; override;
  16. procedure SetLine(X1, Y1, X2, Y2 : integer);
  17. end;
  18.  
  19. Implementation
  20. constructor TLine.Create(AOwner: TWorkFlow);
  21. begin inherited Create(AOwner);
  22.  
  23. end;
  24.  
  25. procedure TLine.SetLine(X1, Y1, X2, Y2 : integer);
  26. begin inherited;
  27. FP1.x := X1; FP1.Y := Y1;
  28. FP2.x := X2; FP2.Y := Y2;
  29. end;
  30.  
  31. procedure TLine.Paint;
  32. var I: Integer; R: TRect;
  33. begin inherited;
  34. Canvas.Pen.Color := clRed; Canvas.Pen.Width := 5;
  35. Canvas.MoveTo(FP1.X, FP1.Y);
  36. Canvas.LineTo(FP2.X, FP2.Y);
  37. end;
  38.  
  39. procedure TLine.DblClick;
  40. var S: String;
  41. begin
  42. FIgnoreClick := True; // Ignore a mouse down click. Read below
  43. if InputQuery(Application.Title, 'Enter Text', S) then
  44. begin
  45. Text := S;
  46. Invalidate;
  47. end;
  48. end;

The problem is the line doesn't appear.
I attached the project
Attached Files
File Type: zip WorkflowEdit.zip (23.6 KB, 1 views)
__________________
just a drop of dew in the morning
abdul.gafur is offline   Reply With Quote
Old Feb 12th, 2010, 1:00 AM   #29
alienkinetics
Programmer
 
alienkinetics's Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 56
Rep Power: 1 alienkinetics is on a distinguished road
Re: Drag and drop shape

The code looks ok, so maybe you havent set the Parent of the control or you haven't made the control big enough and the line is clipped.

But, I wouldn't do it this way. I would use the method in the code I posted. You will run into a pile of problems.

For you task, I would put all the lines in the same TPaintBox and use TShape's as grips. (Like my code)

Yea, I did try using seperate TPaintBox's for lines in the past and its not good. You also cant use the mouse events of the paintbox to select a line. You need to use a "point on line" algorithm.

Trust me. Its not worth the head pain
__________________
Buzz PHP Class Library - Web Components Made Easy!
http://www.buzzphp.com/
alienkinetics is offline   Reply With Quote
Old Feb 12th, 2010, 1:09 AM   #30
alienkinetics
Programmer
 
alienkinetics's Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 56
Rep Power: 1 alienkinetics is on a distinguished road
Re: Drag and drop shape

Just more issues to think about.

1) When a TPaintBox is inverted via a resize (ie: width < 0 or height < 0), doesn't get displayed. So to use it for inverted shapes or lines, you need more coding.
2) When a TPaintBox has a width or height of 0, then no line can be drawn. ie: if you have a line that is (100, 0)-(100, 100), then the line wont get drawn.
3) This method wont support zooming or rotations. If you need zooming, then you need to code your own control library (more coding)

Basiclly, look at this method as a simple way to get what you need done. For more advanced WYSIWYG GUI's, you would need to code more (ie: floating point controls), which isn't in the projects interest.

Just put all the lines (connectors) in the base control. And you can code all your line selector code there.
__________________
Buzz PHP Class Library - Web Components Made Easy!
http://www.buzzphp.com/
alienkinetics is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
popup with drag and drop wont work. RareDevil JavaScript and Client-Side Browser Scripting 1 Mar 7th, 2009 3:52 PM
Drag and Drop Text in C# BstrucT C# 2 May 12th, 2008 8:29 AM
Drag n' Drop tayspen C# 2 Oct 22nd, 2005 2:46 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:53 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC