InsertControl with TLabel - ClassNotFound

General TRichView support forum. Please post your questions here
Post Reply
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

InsertControl with TLabel - ClassNotFound

Post by Jim Knopf »

With this code I insert a TLabel, which also works and displays the TLabel as it should.

Code: Select all

var la: TLabel;
    S: string;
begin
  S := '';
  if InputText('New Box', S) then
  begin
    la := TLabel.Create(Self);
    la.Caption := S;
    CurrRV.InsertControl('la', la, rvvaRight);
    if CurrRV.CurItemStyle = rvsComponent then
      CurrRV.SetCurrentItemExtraIntProperty(rvepResizable, 1, True);
  end;
end;
However, when reloading this document, I get a message that the TLabel class is not found.

What am I doing wrong?

Image
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: InsertControl with TLabel - ClassNotFound

Post by Sergey Tkachenko »

All classes of controls must be registered.

Call before the first RVF load:

Code: Select all

RegisterClasses([TLabel]);
If you use more types of controls in document, register them all, such as:

Code: Select all

RegisterClasses([TLabel, TButton, TPanel]);
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Re: InsertControl with TLabel - ClassNotFound

Post by Jim Knopf »

just quickly deleted the post that it works.

That is, it already works, but when I load the document afterwards with TSRVRichViewEdit, the label is not there.

Please again for a hint where the problem is.
The properties (RVFOptions) are the same for both editors

Image
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: InsertControl with TLabel - ClassNotFound

Post by Sergey Tkachenko »

Unfortunately, not all types of controls can be displayed in TSRichViewEdit.
TRichViewEdit handles children controls like any other Delphi component.
TSRichViewEdit displays scaled images of controls instead.

I highly recommend using SRVControls: https://www.trichview.com/help-scaleric ... ntrols.htm
They are on "ScaleRichView" page of the component palette.
They can be inserted both in TRichViewEdit, TSRichViewEdit, and on a form.

Also, make sure that you use a True Type font (raster fonts like "MS Sans Serif", "Courier", "System" cannot be scaled properly)

Specifically, use TSRVLabel instead of TLabel

(this control has a small flaw, Autosize works only if Parent assigned, so insertion code is like this:

Code: Select all

var
  lbl: TSRVLabel;
begin
  lbl := TSRVLabel.Create(nil);
  lbl.Visible := False; // we be changed to True automatically
  lbl.Parent := Self;
  lbl.Caption := 'Hello!';
  lbl.ForegroundColor := clWindowText;
  lbl.Offset := 0;
  SRV.ActiveEditor.InsertControl( '', lbl, rvvaBaseline);
end;
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Re: InsertControl with TLabel - ClassNotFound

Post by Jim Knopf »

Thanks for your quick reply!

I think with SRVLabel, Skin-Manager and a little tinkering I can realize such textboxes as I imagine them for non-fiction. I just hope that I can get small margins to the text using the skin manager.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: InsertControl with TLabel - ClassNotFound

Post by Sergey Tkachenko »

Skin manager is optional, it can be used if you want to change default appearance. SRVControls can work without it.
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Re: InsertControl with TLabel - ClassNotFound

Post by Jim Knopf »

I have now tried around.

1. RichViewEdit: I create SRVLabel with this code - see below

Code: Select all

var la: TSRVLabel;
    S: string;
begin
  S := '';
  if InputText('Neue Box', S) then
  begin
    la := TSRVLabel.Create(Self);
    la.Parent := Self;
    la.ForegroundColor := clBlack;
    la.Font.Name := 'Arial';
    la.Font.Size := 12;
    la.AutoSize := True;
    la.SkinManager := sm;
    la.SkinSchemeIndex := 4;
    la.Caption := S;
    la.Alignment := taCenter;
    la.AutoSize := False;
    la.Width := la.Width + 10;
    la.Height := la.Height + 4;
    la.Offset := 0;
    CurrRV.InsertControl('la', la, rvvaRight);
    if CurrRV.CurItemStyle = rvsComponent then
      CurrRV.SetCurrentItemExtraIntProperty(rvepResizable, 1, True);
  end;
2. the same document opened with SRichViewEdit

3. switch back to RichViewEdit - it disappeared

4. since I know where I inserted it, I can select.

I just want a simple textbox whose width you specify and which calculates the height itself. Optically something like on (1).
Is there another possibility? Or how can I realize this with SRVLabel?

Image
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Re: InsertControl with TLabel - ClassNotFound

Post by Jim Knopf »

We will solve it with TSRVPaintbox, I think. Unfortunately we can't use sidenotes, because they are not displayed in TRichViewEdit - we optionally need both edits for our users, i.e. TRichViewEdit AND TSRichViewEdit - but it probably works that way, too.

You just have to find the paintboxes again after loading the document and link them to the correct OnPaint event.

Now we still have to explore the handling, how to move these 'textboxes' like a picture. But I saw that there is a thread in the forum for drag'n'drop of components.

Image
Post Reply