Page 1 of 1
InsertControl with TLabel - ClassNotFound
Posted: Tue Sep 26, 2023 11:47 am
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?
Re: InsertControl with TLabel - ClassNotFound
Posted: Tue Sep 26, 2023 12:01 pm
by Sergey Tkachenko
All classes of controls must be registered.
Call before the first RVF load:
If you use more types of controls in document, register them all, such as:
Code: Select all
RegisterClasses([TLabel, TButton, TPanel]);
Re: InsertControl with TLabel - ClassNotFound
Posted: Tue Sep 26, 2023 12:34 pm
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
Re: InsertControl with TLabel - ClassNotFound
Posted: Tue Sep 26, 2023 1:20 pm
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;
Re: InsertControl with TLabel - ClassNotFound
Posted: Tue Sep 26, 2023 3:05 pm
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.
Re: InsertControl with TLabel - ClassNotFound
Posted: Tue Sep 26, 2023 4:23 pm
by Sergey Tkachenko
Skin manager is optional, it can be used if you want to change default appearance. SRVControls can work without it.
Re: InsertControl with TLabel - ClassNotFound
Posted: Tue Sep 26, 2023 7:13 pm
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?
Re: InsertControl with TLabel - ClassNotFound
Posted: Wed Sep 27, 2023 6:36 am
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.