View previous topic :: View next topic |
Author |
Message |
jfcarbel
Joined: 13 Jun 2006 Posts: 27
|
Posted: Thu Jun 15, 2006 6:15 am Post subject: Highlight Line |
|
|
Posted by: Guest (IP Logged)
Date: April 11, 2006 03:46AM
Could you show me how to highlight a specific line with a certain color? I tried the HighlightLine event but i still couldn't get one line to highlight correctly. |
|
Back to top |
|
|
jfcarbel
Joined: 13 Jun 2006 Posts: 27
|
Posted: Thu Jun 15, 2006 6:16 am Post subject: |
|
|
Posted by: econtrol (IP Logged)
Date: April 12, 2006 01:31PM
Example:
Code: | procedure TForm3.SyntaxMemo1LineHighLight(Sender: TObject; Line: Integer;
var Selected: Boolean; var bgColor, frColor: TColor);
begin
if Line = 2 then
begin
bgColor := clBlue;
frColor := clGray;
end;
end; |
Michael. |
|
Back to top |
|
|
jfcarbel
Joined: 13 Jun 2006 Posts: 27
|
Posted: Thu Jun 15, 2006 6:17 am Post subject: |
|
|
I am a bit confused by the code example you have given.
the person asked how to highlight a specfic line, your example only shows highlighting if the line=2. Why are you hardcoding this as 2?
What I would have expected to see is some procedure that would accept a LineNumber and then highlight that LineNumber passed in.
Could you please explain this example or provide another, Thanks. |
|
Back to top |
|
|
jfcarbel
Joined: 13 Jun 2006 Posts: 27
|
Posted: Thu Jun 15, 2006 6:18 am Post subject: |
|
|
Posted by: aarondc (IP Logged)
Date: May 19, 2006 02:36PM
Code: | LineHighLight(Sender: TObject; Line: Integer; var Selected: Boolean; var bgColor, frColor: TColor); |
is an event of the TSyntaxMemo. Like Windows, Delphi and its components, is event-driven, not procedural. The example shows you how to highlight a line using the appropriate event.
Once you get your head around event-driven architecture, the example provided is more than adequate.
Instead of passing a Linenumber into a procedure, keep track of any line(s) you want highlighted, and process them as shown in the event. |
|
Back to top |
|
|
jfcarbel
Joined: 13 Jun 2006 Posts: 27
|
Posted: Thu Jun 15, 2006 6:18 am Post subject: |
|
|
Okay, I think I understand. This gives one the flexibility to have more than one line highlighted at a time and each can be in whatever colors are set in the event.
So in my case I could just create an instance variable that is a collection of line numbers to highlight and then in the event, just iterate thru the collection setting the Selected, bgColor, frColor for each.
So I understand that.
But what I was really thinking of doing is being able to specify a line number and have the syntax memo scroll down to that line and highlight it. It seems like the above OnLineHighLight event is only part of the solution as I need to scroll to a specified line as well.
Maybe I can use the ExecCommand called smSelGotoXY, but not exactly sure how I would pass in the X,Y coordinates to ExecCommand. |
|
Back to top |
|
|
jfcarbel
Joined: 13 Jun 2006 Posts: 27
|
Posted: Thu Jun 15, 2006 6:19 am Post subject: |
|
|
Posted by: econtrol (IP Logged)
Date: May 31, 2006 11:54AM
To scroll to the specified position (x, y) you should only change CaretPos property:
Code: | SyntaxMemo1.CaretPos := Point(x, y); |
Changing caret position automatically scrolls editor to make caret visible.
Michael. |
|
Back to top |
|
|
|