Page 1 of 1

Setting Initial Font

Posted: Sat May 04, 2013 7:55 pm
by w2m
I try to set the initial font for load pascal (*.pas} file as text but after loading font is not correct. How to load .pas file with 'Courier New' Font size = 10?

Code: Select all

// set the initial font
      iFontInfo := TFontInfo.Create(nil);
      try
        iFontInfo.FontName := 'Courier New';
        iFontInfo.Size := 10;
        iStyleNo := RichViewEdit.Style.TextStyles.FindSuchStyleEX(0, iFontInfo,
          RVAllFontInfoProperties);
        if iStyleNo < 0 then
        begin
          RichViewEdit.Style.TextStyles.Add;
          iStyleNo := RichViewEdit.Style.TextStyles.Count - 1;
          RichViewEdit.Style.TextStyles[iStyleNo].Assign(iFontInfo);
          RichViewEdit.Style.TextStyles[iStyleNo].Standard := False;
        end;
      finally
        iFontInfo.Free;
      end;

Posted: Sat May 04, 2013 8:03 pm
by w2m
This should have been posted in the private forum because am a registered user. I do not know why it appeared here instead?

Posted: Sun May 05, 2013 7:58 am
by Sergey Tkachenko
This code must work, if you pass iStyleNo variable as StyleNo parameter to RichViewEdit.LoadText.

This is a shorter code producing the same result (requires TRichView 14.x):

Code: Select all

      // set the initial font 
      iFontInfo := TFontInfo.Create(nil); 
      try 
        iFontInfo.FontName := 'Courier New'; 
        iFontInfo.Size := 10; 
        iStyleNo := RichViewEdit.Style.FindTextStyle(iFontInfo);
      finally 
        iFontInfo.Free; 
      end;
PS: I can move this topic to the private section, but it does not contain anything specific to the newest full version, so it may be discussed here.