* * *

Author Topic: Getting the first VISIBLE line-index of a Memo  (Read 1127 times)

justnewbie

  • Full Member
  • ***
  • Posts: 129
Getting the first VISIBLE line-index of a Memo
« on: April 11, 2018, 06:47:55 pm »
Hi,
Is it possible to get the index of the topmost VISIBLE line of a TMemo component?
If yes, how?

howardpc

  • Hero Member
  • *****
  • Posts: 2778

justnewbie

  • Full Member
  • ***
  • Posts: 129
Re: Getting the first VISIBLE line-index of a Memo
« Reply #2 on: April 11, 2018, 07:40:42 pm »
Thank you! Linux version would be also great.  :)

justnewbie

  • Full Member
  • ***
  • Posts: 129
Re: Getting the first VISIBLE line-index of a Memo
« Reply #3 on: April 17, 2018, 01:30:09 pm »
How can I go through a Memo's text character by character?
In other words: I want to get every single string-character from 0 position to the end of the text.
« Last Edit: April 17, 2018, 01:31:52 pm by justnewbie »

Handoko

  • Hero Member
  • *****
  • Posts: 2598
  • My goal: build my own game engine using Lazarus
Re: Getting the first VISIBLE line-index of a Memo
« Reply #4 on: April 17, 2018, 02:13:42 pm »
How can I go through a Memo's text character by character?

This works for me:

Code: Pascal  [Select]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, StdCtrls;
  9.  
  10. type
  11.  
  12.   { TForm1 }
  13.  
  14.   TForm1 = class(TForm)
  15.     Edit1: TEdit;
  16.     Label1: TLabel;
  17.     Label2: TLabel;
  18.     Memo1: TMemo;
  19.     procedure Edit1Change(Sender: TObject);
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. { TForm1 }
  30.  
  31. procedure TForm1.Edit1Change(Sender: TObject);
  32. var
  33.   Index: Integer;
  34. begin
  35.   TryStrToInt(Edit1.Text, Index);
  36.   Label2.Caption := '';
  37.   if (Index <= 0) or (Index > Memo1.Lines.Text.Length) then Exit;
  38.   Label2.Caption := 'Char #' + Index.ToString + ' is ' + Memo1.Text[Index];
  39. end;
  40.  
  41. end.

justnewbie

  • Full Member
  • ***
  • Posts: 129
Re: Getting the first VISIBLE line-index of a Memo
« Reply #5 on: April 17, 2018, 02:54:58 pm »
@Handoko: thank you!

jamie

  • Hero Member
  • *****
  • Posts: 835
Re: Getting the first VISIBLE line-index of a Memo
« Reply #6 on: April 18, 2018, 01:43:05 am »
I would of thought the Windows solution would work since using Messages is a norm for talking to
common controls?

 Since these widgets support the common controls don't they also support the messages that go with them?


 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus