Recent

Author Topic: Memo1 Inquiry  (Read 2877 times)

JLWest

  • Hero Member
  • *****
  • Posts: 877
Memo1 Inquiry
« on: December 25, 2018, 10:43:28 pm »
I have a form with a Memo1. I load a text file into the memo1 box. After loading the Memo1 is at the bottom of a hundred lines of code. I want to be at the first line.

Can't seem to find the command or method to accomplish this.
 
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 3074
Re: Memo1 Inquiry
« Reply #1 on: December 25, 2018, 11:27:04 pm »
Try Memo1.SelStart := 0 or Memo1.CaretPos := Point(0,0);

If the memo doesnt update itself, try setting:
  Memo1.VertScrollBar.Position := 0;
  Memo1.HorzScrollBar.Position := 0;
« Last Edit: December 25, 2018, 11:30:31 pm by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Bart

  • Hero Member
  • *****
  • Posts: 3939
    • Bart en Mariska's Webstek
Re: Memo1 Inquiry
« Reply #2 on: December 25, 2018, 11:58:19 pm »
Maybe this works: Memo1.Perform(EM_SCROLLCARET, 0, 0)?

Bart

JLWest

  • Hero Member
  • *****
  • Posts: 877
Re: Memo1 Inquiry
« Reply #3 on: December 26, 2018, 12:08:55 am »
umain.pas(148,17) Error: Identifier not found "EM_SCROLLCARET"

What I found is a C routine and needs something added to the use clause. What, I don't know.

None of these appear to work.

I can post the code and maybe one large text file if that will help.

//  Memo1.CaretPos := Point(0,0);
  //Memo1.VertScrollBar.Position := 0;
  //Memo1.HorzScrollBar.Position := 0;
  //Memo1.Perform(EM_SCROLLCARET, 0, 0);
  Memo1.SelStart := 0;               
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 877
Re: Memo1 Inquiry
« Reply #4 on: December 26, 2018, 12:34:50 am »
here is the code and a file 'm trying to work with.

Could somebody take a look please.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

jamie

  • Hero Member
  • *****
  • Posts: 3637
Re: Memo1 Inquiry
« Reply #5 on: December 26, 2018, 12:37:36 am »
Tmemo is a EDIT control and thus uses EDIT control messages and functions...

SelStart(0) is the correct step..

 To use the Messages, you need to include the "Windows" Unit or maybe the LCLintF may have them for the
message constants

P.S.

 Seems like I have nothing on board to open that file. oh well.
« Last Edit: December 26, 2018, 12:43:13 am by jamie »
The only true wisdom is knowing you know nothing

JLWest

  • Hero Member
  • *****
  • Posts: 877
Re: Memo1 Inquiry
« Reply #6 on: December 26, 2018, 12:52:36 am »
Added this to my Use clause. "LCLintF"

Got "umain.pas(151,3) Error: Identifier not found "SelStart"

What "Windows" Unit.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

josh

  • Hero Member
  • *****
  • Posts: 789
Re: Memo1 Inquiry
« Reply #7 on: December 26, 2018, 01:04:07 am »
try adding messages to your uses declaration.

is it possible that your code is not in a procedure/function that is part of the form?

ie
procedure xyz;
rather tha procedure form1.xyz;

base uses declaration with addition of messages
uses Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,messages;
Development Installation Lazarus 1.3, FPC 2.7.1,Windows 7/8 32/64, OSX, *nix

Test Environment Lazarus & FPC Trunk on Windows and OSX (Cocoa Mainly on OSX). Testing also Crosscompile windows to OSX.. 
Any posts made from 2015 will be based on Lazarus Trunk.

JLWest

  • Hero Member
  • *****
  • Posts: 877
Re: Memo1 Inquiry
« Reply #8 on: December 26, 2018, 01:26:31 am »
Anything is possible.

I found some code on the ord that used the "EM_SCROLLCARET" and copied the use clause into my app, resolved the differences and it didn't work. Messages was one of the items in the use clause.

I posted my code a few post up. I'm doing something wrong but after 3 hours of this I now can't figure it out.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 3074
Re: Memo1 Inquiry
« Reply #9 on: December 26, 2018, 01:48:20 am »
Ok, passed a little time with your code and managed to make it work simply by adding Application.ProcessMessages after the call to Memo1.SelStart := 0. In fact, it worked with just calling ProcessMessages after the calls to LoadMemo1, but it's best to allow it do everything at once.

May be something related to the memo not being focussed, I suppose.

Besides that, your code is too complex and prone to unexpected bugs: too many paths to do the same thing and many ad-hoc routines which are already (and normally better) supplied in the extended RTL. Which means maintenance nightmare. But you didn't ask for help on that so I'll stop now ;)
« Last Edit: December 26, 2018, 01:51:43 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

JLWest

  • Hero Member
  • *****
  • Posts: 877
Re: Memo1 Inquiry
« Reply #10 on: December 26, 2018, 02:00:16 am »
@Lucamar

I'll try to add that in the same place as you did.

I know the code needs work, it was written over 2 years ago and I have improved a bit, not much but a bit.

Wanted to correct a few thing and rewrite the code adding the ability to add items to Memo1.

FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

JLWest

  • Hero Member
  • *****
  • Posts: 877
Re: Memo1 Inquiry
« Reply #11 on: December 26, 2018, 02:07:22 am »
It didn't work. Can you post what you changed. Please.
FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

lucamar

  • Hero Member
  • *****
  • Posts: 3074
Re: Memo1 Inquiry
« Reply #12 on: December 26, 2018, 03:26:08 am »
I ony changed a couple or three things:

Code: Pascal  [Select][+][-]
  1. procedure TMain.btnLoadClick(Sender: TObject);
  2. Var
  3.   Item : String = '';
  4.   Ext  : String = '';
  5. begin
  6.   if fileslistbox.Count < 1 then begin Exit; end;
  7.   Item := FilesListBox.Items[FilesListBox.ItemIndex];
  8.   {@mod: This is surer}
  9.   if Lowercase(ExtractFileExt(Item)) <> '.txt' then
  10.     Exit;
  11. {@added}Item := FullPath(Item);
  12.   LoadMemo1(Item);
  13. {@added}Application.ProcessMessages;;
  14. //  Memo1.CaretPos := Point(0,0);
  15.   //Memo1.VertScrollBar.Position := 0;
  16.   //Memo1.HorzScrollBar.Position := 0;
  17.   //Memo1.Perform(EM_SCROLLCARET, 0, 0);
  18.   Memo1.SelStart := 0;
  19. end;
  20.  
  21. Procedure TMain.LoadMemo1(FileName : String);
  22. { Discarded everything to do just this: }
  23. Begin
  24.   if FileExists(FileName) Then
  25.   try
  26.     Memo1.Lines.LoadFromFile(FileName);
  27.   except
  28.     on E: EInOutError do {ignore?!};
  29.     else raise;
  30.   end;
  31. end;

ETA: Forgot to add environment ...
Lazarus/FPC 1.8.4/3.0.4 - GTK2 - i386 under Ubuntu 12.04
« Last Edit: December 26, 2018, 03:33:41 am by lucamar »
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Jurassic Pork

  • Hero Member
  • *****
  • Posts: 835
Re: Memo1 Inquiry
« Reply #13 on: December 26, 2018, 03:46:37 am »
hello,
it's OK for me with this code ( for the Dblclick procedure) :
Code: Pascal  [Select][+][-]
  1. procedure TMain.FilesListBoxDblClick(Sender: TObject);
  2. Var
  3.   Item  : String;
  4.   Path  : String;
  5.   FilePresent : Boolean;
  6. begin
  7.  path := 'M:\Test\';
  8.  Item := FilesListBox.Items[FilesListBox.ItemIndex];
  9.  Path := FullPath (Item);
  10.  filepresent := fileexists(path);
  11.  //LoadMemo1(Path);
  12.  Memo1.Lines.LoadFromFile(Path);
  13.  Memo1.SelStart := 0;
  14.  Memo1.SelLength:=0;
  15. end;
I don't use the LoadMemo1 because you can use the Lines.LoadFromFile to load a text file in a memo.

Friendly, J.P
Jurassic computer : Sinclair ZX81 - Zilog Z80A à 3,25 MHz - RAM 1 Ko - ROM 8 Ko

JLWest

  • Hero Member
  • *****
  • Posts: 877
Re: Memo1 Inquiry
« Reply #14 on: December 26, 2018, 07:19:44 am »
Yep @lucmar Works great. Thanks

Now I'll do some rewrite on the code and test Jurassic Pork solution. At the least save for future use.


FPC 3.2.0, Lazarus IDE v2.0.4
 Windows 10 Pro 32-GB
 Intel i7 770K CPU 4.2GHz 32702MB Ram
GeForce GTX 1080 Graphics - 8 Gig
4.1 TB

 

TinyPortal © 2005-2018