|
EControl Ltd. VCL libraries and software support forum
|
View previous topic :: View next topic |
Author |
Message |
Schnorrenberg
Joined: 10 Aug 2006 Posts: 8
|
Posted: Tue Aug 15, 2006 8:58 am Post subject: Customizing Problem |
|
|
Hello Michael,
I wanted to customize TSyntaxMemo (introducing Linenumbers as ec_Edit as an option), and recognized, that this is impossible without modifying the original source SyntaxMemo.pas.
Therefore, what are you thinking about introducing class function, so that customizing is possible without modifying the source?
for exapmle:
type
TLineNumbersClass = class of TLineNumber;
introducing protected, virtual function in TSyntaxMemo:
function TSyntaxMemo.GetLineNumbersClass: TLineNumbersClass;
begin
Result := TLineNumbers;
end;
modifying the constructor:
constructor TSyntaxMemo.Create(AOwner: TComponent);
begin
.....
FLineNumbers := GetLineNumbersClass.Create(Self);
......
end;
Then, it would be possible to customize TLineNumers by simple overriding GetLineNumberClass:
Result := TMyLineNumbersClass;
Hans-Jürgen |
|
Back to top |
|
|
econtrol Site Admin
Joined: 09 Jun 2006 Posts: 202
|
Posted: Tue Aug 15, 2006 12:27 pm Post subject: |
|
|
Hello Hans,
TLineNumbers is only storage for properties, there is only one method that forms line number string and this process may be controled by via event handler OnGetLineNumberStr.
All functionality of line numbers rendering is implemented in TCustomSyntaxMemo.
What is the task that requires such replacement?
Michael. |
|
Back to top |
|
|
Schnorrenberg
Joined: 10 Aug 2006 Posts: 8
|
Posted: Tue Aug 15, 2006 6:29 pm Post subject: |
|
|
Hello Michael,
in this task I wanted to replace the event handler by a method, because we plan to replace (and will replace) many controls by your control in our applications, and I do not want to implement every time an event handler. Therefore, I override the GetNumberString method in a descendant of TLinenumbers (in order to get linenumbers like in ec_edit.exe).
However, I think it is a question of more principal nature (at the moment I'm still testing your control, please consider the "linenumber wish" only as an example). We use many third-party components in our applications, and for a component user there exists often the problems of customizing nested components and missing virtualty. (Borland components, too: if you want to sort a Collection, you have to hack into the VMT, because they forget to give access to FList).
Hans-Jürgen |
|
Back to top |
|
|
econtrol Site Admin
Joined: 09 Jun 2006 Posts: 202
|
Posted: Wed Aug 16, 2006 3:52 am Post subject: |
|
|
I offer next solution (ecSyntMemo.pas):
new protected method:
Code: | TCustomSyntaxMemo
...
function GetLineNumberStr(Line: integer): ecString; dynamic;
...
function TCustomSyntaxMemo.GetLineNumberStr(Line: integer): ecString;
begin
Result := FLineNumbers.GetNumberString(Line);
if Assigned(FOnGetLineNumberStr) then FOnGetLineNumberStr(Self, Line, Result);
end;
procedure TCustomSyntaxMemo.DrawGutterLine(y1, y2, Line, LineColState: integer); // Draw Gutter
...
s := GetLineNumberStr(Line); // <==
if s = '' then Exit;
ts := cvs.TextExtent(S);
... |
In this case you may reimplement this method in derived class.
P.S. The advantage of Win32 in comparison with .NET is the ability of accessing to protected and private memebers. I often used these techniques.
Michael. |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|