Setting Initial Font

General TRichView support forum. Please post your questions here
Post Reply
w2m
Posts: 114
Joined: Thu Sep 29, 2005 2:43 am
Contact:

Setting Initial Font

Post 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;
w2m
Posts: 114
Joined: Thu Sep 29, 2005 2:43 am
Contact:

Post 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?
Sergey Tkachenko
Site Admin
Posts: 17564
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Post Reply