How do I drag and drop text using Delphi 2006?

I am trying to learn how to do drag and drop with Delphi 2006. I have come across examples on how to do this with objects, but I'm interested in only dragging and dropping text.

I would like to be able to accomplish the following:

  *  Select text in one DBEdit box and drag (move or copy using control and shift keys) to another DBEdit box
  *  Select text from a webpage and drag it into a DBEdit box

I understand that these two operations are pretty different (the second needs to be done with COM). Can anyone help me with this by pointing me to an online article or component? I have read the online help, but so far what I've found deals with DnDing objects and not text.

Thanks in advance for any help you can offer.

Terry
1
Terry
8/13/2009 7:47:50 PM
embarcadero.delphi.vcl.using 2297 articles. 2 followers. Follow

6 Replies
850 Views

Similar Articles

[PageSpeed] 13

<Terry Carnes> wrote in message news:149267@forums.codegear.com...

> I would like to be able to accomplish the following:
>
>  *  Select text in one DBEdit box and drag (move or copy using control and 
> shift keys) to another DBEdit box

Look at the various Drag events that most controls have, such as OnDragOver 
and OnDragDrop.  In the OnStartDrag event of the source TDBEdit, you can 
instantiate a custom-written TDragObject descendant that holds whatever 
information you need (the actual text, and DB record ID, whatever), and then 
the OnDragDrop event of the destination TDBEdit can extract that information 
and use it as needed.

>  *  Select text from a webpage and drag it into a DBEdit box

You have to write a new class that implements the IDropTarget interface, and 
then register the class using the Win32 API RegisterDragDrop() function. 
Inside your IDropTarget.Drop() implementation, you can then use the provided 
IDataObject interface to access whatever data the browser decides to share 
with you.

-- 
Remy Lebeau (TeamB)
0
Remy
8/13/2009 10:50:57 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}

I'm finding this a bit harder than I expected.

When I select text in a TDBEdit control, and then point to the selected text and click, the selection goes away instead of beginning the Drag Event.

This is my code:

procedure TForm2.DBEdit6MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if (Sender is TDBEdit) and ((Sender as TDBEdit).SelLength > 0) then
    begin
    (Sender as TDBEdit).BeginDrag(True);
    end;
end;

What am I doing wrong?
0
Terry
8/17/2009 6:15:54 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> Look at the various Drag events that most controls have, such as OnDragOver 
> and OnDragDrop.  In the OnStartDrag event of the source TDBEdit, you can 
> instantiate a custom-written TDragObject descendant that holds whatever 
> information you need (the actual text, and DB record ID, whatever), and then 
> the OnDragDrop event of the destination TDBEdit can extract that information 
> and use it as needed.

I am sorry, but I'm having a hard time finding examples of how to properly use a TDragObject. I want the object to hold the value of the selected text. But how do I do this?
0
Terry
8/17/2009 6:24:15 PM
<Terry Carnes> wrote in message news:150739@forums.codegear.com...

> When I select text in a TDBEdit control, and then point to the selected
> text and click, the selection goes away instead of beginning the Drag 
> Event.

As it should be.  That is how text selection works in general.

> This is my code:

The OnMouseDown event is not a good place to call BeginDrag() from.  That 
would prevent the user from clicking on the DBEdit to enter new text, or to 
change the current selection.  Use the OnMouseMove event instead.  Even 
then, do not call BeginDrag() until the mouse has been held down and moved a 
few pixels first.  Use OnMouseDown to keep track of the coordinates where 
the mouse is held down initially, use the OnMouseUp event to clear the 
coordinates, and then compare the coordinates in the OnMouseMove event and 
only begin the drag process when actually needed.  In your situation, I 
would suggest not initiating a drag until the user holds down the mouse and 
drags near one of the boundaries of the DBEdit

-- 
Remy Lebeau (TeamB)
0
Remy
8/17/2009 10:49:59 PM
<Terry Carnes> wrote in message news:150745@forums.codegear.com...

> I am sorry, but I'm having a hard time finding examples of how to properly
> use a TDragObject. I want the object to hold the value of the selected 
> text.
> But how do I do this?

As I mentioned earlier, you would need to derive a new class for that, ie:

{code:delphi}
type
  TMyDBEditDragObjectEx = class(TDragObjectEx)
  private
    FDraggedText: String;
  public
    constructor Create(const ADraggedText: String); reintroduce;
    property DraggedText: String read FDraggedText;
  end;

constructor TMyDBEditDragObjectEx.Create(const ADraggedText: String);
begin
  inherited Create;
  FDraggedText := ADraggedText;
end;

procedure TForm1::DBEdit1StartDrag(Sender: TObject; var DragObject: 
TDragObject);
begin
  DragObject := TMyDBEditDragObjectEx.Create((Sender as TDBEdit).SelText);
end;

procedure TForm1.DBEdit2DragOver(Sender: TObject; Source: TObject; X, Y: 
Integer; State: TDragState; var Accept: Boolean);
begin
  Acces := IsDragObject(Source) and (Source is TMyDBEditDragObjectEx);
end;

procedure TForm1.DBEdit2DragDrop(Sender: TObject; Source: TObject; X, Y: 
Integer);
begin
  (Sender as TDBEdit).SelText := TMyDBEditDragObjectEx(Source).DraggedText;
end;
{code}

Alternatively:

{code:delphi}
type
  TMyDBEditDragObjectEx = class(TDragObjectEx)
  private
    FDraggedEdit: TDBEdit;
  public
    constructor Create(ADraggedEdit: TDBEdit); reintroduce;
    property DraggedEdit: TDBEdit read FDraggedEdit;
  end;

constructor TMyDBEditDragObjectEx.Create(ADraggedEdit: TDBEdit);
begin
  inherited Create;
  FDraggedEdit := ADraggedEdit;
end;

procedure TForm1::DBEdit1StartDrag(Sender: TObject; var DragObject: 
TDragObject);
begin
  DragObject := TMyDBEditDragObjectEx.Create(Sender as TDBEdit);
end;


procedure TForm1.DBEdit2DragOver(Sender: TObject; Source: TObject; X, Y: 
Integer; State: TDragState; var Accept: Boolean);
begin
  Acces := IsDragObject(Source) and (Source is TMyDBEditDragObjectEx);
end;

procedure TForm1.DBEdit2DragDrop(Sender: TObject; Source: TObject; X, Y: 
Integer);
begin
  (Sender as TDBEdit).SelText := 
TMyDBEditDragObjectEx(Source).DraggedEdit.SelText;
end;
{code}

-- 
Remy Lebeau (TeamB)
0
Remy
8/17/2009 11:10:49 PM
> {quote:title=Remy Lebeau (TeamB) wrote:}{quote}
> <Terry Carnes> wrote in message news:150739@forums.codegear.com...
> 
> > When I select text in a TDBEdit control, and then point to the selected
> > text and click, the selection goes away instead of beginning the Drag 
> > Event.
> 
> As it should be.  That is how text selection works in general.

Thanks, Remy, for your continued help.

This is what I observe elsewhere:

TRichEdit control: When I select text and then point the mouse cursor at the selected text, the cursor changes from the I-beam to the mouse pointer. When I press and hold down the left mouse button, nothing happens (cursor still mouse pointer). When I drag a few pixels the cursor changes, to crNoDrop if I am still within the selected text, to crDrag if I have dragged outside of the selected text.

Microsoft Word: When I select text and then point the mouse cursor at the selected text, the cursor changes from the I-beam to the mouse pointer. When I press and hold down the left mouse button, after a second or more the cursor changes to dragging (even if I haven't moved. Same thing happens if I move a few pixels, changes right to dragging even if I am still within the selected text.

I would like to be able to duplicate the same user experience as in Microsoft Word. Although showing the crNoDrop while still over the selected text is technically correct, it seems to be more confusing than helpful. I would like the cursor to change after the time needed to differentiate between a mouse down and a mouse click (if that makes sense).
0
Terry
8/17/2009 11:32:49 PM
Reply:

Similar Artilces:

To use or not to use Delphi
Sadly, it seems to me that there is a sort of race between the two threads, for and against using Delphi in new projects, with more or less the same users posting in both threads. Arguments are fiercely debated in both camps. Borland had their own vision. As a community, now that Delphi has changed ownership I believe we should try to be more consistent, more clear, and more articulate in what we expect from Embercadero in terms of Delphi. We can contribute to keeping Delphi alive and moving in the right direction. "Laurent Cocea" schrieb: > Sadly, it seems to me that there ...

Using Delphi 7 and Delphi 2010
I had a project in Delphi 7. I worked on it in Delphi 2010. When I try to open the .dpr again in Delphi 7, the IDE toolbar widens across both monitors, and Delphi 7 locks up. It appears that Delphi 2010 modifies the .dpr in a way that makes Delphi 7 unable to open it again. All my forms & units appear to open fine in D7 after D2010, except for the warnings on the ExplicitHeight and ExplicitWidth properties being missing... I can easily recreate the .dpr, but is this expected behavior? Thanks. Tom Field wrote: > I had a project in Delphi 7. > > I worked o...

How design a COM using Delphi and Using in PB7?
I need some component, So, we want using DELPHI5 to develop a COM or Activex. What type of knowege or Skill I must know it. Can anyone tell us? from DRAOGN Can you explain what type of component you want to create? You may not need to a) build your own, or b) use Delphi. If the component should be used from within a PB application, you ought to use PB to develop it unless it is something that PB does not let you do. regards, Bill DRAGON wrote: > I need some component, So, we want using DELPHI5 to develop a COM or > Activex. > What type of knowege or Skill I ...

delphi Win32 using delphi .NET dll
Hi, I'm trying to use a delphi.NET dll in delphi.WIN32. I am currently using CodeGear Delphi 2007 with version2(base version) of .NET I can get the dll to import into the WIN32 application the only problem is when i include things such as: "using Classes,DateUtils, SysUtils" in the .NET dll the win32 application will instantly hang when any of the dll functions are called. Any help would be great thanks. Also I have tried this example and it also crashes for me? http://cc.embarcadero.com/Item/22688 -Braden I also found this.. "The problem is that, wehn you instal...

can i use delphi 2007 bpls in delphi 2009
can i use delphi 2007 bpls in delphi 2009 ? "Gaetan SIRY" skrev i meddelelsen news:8703@forums.codegear.com... > can i use delphi 2007 bpls in delphi 2009 ? No. -- Finn Tolderlund The compatiblity between D2006 and D2007 was unique. Normaly they can't be compatible because new version enhance/change the API. And D2009 defines String = Unicode where older version has String = Ansistring so D200x/Dx-BPL are 200% incompatible with D2009. ...

How to use a delphi XE3 obj file in delphi 2007?
Hi, I'm migrating an application from delphi 2007 to delphi XE3 and I would like to do it in several steps. To do this I need to use a part of my new code (XE3) in the current delphi 2007 application. So I want to use the .obj file from my XE3 file. I know I have to use the {$L 'Filename'} and I know that I have to declare the functions that I want to use in external in my D2007 project. I wanted to make an easy and simple example to see how it works with only 1 function 'hello world' compiled in obj with XE3 but I can't find the way to use it in D2007. In D200...

Text.Write speed
Hi ! I have speed troubles for using Text.Write method in Delphi 2006, particularly with distant files (local network). For example, with the following code ("F" is a text file ; "Line" is an about 200-character string): ----- AssignFile(F, FileName); try Rewrite(F); for l := 1 to 100 do begin for c := 1 to Length(Line) do Write(F, Line[c]); Writeln(F); end; finally CloseFile(F); end; ----- On a distant file: Delphi 5 -> 0.08 seconds Delphi 2006 -> close to 8 seconds Is there a speci...

How to use AppModeler to generate Delphi forms using Cached Updates
<HTML> <TT>A beginner's question regarding AppModeler 6.1, Delphi 3, and Interbase 5.x...</TT> <P><TT>While I am impressed with the amount of thought and work that has gone into AppModeler, I have nonetheless been surprised to discover that the Delphi application generated by AppModeler is not suitable for real-world situations because of the "fly-away" problem afflicting newly-entered records.</TT> <P><TT>When I enter a record on an AppModeler-generated Delphi form, the record disappears ("flies away") immedia...

How to use a .dmp file for a system which crashes using a delphi app
Hi, I put this post here because I am not sure of the best location. I have been given a memory dump (.dmp) file by a client who thinks that a Delphi 7 application is causing their system to blue screen from time to time. Does anyone know how I can use this .dmp file to locate the problem in the delphi app? The build the client is using has debug symbols turned on. I have downloaded Microsoft Debugging Tools for windows and have dupmchk.exe (and kd.exe) but I would really appreciate some help with how these or any other useful tools should be used? Many thanks Ben > I have down...

When to use ( and when to use ((?
I'm just not getting it. When do you use ( in a statement, when do you need to use ((, and is the space after either or both mandatory? For example, I coded this statement: if (( $_ eq $bad_guys_ip )) { more_stuff_here }; Why the two (( in an if? And why does it seem to not work when I miss the space after the ((? Thanx! Mark me as... /Corn-fused|Dense/ > I'm just not getting it. >=20 > When do you use ( in a statement, when do you need to use ((, and is > the space after either or both mandatory? >=20 > For example, I coded this sta...

If you use Delphi...
If you use Delphi for .NET with ASA, please vote for this: http://qc.borland.com/wc/qcmain.aspx?d=31677 ...

MOVED: Use Delphi XE TLB importer in Delphi 2007?
....to the ActiveX group: https://forums.embarcadero.com/thread.jspa?threadID=47170 -- Craig Stuntz · Vertex Systems Corp. · Columbus, OH Delphi/InterBase Weblog : http://blogs.teamb.com/craigstuntz/ ...

Using Using
I have just completed reading a chapter in my book on performance. The books says to speed up performance on your web site you should use the using statement when opening connections. My question is how do you catch errors if you are using this as apposed to a try catch block.thanksBryan  Why would you use it as an alternative to a try/catch statement. Couldn't you just do something like  public void UsingSomeMethod() { try { SomeMethod(); } catch(SomeException e) { /// do something useful }}public void SomeMethod() { using (Something) { ...

SMART Clients using delphi 2006
"SMART Clients" is the future of enterprise software... It is based on Three tier architecture using Web Services... With codegear is so easy develop this kind of software using TSOAPDataModule, TSoapConnection, etc... How much developers are building "SMART Clients" with Delphi 2006 or 2007? Hi! > {quote:title=Juan Carlos Porras Boada wrote:}{quote} > "SMART Clients" is the future of enterprise software... For most of my clients this future is past... > It is based on Three tier architecture using Web Services... > With codegear is...

Web resources about - How do I drag and drop text using Delphi 2006? - embarcadero.delphi.vcl.using

Delphi - Wikipedia, the free encyclopedia
... an archaeological site and a modern town in Greece on the south-western spur of Mount Parnassus in the valley of Phocis . The site of Delphi ...

Delphi Automotive (@DelphiAuto) on Twitter
Log in Sign up You are on Twitter Mobile because you are using an old version of Internet Explorer. Learn more here Delphi Automotive @ DelphiAuto ...

Delphi Connect for Verizon on the App Store on iTunes
Get Delphi Connect for Verizon on the App Store. See screenshots and ratings, and read customer reviews.


Audi working with Delphi to develop autonomous car tech
Audi is developing an iPad-sized device that will pack all the necessary computing power for a self-driving car

US approves China company's acquisition of Delphi biz
The Committee on Foreign Investment in the United States has formally approved the acquisition of Delphi's global production of braking systems ...

Verizon And Delphi Officially Launch Vehicle Diagnostics Service - $250 For The Module, $5 A Month On ...
If you're a car nut, a paranoid parent, or a small business owner looking to do a little, uh, company vehicle economy analysis, Verizon's teamed ...

Watch out Google: Delphi gives Ars a ride in its self-driving car
The automotive components maker gave Ars a preview ride around the neighborhood. MOUNTAIN VIEW, CA—On Thursday morning I met with Delphi at its ...

The skinny on Delphi's autonomous road trip across the United States
Filed under: Green , Videos , Autonomous Last week, Delphi's autonomous car became the first to complete a coast-to-coast trip across the United ...

Delphi partners with WiTricity on automated wireless charging system
One could easily argue that parking between the white lines at any local hangout presents a challenge for some inexperienced drivers. So, why ...

Resources last updated: 12/28/2015 11:09:29 AM