Recent

Author Topic: TEdit and TMemo?  (Read 4626 times)

kogs

  • New Member
  • *
  • Posts: 42
TEdit and TMemo?
« on: August 27, 2015, 10:26:26 am »
Mac OS X 10.10.4 (14E46) - Mac mini (Mid 2011)

TEdit - yes -> tedit0.png and tedit1.png
TMemo - no -> tmemo0.png

TEdit/TMemo -> TEdit - dmManual - yes, TMemo - dmAutomatic - yes (dmManual - yes)

 :(

kogs
(Aphasia - http://en.wikipedia.org/wiki/Aphasia)
Mac OS X 10.9.1

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: TEdit and TMemo?
« Reply #1 on: August 27, 2015, 02:59:51 pm »
hmm... dragMode should be used when "something" needs to be dragged-out of the control. Not within the control.

Thus dragging text within the Memo itself, should work (at least with dmAutomatic)

kogs: Is the problem with dragging text within TMemo (from one place to another)?

kogs

  • New Member
  • *
  • Posts: 42
Re: TEdit and TMemo?
« Reply #2 on: August 27, 2015, 03:12:27 pm »
TMemo - "qwert uiop" -> "t uiopqwer" -> no

kogs
(Aphasia - http://en.wikipedia.org/wiki/Aphasia)
Mac OS X 10.9.1

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2770
    • havefunsoft.com
Re: TEdit and TMemo?
« Reply #3 on: August 27, 2015, 03:15:18 pm »
ok. so it is about dragging text.

kogs

  • New Member
  • *
  • Posts: 42
Re: TEdit and TMemo?
« Reply #4 on: August 28, 2015, 10:09:54 am »
TEdit - yes -> tedit0.png and tedit1.png

TMemo - no -> tmemo0.png  >:D

:)

kogs
(Aphasia - http://en.wikipedia.org/wiki/Aphasia)
Mac OS X 10.9.1

Michl

  • Full Member
  • ***
  • Posts: 226
Re: TEdit and TMemo?
« Reply #5 on: August 28, 2015, 02:29:15 pm »
On Windows you can do (on Mac I don't know):
Quote
procedure TForm1.ControlDragDrop(Sender, Source: TObject; X, Y: Integer);
var
  RemoveOriginal: Boolean;
  DragText: String;
  NewText: String;
  InsertPos: Integer;
  OrigStart: Integer;

  procedure InsertText;
  begin
    UTF8Insert(DragText, NewText, InsertPos);
    if not RemoveOriginal then Exit;
    if InsertPos < OrigStart then OrigStart := OrigStart + UTF8Length(DragText);
    UTF8Delete(NewText, OrigStart, UTF8Length(DragText));
  end;

begin
  if not Assigned(Source) then Exit;
  if not ((Source is TMemo) or (Source is TEdit)) then Exit;
  if not Assigned(Sender) then Exit;
  if not ((Sender is TMemo) or (Sender is TEdit)) then Exit;

  if Sender = Source then
    RemoveOriginal := true
  else
    RemoveOriginal := false;

  if Source is TEdit then begin
    DragText := TEdit(Source).SelText;
    OrigStart := TEdit(Source).SelStart + 1;
  end else begin
    DragText := TMemo(Source).SelText;
    OrigStart := TMemo(Source).SelStart + 1;
  end;

  if Sender is TEdit then
    InsertPos := MouseToPosition(TEdit(Sender), Point(X, Y)) + 1
  else
    InsertPos := MouseToPosition(TMemo(Sender), Point(X, Y)) + 1;

  if RemoveOriginal and (Insertpos >= OrigStart) and (InsertPos <= OrigStart + Length(DragText)) then Exit;  //Same Position

  if Sender is TEdit then begin
    NewText := TEdit(Sender).Text;
    InsertText;
    TEdit(Sender).Text := NewText;
  end else begin
    NewText := TMemo(Sender).Text;
    InsertText;
    TMemo(Sender).Text := NewText;
  end;
end;

function TForm1.MouseToPosition(Sender: TWinControl;
  P: TPoint): Integer;
begin
  Result := 0;
  if not Assigned(Sender) then Exit;
  Result := LoWord(SendMessage(Sender.Handle, EM_CHARFROMPOS, 0, MakeLong(P.x, P.y)));
end;
Project added (you can select a text with the left mouse button, drag&drop with the right mouse button).
Code: [Select]
type
  TLiveSelection = (lsMoney, lsChilds, lsTime);
  TLive = Array[0..1] of TLiveSelection;

 

TinyPortal © 2005-2018