If I add/insert text into an untitled.pas memo, you can see it has property highlighting until you save it, then it seems to change colors to what the default pascal highlighter colors. I use a modified pascal highlighter to fit better with the dark style. It's assigned to the multifile memo, then I set it also when the OnNewMemo event fires. Everything works as expected except when I text is added to a untitled memo. You can see it has the right colors after the past, only after coming back from a save.
function TAdvMultiFileMemo.SaveUntitledMemo(UntitledMemoPage: TAdvMultiFileMemoPage): boolean;
var
AFileName: string;
AStyler: TAdvCustomMemoStyler;
begin
Result := false;
if Assigned(FOnSaveUntitled) then
begin
AFileName := '';
FOnSaveUntitled(Self, UntitledMemoPage, AFileName);
if AFileName <> '' then
begin
//On real error, let it create exception for application
UntitledMemoPage.SaveMemoAs(AFileName);
AStyler := GetStylerByFileName(AFileName);
if AStyler <> nil then
UntitledMemoPage.Memo.SyntaxStyles := AStyler
else
UntitledMemoPage.Memo.SyntaxStyles := DefaultStyler;
Result := true;
end;
end;
end;
I've traced it to this routine that is the source of the problem (I think), where AStyler is getting assigned. The styler is already setup for the memo. It's set in properties window at design time, also in OnNewMemo event, I set it there also. And you can see it works when code is pasted in. GetStylerByFileName should return the existing styler and it seem to do so when you create a untitled page, yet when you save the untitled file, it seems get the wrong styler. As a work around I commented out this section of code:
(*
AStyler := GetStylerByFileName(AFileName);
if AStyler <> nil then
UntitledMemoPage.Memo.SyntaxStyles := AStyler
else
UntitledMemoPage.Memo.SyntaxStyles := DefaultStyler;
*)
I hate making changes to the base code, so if you let me know the proper solution to this, I would be grateful.
Drop a TAdvMemoStylerManger to AdvMultiFileMemo.StylersCustom and add your custom styler to a this AdvMemoStylerManger and couple it to the file extensions you use.
Then when you pick a file or save the file with your extension, your custom syntax styler will be used.