[lazarus] How to scroll TMemo control in code
Marc Weustink
marc.weustink at cuperus.nl
Tue Apr 8 05:53:31 EDT 2003
+ From: Mattias Gaertner [mailto:nc-gaertnma at netcologne.de]
+
+
+ On Tue, 8 Apr 2003 08:34:39 +0800
+ hernan.et at pg.com wrote:
+
+
+ > About the TStringText, I don't have any clue how to implement it. Maybe
+ > you can give more details.
+
+
+ type
+ TStringText = class(TStrings)
+ private
+ fStr: string;
+ ...
+ end;
+
+ see TStrings
+ add some useful procedures like GetTextLength, GetLineBounds, InsertText,
+ DeleteText, ReplaceText, MoveText, SearchText, ... and override any
+ inherited method from TStrings that should access fStr.
Some ideas I had when I thought of this.
It might handy to keep track of indexes to individual strings in a internal
FIndex: Tlist and a FValidIndex: Integer. With the help of these indices one
can easaly access the individual strings.
Simple store the index (casted to pointer) of the index of the first
LineEndChar (CR or LF) or so
But focus mainly on the usage of FStr. Don't try to create the index, but
create it when one accesses Get(AIndex).
A Get(AIndex) would then like:
if AIndex >= FValidIndex then CreateIndex(Aindex)
if AIndex >= FValidIndex then Reaise list error // we couldnt create it so
the index doesnt exist
if AIndex = 0
then idx := 0
else begin
idx := Integer(FIndex[AIndex - 1])
while FStr[idx] in [#10, #13] do Inc(idx) // skip the previous line
terminator
end
Result := Copy(FStr, idx, Integer(FIndex[AIndex]) - idx);
CreateIndex in its turn scans FStr and Appends indices to FIndex.
It starts scanning from Integer(FList[FValidIndex]) until the required index
is reached.
In Move Add Delete etc the FValidIndex is reset to the last known valid
index (IE if line 15 is deleted, the valid index becomes 14 (if it was
larger)).
Again, this is a way to implement the individual lines. They are expensive.
But that is not our problem, since we primarely wamt to access the Test as a
whole.
Marc
More information about the Lazarus
mailing list