Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

TRichEdit, get vertical scroll bar position...

Posted on 2004-10-15
16
Medium Priority
?
1,554 Views
Last Modified: 2010-04-05
Hello All,

I need to get a current possition of vertical scroll bar in the TRichEdit...
I need to get a current line if it possible...

But this TRichEdit is not focused element. It means that you can not place cursor there and get line number.

Thanks,
Dan
0
Comment
Question by:DanDaemon
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
  • 2
  • +1
16 Comments
 
LVL 17

Expert Comment

by:geobul
ID: 12318586
Hi,

>I need to get a current line if it possible...

Label2.Caption := IntToStr(RichEdit1.CaretPos.Y);

Regards, Geo
0
 
LVL 17

Expert Comment

by:geobul
ID: 12318722
And about the scrollbar:

Label3.Caption := IntToStr(GetScrollPos(RichEdit1.Handle, SB_VERT));

Regards, Geo
0
 
LVL 23

Accepted Solution

by:
Ferruccio Accalai earned 1500 total points
ID: 12319123
try this:

procedure TForm1.Button1Click(Sender: TObject);
var
ScrolPos, FirstVisibleLine: Integer;
ScrollInfo1: TScrollInfo;
begin
FirstVisibleLine := RichEdit1.Perform(EM_GETFIRSTVISIBLELINE,0,0);
ScrollInfo1.cbSize := SizeOf(TScrollInfo);
ScrollInfo1.fMask := SIF_RANGE;
GetScrollInfo(RichEdit1.Handle,SB_VERT, ScrollInfo1);
ScrolPos := GetScrollPos(RichEdit1.Handle, SB_VERT);
ShowMessage('ScrolPos is '+IntToStr(ScrolPos)+'  First Visible Line is '+IntToStr( FirstVisibleLine)+' Scroll max is '+IntToStr(ScrollInfo1.nMax));
end;

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:DanDaemon
ID: 12320209
I need to get current line when mouse cursor held scroll bar and user moving scoll box to up or down.
0
 
LVL 17

Expert Comment

by:geobul
ID: 12320409
The current line is where the cursor is (not the mouse pointer). Thus, in your case the current line might not be visible.

If your RichEdit can show 10 lines at the same time which one should be considered 'current'? If it is the first line on the top then F68 gave you the answer:
FirstVisibleLine := RichEdit1.Perform(EM_GETFIRSTVISIBLELINE,0,0);
0
 

Author Comment

by:DanDaemon
ID: 12320504
Hey geobul, I do not need to get first line!

Ok, explain again...

Step-By-step:
1. User start software;
2. User sees rich edit with text;
3. Text is huge, about 100000+ lines;
4. He can not see all text;
5. He hand scroll bar by mouse pointer and moves on NN lines up or down...
6. I NEED TO KNOW WHERE HE IS NOW... Better if this is line number...
7. This line number I can get from scroll bar position but scroll bar position in points;
8. TAKS: I need to know which line is visible now and moves automaticaly on this line
    if text will be changed but another user.

I hope now you understand what I need
0
 

Author Comment

by:DanDaemon
ID: 12320529
You can see a veeeery good example... Open ICQ message window and move cursor in the top window where is the messages history... when you will get message from another member you still will see here text where you are. but if you move scroll bar down and will receive new message, history text will be moved.
0
 
LVL 17

Expert Comment

by:geobul
ID: 12320561
That's exactly what I'm trying to explan: your user is nowhere. There are several lines currently visible and you can get the number of the first of them. I hope it becomes more clear now.
0
 

Author Comment

by:DanDaemon
ID: 12320625
Ok, WinXP+SP2, Delphi 7+both service packs...

This code:
---
FirstVisibleLine := RichEdit1.Perform(EM_GETFIRSTVISIBLELINE,0,0);
---
Always returns me 0...
0
 

Author Comment

by:DanDaemon
ID: 12320665
I think better way if I explain it as:

I need function Add which will make same than standard Add but will not move cursor to end of text if user is not there.
0
 
LVL 17

Expert Comment

by:geobul
ID: 12320980
OK. A simple example. Drop one Richedit, one Timer, one Label and one Button on a form and apply the following code. RichEdit behaves itself exactly as you've described:

type
  TForm1 = class(TForm)
    RichEdit1: TRichEdit;
    Timer1: TTimer;
    Label1: TLabel;
    Button1: TButton;
    procedure Timer1Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Counter: integer = 0;

implementation

{$R *.DFM}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  RichEdit1.Lines.Add(IntToStr(Counter));
  Inc(Counter);
  Label1.Caption := IntToStr(RichEdit1.Perform(EM_GETFIRSTVISIBLELINE,0,0));
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  RichEdit1.TabStop := false;
end;

end.

Regards, Geo
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 12326505
If you set the HideSelection property of the RichEdit to False, then the Richedit will automatically scroll to newly added text...

Regards
Pierre
0
 
LVL 14

Expert Comment

by:Pierre Cornelius
ID: 12326509
Sorry, Just noticed you said: "...will NOT move cursor to end of text if user is not there."

Do something like this:

var SavePos: integer;
begin
  SavePos:= Richedit1.SelStart;
  Richedit1.Lines.Add('SomeText');
  RichEdit.SelStart:= SavePos;
end;
0
 
LVL 17

Expert Comment

by:geobul
ID: 12679815
IMHO Ferruccio68 and I answered all the questions here. Please correct me if I'm wrong.
0
 

Author Comment

by:DanDaemon
ID: 12679867
Uh, sorry Ferruccio68... I was waiting additional answers, and forgot about your answer.
Yes, I have changed your code fully, but idea was correct!

Thanks,
Dan
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question