Forum > SynEdit

Deprecated function

<< < (2/2)

Kaller:
i see. Well the answer is obvious now I will just keep the cumulative char count myself!  Since the lines come up consecutively.  Then just   
SelectedColor.Background := clYellow;
SelectedColor.Foreground := clBlack;
SelStart  := StartPos;
SelEnd    := EndPos;


Martin_fr:

--- Quote from: Kaller on August 26, 2023, 01:05:48 pm ---i see. Well the answer is obvious now I will just keep the cumulative char count myself!  Since the lines come up consecutively.  Then just   
SelectedColor.Background := clYellow;
SelectedColor.Foreground := clBlack;
SelStart  := StartPos;
SelEnd    := EndPos;

--- End quote ---

StartPos/EndPos are points (x/y) too. So where to you need the Position in the text?

Also, note that SynEdit does NOT keep the original LineEnding. So if your text does have LineEndings that differ from the default for the OS, then  RowColToCharIndex  gives the wrong result.
Of course in your own code you may be able to correct for that.

Still, I don't see where you need the "CharIndex"?
Do you read a 2nd copy of the text from a file?
If so, then maybe go the opposite way, while you read the file, notice and count the LineEndings that you passed (the y pos). Keep the CharIndex of the last LineEnding, so you can get the diff to the current pos (and use that as the x pos).

But anyway, yes keeping counting (cumulative) will solve the speed issue.
Besides, in your case you are running only ONE count for each user input (each step instruction by the user). So that won't get you into to much trouble.
Some people used that in search/replace or similar, running hundreds of calls to RowColToCharIndex for a single user command. And then a 1000 lines of text multiplied by several hundred invocations....

Kaller:
Here's my quick and dirty solution
to  highlighted the text in synedit during the processing loop...
i dumped it all the text into a stringlist and looped it to accumulate a charcounter as I processed the lines. Don't forget to add in the end of line chars. I think there is a property called sLines or something.

SynEditSelectedColor.Background := clYellow;  // just Toggle it back to reset any background color.
synedit.selstart := charcounter + 1;   
synedit.selend =  synedit.selstart  + length(s) + 1;  where s is the stringlist string

works like a charm :)







Martin_fr:

--- Quote from: Kaller on August 27, 2023, 02:21:56 pm ---synedit.selend =  synedit.selstart  + length(s) + 1;  where s is the stringlist string

--- End quote ---

Ahhh, now I get it...

Well, "SelStart" should probably get the same warning. It has the same flaw.
(Don't worry, it is not going to be removed.).

The Method you may need is

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SynEdit.BlockBegin := Point(1, Line);SynEdit.BlockEnd := Point(length(SynEdit.Lines[Line-1])+1, Line); // IIRC SynEdit.Lines is 0-based
But as I said, you can also do:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---SynEdit.OnSpecialLineColors := @Form1.MySynLineColor;/////////procedure TForm1.MySynLineColor(Sender: TObject; Line: integer; var Special: boolean; var FG, BG: TColor);begin  Special  := Line = FMyStoredLineToHighlight;  // if Special then  FG := clNone;  BG := clYellow;end;

Kaller:
OnSpecialLineColors is also marked as deprecated.  Synedit doesn't appear to be that well documented, so I kind of stumble my way through it. For example the Clearall function results in a single line remaining, line 1, with a CR LF entry in windows so the line count is 1, not zero after clearing the page and the char count is 2.  Inserting text can carry line endings with it so I was finding the files growing during save load cycles when no edits were occurring.  Anyways it seems like it is hard to avoid the indexing by character as it might be baked in to everything, but making my own indexer was one idea. Fortunately the text is not so long. I might still do something like dump the synedit text into a string list, and then use the associated object feature of the stringlist to maintain a line counter and a byte counter, at least the compiler might stop nagging me about deprecated functions. LOl.

Navigation

[0] Message Index

[*] Previous page

Go to full version