Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 12-22-2008, 05:42 AM
dad45 dad45 is offline
Junior Member
 
Join Date: Jul 2008
Posts: 9
Default Move rows in Tmemo w/mouse?

Need to move rows around in a Memo component. Any hints?

Thank you,

Vern
Reply With Quote
  #2  
Old 12-22-2008, 09:09 AM
tomu tomu is offline
Senior Member
 
Join Date: May 2002
Posts: 186
Default RE: Move rows in Tmemo w/mouse?

To find out what line a user clicks on you can do something like this:

procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
iLine : integer;
begin
iLine := Memo1.Perform(EM_LINEFROMCHAR, Memo1.SelStart, 0);
caption := format('%d',[iLine]);
end;

To switch two lines, something like this:

procedure TForm1.Button1Click(Sender: TObject);
var
l1, l2 : string;
begin
l1 := memo1.Lines[0];
l2 := memo1.Lines[4];

memo1.Lines[0] := l2;
memo1.Lines[4] := l1;
end;

Hope it helps...
Reply With Quote
  #3  
Old 12-22-2008, 05:45 PM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: Move rows in Tmemo w/mouse?

[pre]
This is adapted from: http://licomputing.com/cgi-bin/webpo.../kbitem?id=111

Requires a TApplicationEvents component (Additional tab).

Should be fine for a simple application, otherwise making it a component
would be better. A cursor adapted from the default Drag cursor with
a caret at the tip would probably help.

[/pre][DELPHI]
var
FSelStart,
FSelLength : integer;

procedure TForm1.ApplicationEvents1Message(var Msg: tagMSG;
var Handled: Boolean);
var
i : integer;
pt : TPoint;
begin
if (Msg.message = WM_LBUTTONDOWN) and
(WindowFromPoint(mouse.CursorPos) = Memo1.Handle) and
(Memo1.SelLength > 0) then
begin
pt := Memo1.ScreenToClient(mouse.CursorPos);
i := LoWord(Memo1.Perform(EM_CHARFROMPOS, 0, MakeLParam(pt.X, pt.Y)));
FSelStart := Memo1.SelStart;
FSelLength := Memo1.SelLength;
if (i >= FSelStart) and (i <= FSelStart +FSelLength -1) then begin
Memo1.BeginDrag(True);
Handled := true;
end;
end;
end;
end;

procedure TForm1.Memo1DragOver(Sender, Source: TObject; X, Y: Integer;
State: TDragState; var Accept: Boolean);
begin
Accept := Sender = Source;
end;

procedure TForm1.Memo1DragDrop(Sender, Source: TObject; X, Y: Integer);
var
i : integer;
s : string;
begin
i := LoWord(Memo1.Perform(EM_CHARFROMPOS, 0, MakeLParam(X, Y)));

if (i >= FSelStart) and (i <= FSelStart +FSelLength-1) then
exit;

s := Memo1.SelText;

if i > FSelStart +FSelLength -1 then
Dec(i, FSelLength);

Memo1.SelText := '';
Memo1.SelStart := i;
Memo1.SelText := s;

//re-select
Memo1.SelStart := i;
Memo1.SelLength := FSelLength;
end;

[/DELPHI][pre]
Merry Xmas
[/pre]

Chris
Reply With Quote
  #4  
Old 12-24-2008, 06:27 AM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: Move rows in Tmemo w/mouse?

You might want to use a TRichEdit as it already does this.

Chris
Reply With Quote
  #5  
Old 12-25-2008, 07:58 AM
dad45 dad45 is offline
Junior Member
 
Join Date: Jul 2008
Posts: 9
Default RE: Move rows in Tmemo w/mouse?

I do NOT see how the TRichEdit component can be configured to do what I stated was needed. Please excuse my lack of D6 skills.

Vern
Reply With Quote
  #6  
Old 12-25-2008, 10:05 AM
chris_w chris_w is offline
Senior Member
 
Join Date: Jan 2004
Posts: 1,397
Default RE: Move rows in Tmemo w/mouse?

Using D7 w/ XP Pro, the TRichEdit supports dragging and dropping of selected text auto magically.

Chris
Reply With Quote
  #7  
Old 12-27-2008, 07:57 PM
dad45 dad45 is offline
Junior Member
 
Join Date: Jul 2008
Posts: 9
Default RE: Move rows in Tmemo w/mouse?

I am using D6. I will do it the hard way.

Thanks much,

Vern
Reply With Quote
Reply

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 On

Forum Jump


All times are GMT. The time now is 07:28 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.